Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: PyCQA/isort
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4.3.18
Choose a base ref
...
head repository: PyCQA/isort
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4.3.19
Choose a head ref
  • 3 commits
  • 7 files changed
  • 2 contributors

Commits on May 3, 2019

  1. Add .pre-commit-hooks.yaml to ensure use with pre-commit

    Helps isort work as a pre-commit hook with [pre-commit](https://pre-commit.com/)
    gurunathparasaram authored and timothycrosley committed May 3, 2019
    Copy the full SHA
    d52f990 View commit details

Commits on May 12, 2019

  1. Copy the full SHA
    1a6b508 View commit details

Commits on May 13, 2019

  1. Issue/942 (#946)

    * Add test cases for .pyi extension support, in particular from file based loading
    
    * Implement native support for pyi files
    
    * Bump version to prepare for immediate deploy
    timothycrosley authored May 13, 2019
    Copy the full SHA
    700536e View commit details
Showing with 47 additions and 5 deletions.
  1. +4 −0 .gitignore
  2. +6 −0 .pre-commit-hooks.yaml
  3. +3 −0 CHANGELOG.md
  4. +1 −1 isort/__init__.py
  5. +10 −3 isort/isort.py
  6. +1 −1 setup.py
  7. +22 −0 test_isort.py
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -60,10 +60,14 @@ atlassian-ide-plugin.xml
*.swp
*.kate-swp
.ropeproject/
.vscode

# pip
pip-selfcheck.json

# Python3 Venv Files
.venv/
pyvenv.cfg

# mypy
.mypy_cache
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- id: isort
name: isort
entry: isort
require_serial: true
additional_dependencies: []
language: python
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
=========

### 4.3.19 - May 12, 2019 - hot fix release
- Fixed issue #942 - correctly handle pyi (Python Template Files) to match `black` output

### 4.3.18 - May 1, 2019 - hot fix release
- Fixed an issue with parsing files that contain unicode characters in Python 2
- Fixed issue #924 - Pulling in pip internals causes depreciation warning
2 changes: 1 addition & 1 deletion isort/__init__.py
Original file line number Diff line number Diff line change
@@ -25,4 +25,4 @@
from . import settings # noqa: F401
from .isort import SortImports # noqa: F401

__version__ = "4.3.18"
__version__ = "4.3.19"
13 changes: 10 additions & 3 deletions isort/isort.py
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ class SortImports(object):

def __init__(self, file_path=None, file_contents=None, file_=None, write_to_stdout=False, check=False,
show_diff=False, settings_path=None, ask_to_apply=False, run_path='', check_skip=True,
**setting_overrides):
extension=None, **setting_overrides):
if not settings_path and file_path:
settings_path = os.path.dirname(os.path.abspath(file_path))
settings_path = settings_path or os.getcwd()
@@ -181,6 +181,11 @@ def __init__(self, file_path=None, file_contents=None, file_=None, write_to_stdo
self.in_lines.append(add_import)
self.number_of_lines = len(self.in_lines)

if not extension:
self.extension = file_name.split('.')[-1] if file_name else "py"
else:
self.extension = extension

self.out_lines = []
self.comments = {'from': {}, 'straight': {}, 'nested': {}, 'above': {'straight': {}, 'from': {}}}
self.imports = OrderedDict()
@@ -672,8 +677,10 @@ def by_module(line):

if self.config['lines_after_imports'] != -1:
self.out_lines[imports_tail:0] = ["" for line in range(self.config['lines_after_imports'])]
elif next_construct.startswith("def ") or next_construct.startswith("class ") or \
next_construct.startswith("@") or next_construct.startswith("async def"):
elif self.extension != "pyi" and (next_construct.startswith("def ") or
next_construct.startswith("class ") or
next_construct.startswith("@") or
next_construct.startswith("async def")):
self.out_lines[imports_tail:0] = ["", ""]
else:
self.out_lines[imports_tail:0] = [""]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
readme = f.read()

setup(name='isort',
version='4.3.18',
version='4.3.19',
description='A Python utility / library to sort Python imports.',
long_description=readme,
author='Timothy Crosley',
22 changes: 22 additions & 0 deletions test_isort.py
Original file line number Diff line number Diff line change
@@ -2994,3 +2994,25 @@ def test_import_heading_issue_905():
'# Local imports\n'
'from oklib.plot_ok import imagesc\n')
assert SortImports(file_contents=test_input, **config).output == test_input


def test_pyi_formatting_issue_942(tmpdir):
test_input = ('import os\n'
'\n'
'\n'
'def my_method():\n')
expected_py_output = test_input.splitlines()
expected_pyi_output = ('import os\n'
'\n'
'def my_method():\n').splitlines()
assert SortImports(file_contents=test_input).output.splitlines() == expected_py_output
assert SortImports(file_contents=test_input,
extension="pyi").output.splitlines() == expected_pyi_output

source_py = tmpdir.join('source.py')
source_py.write(test_input)
assert SortImports(file_path=str(source_py)).output.splitlines() == expected_py_output

source_pyi = tmpdir.join('source.pyi')
source_pyi.write(test_input)
assert SortImports(file_path=str(source_pyi)).output.splitlines() == expected_pyi_output