Skip to content

Commit

Permalink
Merge branch 'release/3.9.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Dec 25, 2014
2 parents 909655f + 5ae119a commit e8a556b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
1 change: 1 addition & 0 deletions ACKNOWLEDGEMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Code Contributors
- Maciej Wolff (@maciejwo)
- Elliott Sales de Andrade (@qulogic)
- Kasper Jacobsen (@dinoshauer)
- Sebastian Pipping (@hartwork)

--------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion isort/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
from . import settings
from .isort import SECTION_NAMES, SECTIONS, SortImports

__version__ = "3.9.2"
__version__ = "3.9.3"
27 changes: 12 additions & 15 deletions isort/isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,18 @@ def place_module(self, moduleName):
if moduleName.startswith("."):
return SECTIONS.LOCALFOLDER

try:
firstPart = moduleName.split('.')[0]
except IndexError:
firstPart = None

if (moduleName in self.config['known_future_library'] or
firstPart in self.config['known_future_library']):
return SECTIONS.FUTURE
elif moduleName in self.config['known_standard_library'] or \
(firstPart in self.config['known_standard_library']):
return SECTIONS.STDLIB
elif moduleName in self.config['known_third_party'] or (firstPart in self.config['known_third_party']):
return SECTIONS.THIRDPARTY
elif moduleName in self.config['known_first_party'] or (firstPart in self.config['known_first_party']):
return SECTIONS.FIRSTPARTY
# Try to find most specific placement instruction match (if any)
parts = moduleName.split('.')
module_names_to_check = ['.'.join(parts[:first_k]) for first_k in range(len(parts), 0, -1)]
for module_name_to_check in module_names_to_check:
for placement, config_key in (
(SECTIONS.FUTURE, 'known_future_library'),
(SECTIONS.STDLIB, 'known_standard_library'),
(SECTIONS.THIRDPARTY, 'known_third_party'),
(SECTIONS.FIRSTPARTY, 'known_first_party'),
):
if module_name_to_check in self.config[config_key]:
return placement

for prefix in PYTHONPATH:
module_path = "/".join((prefix, moduleName.replace(".", "/")))
Expand Down
4 changes: 3 additions & 1 deletion isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def main():
parser = argparse.ArgumentParser(description='Sort Python import definitions alphabetically '
'within logical sections.')
parser.add_argument('files', nargs='+', help='One or more Python source files that need their imports sorted.')
parser.add_argument('-l', '--lines', help='The max length of an import line (used for wrapping long imports).',
parser.add_argument('-l', '--lines', help='[Deprecated] The max length of an import line (used for wrapping long imports).',
dest='line_length', type=int)
parser.add_argument('-w', '--line-width', help='The max length of an import line (used for wrapping long imports).',
dest='line_length', type=int)
parser.add_argument('-s', '--skip', help='Files that sort imports should skip over.', dest='skip', action='append')
parser.add_argument('-ns', '--dont-skip', help='Files that sort imports should never skip over.',
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def run(self):
readme = ''

setup(name='isort',
version='3.9.2',
version='3.9.3',
description='A Python utility / library to sort Python imports.',
long_description=readme,
author='Timothy Crosley',
author_email='timothy.crosley@gmail.com',
url='https://github.com/timothycrosley/isort',
download_url='https://github.com/timothycrosley/isort/archive/3.9.2.tar.gz',
download_url='https://github.com/timothycrosley/isort/archive/3.9.3.tar.gz',
license="MIT",
entry_points={
'console_scripts': [
Expand All @@ -57,7 +57,7 @@ def run(self):
},
packages=['isort'],
requires=['pies', 'natsort'],
install_requires=['pies>=2.6.0', 'natsort>=3.0.0'],
install_requires=['pies>=2.6.2', 'natsort>=3.0.0'],
cmdclass={'test': PyTest},
keywords='Refactor, Python, Python2, Python3, Refactoring, Imports, Sort, Clean',
classifiers=['Development Status :: 6 - Mature',
Expand All @@ -74,6 +74,7 @@ def run(self):
'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Software Development :: Libraries',
'Topic :: Utilities'],
**PyTest.extra_kwargs)
24 changes: 24 additions & 0 deletions test_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,3 +1081,27 @@ def test_place_comments():
"# isort:imports-stdlib\n"
"import os\n"
"import sys\n")


def test_placement_control():
"""Ensure that most specific placement control match wins"""
test_input = ("import os\n"
"import sys\n"
"from bottle import Bottle, redirect, response, run\n"
"import p24.imports._argparse as argparse\n"
"import p24.imports._subprocess as subprocess\n"
"import p24.imports._VERSION as VERSION\n"
"import p24.shared.media_wiki_syntax as syntax\n")
test_output = SortImports(file_contents=test_input,
known_first_party=['p24', 'p24.imports._VERSION'],
known_standard_library=['p24.imports'],
default_section="THIRDPARTY").output
assert test_output == ("import os\n"
"import p24.imports._argparse as argparse\n"
"import p24.imports._subprocess as subprocess\n"
"import sys\n"
"\n"
"from bottle import Bottle, redirect, response, run\n"
"\n"
"import p24.imports._VERSION as VERSION\n"
"import p24.shared.media_wiki_syntax as syntax\n")

0 comments on commit e8a556b

Please sign in to comment.