isort-4.2.2/000077500000000000000000000000001260070737300126645ustar00rootroot00000000000000isort-4.2.2/.editorconfig000066400000000000000000000005171260070737300153440ustar00rootroot00000000000000root = true [*.py] max_line_length = 120 indent_style = space indent_size = 4 known_first_party = isort known_third_party = kate ignore_frosted_errors = E103 skip = runtests.py,build,.tox balanced_wrapping = true not_skip = __init__.py [*.{rst,ini}] indent_style = space indent_size = 4 [*.yml] indent_style = space indent_size = 2 isort-4.2.2/.env000066400000000000000000000017641260070737300134650ustar00rootroot00000000000000#!/bin/bash OPEN_PROJECT_NAME="isort" if [ "$PROJECT_NAME" = "$OPEN_PROJECT_NAME" ]; then return fi if [ ! -f ".env" ]; then return fi export PROJECT_NAME=$OPEN_PROJECT_NAME export PROJECT_DIR="$PWD" # Let's make sure this is a hubflow enabled repo yes | git hf init >/dev/null 2>/dev/null # Quick directory switching alias root="cd $PROJECT_DIR" alias project="root; cd $PROJECT_NAME" # Commands alias test="root; py.test -s" alias install="_install_project" alias distribute="python setup.py sdist upload; python setup.py bdist_wheel upload" alias leave="_leave_project" function _install_project() { CURRENT_DIRECTORY="$PWD" root sudo python setup.py install cp isort_kate_plugin.py ~/.kde/share/apps/kate/pate/isort_plugin.py >/dev/null 2>/dev/null cd $CURRENT_DIRECTORY } function _leave_project() { export PROJECT_NAME="" export PROJECT_DIR="" unalias root unalias project unalias test unalias install unalias distribute unalias leave } isort-4.2.2/.gitignore000066400000000000000000000011711260070737300146540ustar00rootroot00000000000000*.py[cod] .DS_Store # C extensions *.so # Packages *.egg *.egg-info .eggs build eggs parts var sdist develop-eggs .installed.cfg lib lib64 MANIFEST .eggs # Installer logs pip-log.txt npm-debug.log # Unit test / coverage reports .coverage .tox nosetests.xml htmlcov .cache # Translations *.mo # Mr Developer .mr.developer.cfg .project .pydevproject # SQLite test_exp_framework # npm node_modules/ # dolphin .directory libpeerconnection.log # setuptools dist # IDE Files atlassian-ide-plugin.xml .idea/ *.swp *.kate-swp .ropeproject/ # pip pip-selfcheck.json # Python3 Venv Files bin/ include/ lib/ lib64 pyvenv.cfg share/ isort-4.2.2/.travis.yml000066400000000000000000000003051260070737300147730ustar00rootroot00000000000000language: python env: - TOXENV=isort-check - TOXENV=py26 - TOXENV=py27 - TOXENV=py32 - TOXENV=py33 - TOXENV=py34 - TOXENV=pypy install: - pip install tox script: - tox -e $TOXENV isort-4.2.2/.undertake000066400000000000000000000001071260070737300146450ustar00rootroot00000000000000name=Add isort settings color=#3C79AB font_color=white format=instantlyisort-4.2.2/ACKNOWLEDGEMENTS.md000066400000000000000000000041051260070737300155400ustar00rootroot00000000000000Original Creator & Maintainer =================== - Timothy Edmund Crosley (@timothycrosley) Plugin Writers =================== - *VIM* - Juan Pedro Fisanotti (@fisadev) - *Emacs* - Friedrich Paetzke (@paetzke) - *Sublime* - Thijs de Zoute (@thijsdezoete) Notable Bug Reporters =================== - Bengt Lüers (@Bengt) - Chris Adams (@acdha) - @OddBloke - Martin Geisler (@mgeisler) Code Contributors =================== - Aaron Gallagher (@habnabit) - Thomas Grainger (@graingert) - Thijs de Zoute (@thijsdezoete) - Marc Abramowitz (@msabramo) - Daniel Cowgill (@dcowgill) - Francois Lebel (@flebel) - Antoni Segura Puimedon (@celebdor) - Pablo (@oubiga) - Oskar Hahn (@ostcar) - Wim Glenn (@wimglenn) - Matt Caldwell (@mattcaldwell) - Dwayne Bailey (@dwaynebailey) - Ionel Cristian Mărieș (@ionelmc) - Chris Adams (@acdha) - GuoJing (@GuoJing) - George Hickman (@ghickman) - Dan Davison (@dandavison) - Maciej Wolff (@maciejwo) - Elliott Sales de Andrade (@qulogic) - Kasper Jacobsen (@dinoshauer) - Sebastian Pipping (@hartwork) - Helen Sherwood-Taylor (@helenst) - Mocker (@Zuckonit) - Tim Graham (@timgraham) - Adam (@NorthIsUp) - Norman Jäckel (@normanjaeckel) - Derrick Petzold (@dpetzold) - Michael van Tellingen (@mvantellingen) - Patrick Yevsukov (@patrickyevsukov) - Christer van der Meeren (@cmeeren) - Timon Wong/NHNCN (@timonwong) - Jeremy Dunck (@jdunck) - Benjamin ABEL (@benjaminabel) - Dan Baragan (@danbaragan) - Rob Cowie (@robcowie) - Amit Shah (@Amwam) - Patrick Gerken (@do3cc) - @dein0s - David Stensland (@terite) - Ankur Dedania (@AbsoluteMSTR) - Lee Packham (@leepa) - Jesse Mullan (@jmullan) Documenters =================== - Reinout van Rees (@reinout) - Helen Sherwood-Taylor (@helenst) - Elliott Sales de Andrade (@QuLogic) - Brian Peiris (@brianpeiris) - Tim Graham (@timgraham) -------------------------------------------- A sincere thanks to everyone who has helped isort be the great utility it is today! It would not be one-hundredth as useful and consistent as it is now without the help of your bug reports, commits, and suggestions. You guys rock! ~Timothy Crosley isort-4.2.2/CHANGELOG.md000066400000000000000000000044541260070737300145040ustar00rootroot00000000000000Changelog ========= ### 4.0.0 - Removed all external dependencies ### 4.1.0 - Started keeping a log of all changes between releases - Added the isort logo to the command line interface - Added example usage gif to README - Implemented issue #292: skip setting now supports glob patterns - Implemented issue #271: Add option to sort imports purely alphabetically - Implemented issue #301: Readme is now natively in RST format, making it easier for Python tooling to pick up - Implemented pylama isort extension - Fixed issue #260: # encoding lines at the top of the file are now correctly supported - Fixed issue #284: Sticky comments above first import are now supported - Fixed issue #310: Ensure comments don't get duplicated when reformatting imports - Fixed issue #289: Sections order not being respected - Fixed issue #296: Made it more clear how to set arguments more then once ### 4.1.1 - Added support for partial file match skips (thanks to @Amwam) - Added support for --quiet option to only show errors when running isort - Fixed issue #316: isort added new lines incorrectly when a top-of line comment is present ### 4.1.2 - Fixed issue #323: Accidental default configuration change introduced ### 4.2.0 - Added option "NOQA" Do not wrap lines, but add a noqa statement at the end - Added support for runnning isort recursively, simply with a standalone `isort` command - Added support to run isort library as a module - Added compatibility for Python 3.5 - Fixed performance issue (#338) when running on project with lots of skipped directories - Fixed issue #328: extra new can occasionally occur when using alphabetical-only sort - Fixed custom sections parsing from config file (unicode string -> list) - Updated pylama extension to the correct entry point - Skip files even when file_contents is provided if they are explicitly in skip list - Removed always showing isort banner, keeping it for when the version is requested, verbose is used, or show_logo setting is set. ### 4.2.1 - Hot fix release to fix code error when skipping globs ### 4.2.2 - Give an error message when isort is unable to determine where to place a module - Allow imports to be sorted by module, independant of import_type, when `force_sort_within_sections` option is set - Fixed an issue that caused Python files with 2 top comments not to be sorted isort-4.2.2/LICENSE000077500000000000000000000021011260070737300136660ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2013 Timothy Edmund Crosley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. isort-4.2.2/README.rst000066400000000000000000000400021260070737300143470ustar00rootroot00000000000000.. image:: https://raw.github.com/timothycrosley/isort/master/logo.png :alt: isort ######## .. image:: https://badge.fury.io/py/isort.png :target: http://badge.fury.io/py/isort :alt: PyPI version .. image:: https://travis-ci.org/timothycrosley/isort.png?branch=master :target: https://travis-ci.org/timothycrosley/isort :alt: Build Status .. image:: https://coveralls.io/repos/timothycrosley/isort/badge.svg?branch=release%2F2.6.0&service=github :target: https://coveralls.io/github/timothycrosley/isort?branch=release%2F2.6.0 :alt: Coverage .. image:: https://img.shields.io/github/license/mashape/apistatus.svg :target: https://pypi.python.org/pypi/hug/ :alt: License .. image:: https://badges.gitter.im/Join%20Chat.svg :alt: Join the chat at https://gitter.im/timothycrosley/isort :target: https://gitter.im/timothycrosley/isort?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge isort your python imports for you so you don't have to. isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections. It provides a command line utility, Python library and `plugins for various editors `_ to quickly sort all your imports. It currently cleanly supports Python 2.6 - 3.5 using `pies `_ to achieve this without ugly hacks and/or py2to3. .. image:: https://raw.github.com/timothycrosley/isort/develop/example.gif :alt: Example Usage Before isort: .. code-block:: python from my_lib import Object print("Hey") import os from my_lib import Object3 from my_lib import Object2 import sys from third_party import lib15, lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14 import sys from __future__ import absolute_import from third_party import lib3 print("yo") After isort: .. code-block:: python from __future__ import absolute_import import os import sys from third_party import (lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14, lib15) from my_lib import Object, Object2, Object3 print("Hey") print("yo") Installing isort ================ Installing isort is as simple as: .. code-block:: bash pip install isort or if you prefer .. code-block:: bash easy_install isort Using isort =========== **From the command line**: .. code-block:: bash isort mypythonfile.py mypythonfile2.py or recursively: .. code-block:: bash isort -rc . *which is equivalent to:* .. code-block:: bash isort **/*.py or to see the proposed changes without applying them: .. code-block:: bash isort mypythonfile.py --diff Finally, to atomically run isort against a project, only applying changes if they don't introduce syntax errors do: .. code-block:: bash isort -rc --atomic . (Note: this is disabled by default as it keeps isort from being able to run against code written using a different version of Python) **From within Python**: .. code-block:: bash from isort import SortImports SortImports("pythonfile.py") or: .. code-block:: bash from isort import SortImports new_contents = SortImports(file_contents=old_contents).output **From within Kate:** .. code-block:: bash ctrl+[ or: .. code-block:: bash menu > Python > Sort Imports Installing isort's Kate plugin ============================== For KDE 4.13+ / Pate 2.0+: .. code-block:: bash wget https://raw.github.com/timothycrosley/isort/master/kate_plugin/isort_plugin.py --output-document ~/.kde/share/apps/kate/pate/isort_plugin.py wget https://raw.github.com/timothycrosley/isort/master/kate_plugin/isort_plugin_ui.rc --output-document ~/.kde/share/apps/kate/pate/isort_plugin_ui.rc wget https://raw.github.com/timothycrosley/isort/master/kate_plugin/katepart_isort.desktop --output-document ~/.kde/share/kde4/services/katepart_isort.desktop For all older versions: .. code-block:: bash wget https://raw.github.com/timothycrosley/isort/master/kate_plugin/isort_plugin_old.py --output-document ~/.kde/share/apps/kate/pate/isort_plugin.py You will then need to restart kate and enable Python Plugins as well as the isort plugin itself. Installing isort's for your preferred text editor ================================================= Several plugins have been written that enable to use isort from within a variety of text-editors. You can find a full list of them `on the isort wiki `_. Additionally, I will enthusiastically accept pull requests that include plugins for other text editors and add documentation for them as I am notified. How does isort work? ==================== isort parses specified files for global level import lines (imports outside of try / except blocks, functions, etc..) and puts them all at the top of the file grouped together by the type of import: - Future - Python Standard Library - Third Party - Current Python Project - Explicitly Local (. before import, as in: ``from . import x``) - Custom Separate Sections (Defined by forced_separate list in configuration file) - Custom Sections (Defined by sections list in configuration file) Inside of each section the imports are sorted alphabetically. isort automatically removes duplicate python imports, and wraps long from imports to the specified line length (defaults to 80). When will isort not work? ========================= If you ever have the situation where you need to have a try / except block in the middle of top-level imports or if your import order is directly linked to precedence. For example: a common practice in Django settings files is importing * from various settings files to form a new settings file. In this case if any of the imports change order you are changing the settings definition itself. However, you can configure isort to skip over just these files - or even to force certain imports to the top. Configuring isort ================= If you find the default isort settings do not work well for your project, isort provides several ways to adjust the behavior. To configure isort for a single user create a ``~/.isort.cfg`` file: .. code-block:: ini [settings] line_length=120 force_to_top=file1.py,file2.py skip=file3.py,file4.py known_future_library=future,pies known_standard_library=std,std2 known_third_party=randomthirdparty known_first_party=mylib1,mylib2 indent=' ' multi_line_output=3 length_sort=1 forced_separate=django.contrib,django.utils default_section=FIRSTPARTY Additionally, you can specify project level configuration simply by placing a ``.isort.cfg`` file at the root of your project. isort will look up to 25 directories up, from the the file it is ran against, to find a project specific configuration. Or, if you prefer, you can add an isort section to your project's ``setup.cfg`` with any desired settings. You can then override any of these settings by using command line arguments, or by passing in override values to the SortImports class. Finally, as of version 3.0 isort supports editorconfig files using the standard syntax defined here: http://editorconfig.org/ Meaning you place any standard isort configuration parameters within a .editorconfig file under the ``*.py`` section and they will be honored. For a full list of isort settings and their meanings `take a look at the isort wiki `_. Multi line output modes ======================= You will notice above the "multi_line_output" setting. This setting defines how from imports wrap when they extend past the line_length limit and has 6 possible settings: **0 - Grid** .. code-block:: python from third_party import (lib1, lib2, lib3, lib4, lib5, ...) **1 - Vertical** .. code-block:: python from third_party import (lib1, lib2, lib3 lib4, lib5, ...) **2 - Hanging Indent** .. code-block:: python from third_party import \ lib1, lib2, lib3, \ lib4, lib5, lib6 **3 - Vertical Hanging Indent** .. code-block:: python from third_party import ( lib1, lib2, lib3, lib4, ) **4 - Hanging Grid** .. code-block:: python from third_party import ( lib1, lib2, lib3, lib4, lib5, ...) **5 - Hanging Grid Grouped** .. code-block:: python from third_party import ( lib1, lib2, lib3, lib4, lib5, ... ) **6 - NOQA** .. code-block:: python from third_party import lib1, lib2, lib3, ... # NOQA Alternatively, you can set ``force_single_line`` to ``True`` (``-sl`` on the command line) and every import will appear on its own line: .. code-block:: python from third_party import lib1 from third_party import lib2 from third_party import lib3 ... Note: to change the how constant indents appear - simply change the indent property with the following accepted formats: * Number of spaces you would like. For example: 4 would cause standard 4 space indentation. * Tab * A verbatim string with quotes around it. For example: .. code-block:: python " " is equivalent to 4. For the import styles that use parentheses, you can control whether or not to include a trailing comma after the last import with the ``include_trailing_comma`` option (defaults to ``False``). Intelligently Balanced Multi-line Imports ========================================= As of isort 3.1.0 support for balanced multi-line imports has been added. With this enabled isort will dynamically change the import length to the one that produces the most balanced grid, while staying below the maximum import length defined. Example: .. code-block:: python from __future__ import (absolute_import, division, print_function, unicode_literals) Will be produced instead of: .. code-block:: python from __future__ import (absolute_import, division, print_function, unicode_literals) To enable this set ``balanced_wrapping`` to ``True`` in your config or pass the ``-e`` option into the command line utility. Custom Sections and Ordering ============================ You can change the section order with ``sections`` option from the default of: .. code-block:: ini FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER to your preference: .. code-block:: ini sections=FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,LOCALFOLDER You also can define your own sections and thier order. Example: .. code-block:: ini known_django=django known_pandas=pandas,numpy sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,PANDAS,FIRSTPARTY,LOCALFOLDER would create two new sections with the specified known modules. Auto-comment import sections ============================ Some projects prefer to have import sections uniquely titled to aid in identifying the sections quickly when visually scanning. isort can automate this as well. To do this simply set the ``import_heading_{section_name}`` setting for each section you wish to have auto commented - to the desired comment. For Example: .. code-block:: ini import_heading_stdlib=Standard Library import_heading_firstparty=My Stuff Would lead to output looking like the following: .. code-block:: python # Standard Library import os import sys import django.settings # My Stuff import myproject.test Ordering by import length ========================= isort also makes it easy to sort your imports by length, simply by setting the ``length_sort`` option to ``True``. This will result in the following output style: .. code-block:: python from evn.util import ( Pool, Dict, Options, Constant, DecayDict, UnexpectedCodePath, ) Skip processing of imports (outside of configuration) ===================================================== To make isort ignore a single import simply add a comment at the end of the import line containing the text ``isort:skip``: .. code-block:: python import module # isort:skip or: .. code-block:: python from xyz import (abc, # isort:skip yo, hey) To make isort skip an entire file simply add ``isort:skip_file`` to the module's doc string: .. code-block:: python """ my_module.py Best module ever isort:skip_file """ import b import a Adding an import to multiple files ================================== isort makes it easy to add an import statement across multiple files, while being assured it's correctly placed. From the command line: .. code-block:: bash isort -a "from __future__ import print_function" *.py from within Kate: .. code-block:: ctrl+] or: .. code-block:: menu > Python > Add Import Removing an import from multiple files ====================================== isort also makes it easy to remove an import from multiple files, without having to be concerned with how it was originally formatted. From the command line: .. code-block:: bash isort -r "os.system" *.py from within Kate: .. code-block:: ctrl+shift+] or: .. code-block:: menu > Python > Remove Import Using isort to verify code ========================== The ``--check-only`` option --------------------------- isort can also be used to used to verify that code is correctly formatted by running it with ``-c``. Any files that contain incorrectly sorted and/or formatted imports will be outputted to ``stderr``. .. code-block:: bash isort **/*.py -c -vb SUCCESS: /home/timothy/Projects/Open_Source/isort/isort_kate_plugin.py Everything Looks Good! ERROR: /home/timothy/Projects/Open_Source/isort/isort/isort.py Imports are incorrectly sorted. One great place this can be used is with a pre-commit git hook, such as this one by @acdha: https://gist.github.com/acdha/8717683 This can help to ensure a certain level of code quality throughout a project. Git hook -------- isort provides a hook function that can be integrated into your Git pre-commit script to check Python code before committing. To cause the commit to fail if there are isort errors (strict mode), include the following in ``.git/hooks/pre-commit``: .. code-block:: python from isort.hooks import git_hook if __name__ == '__main__': sys.exit(git_hook(strict=True)) If you just want to display warnings, but allow the commit to happen anyway, call ``git_hook`` without the `strict` parameter. Setuptools integration ---------------------- Upon installation, isort enables a ``setuptools`` command that checks Python files declared by your project. Running ``python setup.py isort`` on the command line will check the files listed in your ``py_modules`` and ``packages``. If any warning is found, the command will exit with an error code: .. code-block:: bash $ python setup.py isort Also, to allow users to be able to use the command without having to install isort themselves, add isort to the setup_requires of your ``setup()`` like so: .. code-block:: python setup( name="project", packages=["project"], setup_requires=[ "isort" ] ) Why isort? ========== isort simply stands for import sort. It was originally called "sortImports" however I got tired of typing the extra characters and came to the realization camelCase is not pythonic. I wrote isort because in an organization I used to work in the manager came in one day and decided all code must have alphabetically sorted imports. The code base was huge - and he meant for us to do it by hand. However, being a programmer - I'm too lazy to spend 8 hours mindlessly performing a function, but not too lazy to spend 16 hours automating it. I was given permission to open source sortImports and here we are :) -------------------------------------------- Thanks and I hope you find isort useful! ~Timothy Crosley isort-4.2.2/example.gif000066400000000000000000002376201260070737300150200ustar00rootroot00000000000000GIF89a         # !$ (8 !!%$%!!"%%&!($*&,"(%(',(.(*)-,. (()0,2*1-1-5021546283<595<9=$'00"//# )((1.-20/988N:@=A>D8?A""h*G)AE8@B"hhB<;XXDC6FFFGORGPSPNLSPOXXX[eg`]\c`_n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id%%W>(¤ǒ 2$ R{ 8o\,׭/tү^%h1HnG2+AQ(N"sֈR)=Ϟ94)!h3_~0˞( {M!Žs/] Bc?%Z(W3L"$3j{hh2K)c?g6{=j^N(kS 3M3=(9I4REeUEo ClŢ\NkD(rJѐG&A& Z2o^D.C滇ϧ|9w/Ӂ$WldIDyyf]H\|kQѠyDBh-fM8!SΪ›4g' hmjHDfy\wI\_ H%zHU$$Rhfv54O("a>Q61%/L&=ڶirhܰkqMMF>0'@0?(S 1 or self.in_lines[:1] not in ([], [""])) or self.config.get('force_adds', False): for add_import in self.add_imports: self.in_lines.append(add_import) self.number_of_lines = len(self.in_lines) self.out_lines = [] self.comments = {'from': {}, 'straight': {}, 'nested': {}, 'above': {'straight': {}, 'from': {}}} self.imports = {} self.as_map = {} section_names = self.config.get('sections') self.sections = namedtuple('Sections', section_names)(*[n for n in section_names]) for section in itertools.chain(self.sections, self.config['forced_separate']): self.imports[section] = {'straight': set(), 'from': {}} self.index = 0 self.import_index = -1 self._first_comment_index_start = -1 self._first_comment_index_end = -1 self._parse() if self.import_index != -1: self._add_formatted_imports() self.length_change = len(self.out_lines) - self.original_length while self.out_lines and self.out_lines[-1].strip() == "": self.out_lines.pop(-1) self.out_lines.append("") self.output = "\n".join(self.out_lines) if self.config.get('atomic', False): try: compile(self._strip_top_comments(self.out_lines), self.file_path, 'exec', 0, 1) except SyntaxError: self.output = file_contents self.incorrectly_sorted = True try: compile(self._strip_top_comments(self.in_lines), self.file_path, 'exec', 0, 1) print("ERROR: {0} isort would have introduced syntax errors, please report to the project!". \ format(self.file_path)) except SyntaxError: print("ERROR: {0} File contains syntax errors.".format(self.file_path)) return if check: if self.output == file_contents: if self.config['verbose']: print("SUCCESS: {0} Everything Looks Good!".format(self.file_path)) else: print("ERROR: {0} Imports are incorrectly sorted.".format(self.file_path)) self.incorrectly_sorted = True if show_diff or self.config.get('show_diff', False) is True: self._show_diff(file_contents) return if show_diff or self.config.get('show_diff', False) is True: self._show_diff(file_contents) elif write_to_stdout: stdout.write(self.output) elif file_name: if ask_to_apply: if self.output == file_contents: return self._show_diff(file_contents) answer = None while answer not in ('yes', 'y', 'no', 'n', 'quit', 'q'): answer = input("Apply suggested changes to '{0}' [Y/n/q]?".format(self.file_path)).lower() if answer in ('no', 'n'): return if answer in ('quit', 'q'): sys.exit(1) with codecs.open(self.file_path, encoding=self.file_encoding, mode='w') as output_file: output_file.write(self.output) def _show_diff(self, file_contents): for line in unified_diff( file_contents.splitlines(1), self.output.splitlines(1), fromfile=self.file_path + ':before', tofile=self.file_path + ':after', fromfiledate=str(datetime.fromtimestamp(os.path.getmtime(self.file_path))), tofiledate=str(datetime.now()) ): stdout.write(line) @staticmethod def _strip_top_comments(lines): """Strips # comments that exist at the top of the given lines""" lines = copy.copy(lines) while lines and lines[0].startswith("#"): lines = lines[1:] return "\n".join(lines) def place_module(self, moduleName): """Tries to determine if a module is a python std import, third party import, or project code: if it can't determine - it assumes it is project code """ for forced_separate in self.config['forced_separate']: if moduleName.startswith(forced_separate) or moduleName.startswith("." + forced_separate): return forced_separate if moduleName.startswith("."): return self.sections.LOCALFOLDER # 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 in reversed(self.sections): known_placement = KNOWN_SECTION_MAPPING.get(placement, placement) config_key = 'known_{0}'.format(known_placement.lower()) if module_name_to_check in self.config.get(config_key, []): return placement paths = PYTHONPATH virtual_env = os.environ.get('VIRTUAL_ENV', None) if virtual_env: paths = list(paths) for version in ((2, 6), (2, 7), (3, 0), (3, 1), (3, 2), (3, 3), (3, 4)): paths.append("{0}/lib/python{1}.{2}/site-packages".format(virtual_env, version[0], version[1])) for prefix in paths: module_path = "/".join((prefix, moduleName.replace(".", "/"))) package_path = "/".join((prefix, moduleName.split(".")[0])) if (os.path.exists(module_path + ".py") or os.path.exists(module_path + ".so") or (os.path.exists(package_path) and os.path.isdir(package_path))): if "site-packages" in prefix or "dist-packages" in prefix: return self.sections.THIRDPARTY elif "python2" in prefix.lower() or "python3" in prefix.lower(): return self.sections.STDLIB else: return self.sections.FIRSTPARTY return self.config['default_section'] def _get_line(self): """Returns the current line from the file while incrementing the index.""" line = self.in_lines[self.index] self.index += 1 return line @staticmethod def _import_type(line): """If the current line is an import line it will return its type (from or straight)""" if "isort:skip" in line: return elif line.startswith('import '): return "straight" elif line.startswith('from '): return "from" def _at_end(self): """returns True if we are at the end of the file.""" return self.index == self.number_of_lines @staticmethod def _module_key(module_name, config, sub_imports=False): prefix = "" module_name = str(module_name) if sub_imports and config['order_by_type']: if module_name.isupper(): prefix = "A" elif module_name[0:1].isupper(): prefix = "B" else: prefix = "C" module_name = module_name.lower() return "{0}{1}{2}".format(module_name in config['force_to_top'] and "A" or "B", prefix, config['length_sort'] and (str(len(module_name)) + ":" + module_name) or module_name) def _add_comments(self, comments, original_string=""): """ Returns a string with comments added """ return comments and "{0} # {1}".format(self._strip_comments(original_string)[0], "; ".join(comments)) or original_string def _wrap(self, line): """ Returns an import wrapped to the specified line-length, if possible. """ wrap_mode = self.config.get('multi_line_output', 0) if len(line) > self.config['line_length'] and wrap_mode != settings.WrapModes.NOQA: for splitter in ("import", "."): exp = r"\b" + re.escape(splitter) + r"\b" if re.search(exp, line) and not line.strip().startswith(splitter): line_parts = re.split(exp, line) next_line = [] while (len(line) + 2) > (self.config['wrap_length'] or self.config['line_length']) and line_parts: next_line.append(line_parts.pop()) line = splitter.join(line_parts) if not line: line = next_line.pop() cont_line = self._wrap(self.config['indent'] + splitter.join(next_line).lstrip()) if self.config['use_parentheses']: return "{0}{1} (\n{2})".format(line, splitter, cont_line) return "{0}{1} \\\n{2}".format(line, splitter, cont_line) elif len(line) > self.config['line_length'] and wrap_mode == settings.WrapModes.NOQA: if "# NOQA" not in line: return "{0} # NOQA".format(line) return line def _add_straight_imports(self, straight_modules, section, section_output): for module in straight_modules: if module in self.remove_imports: continue if module in self.as_map: import_definition = "import {0} as {1}".format(module, self.as_map[module]) else: import_definition = "import {0}".format(module) comments_above = self.comments['above']['straight'].pop(module, None) if comments_above: section_output.extend(comments_above) section_output.append(self._add_comments(self.comments['straight'].get(module), import_definition)) def _add_from_imports(self, from_modules, section, section_output): for module in from_modules: if module in self.remove_imports: continue import_start = "from {0} import ".format(module) from_imports = list(self.imports[section]['from'][module]) from_imports = nsorted(from_imports, key=lambda key: self._module_key(key, self.config, True)) if self.remove_imports: from_imports = [line for line in from_imports if not "{0}.{1}".format(module, line) in self.remove_imports] for from_import in copy.copy(from_imports): submodule = module + "." + from_import import_as = self.as_map.get(submodule, False) if import_as: import_definition = "{0} as {1}".format(from_import, import_as) if self.config['combine_as_imports'] and not ("*" in from_imports and self.config['combine_star']): from_imports[from_imports.index(from_import)] = import_definition else: import_statement = self._wrap(import_start + import_definition) comments = self.comments['straight'].get(submodule) import_statement = self._add_comments(comments, import_statement) section_output.append(import_statement) from_imports.remove(from_import) if from_imports: comments = self.comments['from'].pop(module, ()) if "*" in from_imports and self.config['combine_star']: import_statement = self._wrap(self._add_comments(comments, "{0}*".format(import_start))) elif self.config['force_single_line']: import_statements = [] for from_import in from_imports: single_import_line = self._add_comments(comments, import_start + from_import) comment = self.comments['nested'].get(module, {}).pop(from_import, None) if comment: single_import_line += "{0} {1}".format(comments and ";" or " #", comment) import_statements.append(self._wrap(single_import_line)) comments = None import_statement = "\n".join(import_statements) else: star_import = False if "*" in from_imports: section_output.append(self._add_comments(comments, "{0}*".format(import_start))) from_imports.remove('*') star_import = True comments = None for from_import in copy.copy(from_imports): comment = self.comments['nested'].get(module, {}).pop(from_import, None) if comment: single_import_line = self._add_comments(comments, import_start + from_import) single_import_line += "{0} {1}".format(comments and ";" or " #", comment) above_comments = self.comments['above']['from'].pop(module, None) if above_comments: section_output.extend(above_comments) section_output.append(self._wrap(single_import_line)) from_imports.remove(from_import) comments = None if star_import: import_statement = import_start + (", ").join(from_imports) else: import_statement = self._add_comments(comments, import_start + (", ").join(from_imports)) if not from_imports: import_statement = "" if len(from_imports) > 1 and ( len(import_statement) > self.config['line_length'] or self.config.get('force_grid_wrap') ): output_mode = settings.WrapModes._fields[self.config.get('multi_line_output', 0)].lower() formatter = getattr(self, "_output_" + output_mode, self._output_grid) dynamic_indent = " " * (len(import_start) + 1) indent = self.config['indent'] line_length = self.config['wrap_length'] or self.config['line_length'] import_statement = formatter(import_start, copy.copy(from_imports), dynamic_indent, indent, line_length, comments) if self.config['balanced_wrapping']: lines = import_statement.split("\n") line_count = len(lines) if len(lines) > 1: minimum_length = min([len(line) for line in lines[:-1]]) else: minimum_length = 0 new_import_statement = import_statement while (len(lines[-1]) < minimum_length and len(lines) == line_count and line_length > 10): import_statement = new_import_statement line_length -= 1 new_import_statement = formatter(import_start, copy.copy(from_imports), dynamic_indent, indent, line_length, comments) lines = new_import_statement.split("\n") elif len(import_statement) > self.config['line_length']: import_statement = self._wrap(import_statement) if import_statement: above_comments = self.comments['above']['from'].pop(module, None) if above_comments: section_output.extend(above_comments) section_output.append(import_statement) def _add_formatted_imports(self): """Adds the imports back to the file. (at the index of the first import) sorted alphabetically and split between groups """ if self.config.get('force_alphabetical_sort', False): from_output = [] straight_output = [] for section in itertools.chain(self.sections, self.config['forced_separate']): straight_modules = list(self.imports[section]['straight']) from_modules = list(self.imports[section]['from'].keys()) self._add_from_imports(from_modules, section, from_output) self._add_straight_imports(straight_modules, section, straight_output) new_from_output = [] new_straight_output = [] for line in from_output: for element in line.split('\n'): new_from_output.append(element) for line in straight_output: for element in line.split('\n'): new_straight_output.append(element) sorted_from = sorted(new_from_output, key=lambda import_string: import_string.lower()) sorted_straight = sorted(new_straight_output, key=lambda import_string: import_string.lower()) output = (sorted_from + [''] + sorted_straight) if (sorted_from and sorted_straight) else \ (sorted_from or sorted_straight) else: output = [] for section in itertools.chain(self.sections, self.config['forced_separate']): straight_modules = list(self.imports[section]['straight']) straight_modules = nsorted(straight_modules, key=lambda key: self._module_key(key, self.config)) from_modules = sorted(list(self.imports[section]['from'].keys())) from_modules = nsorted(from_modules, key=lambda key: self._module_key(key, self.config, )) section_output = [] if self.config.get('from_first', False): self._add_from_imports(from_modules, section, section_output) self._add_straight_imports(straight_modules, section, section_output) else: self._add_straight_imports(straight_modules, section, section_output) self._add_from_imports(from_modules, section, section_output) if self.config.get('force_sort_within_sections', False): def by_module(line): line = re.sub('^from ', '', line) line = re.sub('^import ', '', line) if not self.config['order_by_type']: line = line.lower() return line section_output = nsorted(section_output, key=by_module) if section_output: section_name = section if section_name in self.place_imports: self.place_imports[section_name] = section_output continue section_title = self.config.get('import_heading_' + str(section_name).lower(), '') if section_title: section_comment = "# {0}".format(section_title) if not section_comment in self.out_lines[0:1]: section_output.insert(0, section_comment) output += section_output + [''] while [character.strip() for character in output[-1:]] == [""]: output.pop() output_at = 0 if self.import_index < self.original_length: output_at = self.import_index elif self._first_comment_index_end != -1 and self._first_comment_index_start <= 2: output_at = self._first_comment_index_end self.out_lines[output_at:0] = output imports_tail = output_at + len(output) while [character.strip() for character in self.out_lines[imports_tail: imports_tail + 1]] == [""]: self.out_lines.pop(imports_tail) if len(self.out_lines) > imports_tail: next_construct = "" self._in_quote = False for line in self.out_lines[imports_tail:]: if not self._skip_line(line) and not line.strip().startswith("#") and line.strip(): next_construct = line break 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("@"): self.out_lines[imports_tail:0] = ["", ""] else: self.out_lines[imports_tail:0] = [""] if self.place_imports: new_out_lines = [] for index, line in enumerate(self.out_lines): new_out_lines.append(line) if line in self.import_placements: new_out_lines.extend(self.place_imports[self.import_placements[line]]) if len(self.out_lines) <= index or self.out_lines[index + 1].strip() != "": new_out_lines.append("") self.out_lines = new_out_lines def _output_grid(self, statement, imports, white_space, indent, line_length, comments): statement += "(" + imports.pop(0) while imports: next_import = imports.pop(0) next_statement = self._add_comments(comments, statement + ", " + next_import) if len(next_statement.split("\n")[-1]) + 1 > line_length: statement = (self._add_comments(comments, "{0},".format(statement)) + "\n{0}{1}".format(white_space, next_import)) comments = None else: statement += ", " + next_import return statement + ("," if self.config['include_trailing_comma'] else "") + ")" def _output_vertical(self, statement, imports, white_space, indent, line_length, comments): first_import = self._add_comments(comments, imports.pop(0) + ",") + "\n" + white_space return "{0}({1}{2}{3})".format( statement, first_import, (",\n" + white_space).join(imports), "," if self.config['include_trailing_comma'] else "", ) def _output_hanging_indent(self, statement, imports, white_space, indent, line_length, comments): statement += imports.pop(0) while imports: next_import = imports.pop(0) next_statement = self._add_comments(comments, statement + ", " + next_import) if len(next_statement.split("\n")[-1]) + 3 > line_length: next_statement = (self._add_comments(comments, "{0}, \\".format(statement)) + "\n{0}{1}".format(indent, next_import)) comments = None statement = next_statement return statement def _output_vertical_hanging_indent(self, statement, imports, white_space, indent, line_length, comments): return "{0}({1}\n{2}{3}{4}\n)".format( statement, self._add_comments(comments), indent, (",\n" + indent).join(imports), "," if self.config['include_trailing_comma'] else "", ) def _output_vertical_grid_common(self, statement, imports, white_space, indent, line_length, comments): statement += self._add_comments(comments, "(") + "\n" + indent + imports.pop(0) while imports: next_import = imports.pop(0) next_statement = "{0}, {1}".format(statement, next_import) if len(next_statement.split("\n")[-1]) + 1 > line_length: next_statement = "{0},\n{1}{2}".format(statement, indent, next_import) statement = next_statement if self.config['include_trailing_comma']: statement += ',' return statement def _output_vertical_grid(self, statement, imports, white_space, indent, line_length, comments): return self._output_vertical_grid_common(statement, imports, white_space, indent, line_length, comments) + ")" def _output_vertical_grid_grouped(self, statement, imports, white_space, indent, line_length, comments): return self._output_vertical_grid_common(statement, imports, white_space, indent, line_length, comments) + "\n)" def _output_noqa(self, statement, imports, white_space, indent, line_length, comments): retval = '{0}{1}'.format(statement, ' '.join(imports)) comment_str = ' '.join(comments) if comments: if len(retval) + 4 + len(comment_str) <= line_length: return '{0} # {1}'.format(retval, comment_str) else: if len(retval) <= line_length: return retval if comments: if "NOQA" in comments: return '{0} # {1}'.format(retval, comment_str) else: return '{0} # NOQA {1}'.format(retval, comment_str) else: return '{0} # NOQA'.format(retval) @staticmethod def _strip_comments(line, comments=None): """Removes comments from import line.""" if comments is None: comments = [] new_comments = False comment_start = line.find("#") if comment_start != -1: comments.append(line[comment_start + 1:].strip()) new_comments = True line = line[:comment_start] return line, comments, new_comments @staticmethod def _format_simplified(import_line): import_line = import_line.strip() if import_line.startswith("from "): import_line = import_line.replace("from ", "") import_line = import_line.replace(" import ", ".") elif import_line.startswith("import "): import_line = import_line.replace("import ", "") return import_line @staticmethod def _format_natural(import_line): import_line = import_line.strip() if not import_line.startswith("from ") and not import_line.startswith("import "): if not "." in import_line: return "import {0}".format(import_line) parts = import_line.split(".") end = parts.pop(-1) return "from {0} import {1}".format(".".join(parts), end) return import_line def _skip_line(self, line): skip_line = self._in_quote if self.index == 1 and line.startswith("#"): self._in_top_comment = True return True elif self._in_top_comment: if not line.startswith("#"): self._in_top_comment = False self._first_comment_index_end = self.index if '"' in line or "'" in line: index = 0 if self._first_comment_index_start == -1: self._first_comment_index_start = self.index while index < len(line): if line[index] == "\\": index += 1 elif self._in_quote: if line[index:index + len(self._in_quote)] == self._in_quote: self._in_quote = False if self._first_comment_index_end < self._first_comment_index_start: self._first_comment_index_end = self.index elif line[index] in ("'", '"'): long_quote = line[index:index + 3] if long_quote in ('"""', "'''"): self._in_quote = long_quote index += 2 else: self._in_quote = line[index] elif line[index] == "#": break index += 1 return skip_line or self._in_quote or self._in_top_comment def _strip_syntax(self, import_string): import_string = import_string.replace("_import", "[[i]]") for remove_syntax in ['\\', '(', ')', ',']: import_string = import_string.replace(remove_syntax, " ") import_list = import_string.split() for key in ('from', 'import'): if key in import_list: import_list.remove(key) import_string = ' '.join(import_list) import_string = import_string.replace("[[i]]", "_import") return import_string.replace("{ ", "{|").replace(" }", "|}") def _parse(self): """Parses a python file taking out and categorizing imports.""" self._in_quote = False self._in_top_comment = False while not self._at_end(): line = self._get_line() skip_line = self._skip_line(line) if line in self._section_comments and not skip_line: if self.import_index == -1: self.import_index = self.index - 1 continue if "isort:" + "imports-" in line and line.startswith("#"): section = line.split("isort:" + "imports-")[-1].split()[0] self.place_imports[section.upper()] = [] self.import_placements[line] = section.upper() if ";" in line: for part in (part.strip() for part in line.split(";")): if part and not part.startswith("from ") and not part.startswith("import "): skip_line = True import_type = self._import_type(line) if not import_type or skip_line: self.out_lines.append(line) continue for line in (line.strip() for line in line.split(";")): import_type = self._import_type(line) if not import_type: self.out_lines.append(line) continue line = line.replace("\t", " ") if self.import_index == -1: self.import_index = self.index - 1 nested_comments = {} import_string, comments, new_comments = self._strip_comments(line) stripped_line = [part for part in self._strip_syntax(import_string).strip().split(" ") if part] if import_type == "from" and len(stripped_line) == 2 and stripped_line[1] != "*" and new_comments: nested_comments[stripped_line[-1]] = comments[0] if "(" in line and not self._at_end(): while not line.strip().endswith(")") and not self._at_end(): line, comments, new_comments = self._strip_comments(self._get_line(), comments) stripped_line = self._strip_syntax(line).strip() if import_type == "from" and stripped_line and not " " in stripped_line and new_comments: nested_comments[stripped_line] = comments[-1] import_string += "\n" + line else: while line.strip().endswith("\\"): line, comments, new_comments = self._strip_comments(self._get_line(), comments) stripped_line = self._strip_syntax(line).strip() if import_type == "from" and stripped_line and not " " in stripped_line and new_comments: nested_comments[stripped_line] = comments[-1] if import_string.strip().endswith(" import") or line.strip().startswith("import "): import_string += "\n" + line else: import_string = import_string.rstrip().rstrip("\\") + line.lstrip() if import_type == "from": parts = import_string.split(" import ") from_import = parts[0].split(" ") import_string = " import ".join([from_import[0] + " " + "".join(from_import[1:])] + parts[1:]) imports = [item.replace("{|", "{ ").replace("|}", " }") for item in self._strip_syntax(import_string).split()] if "as" in imports and (imports.index('as') + 1) < len(imports): while "as" in imports: index = imports.index('as') if import_type == "from": module = imports[0] + "." + imports[index - 1] self.as_map[module] = imports[index + 1] else: module = imports[index - 1] self.as_map[module] = imports[index + 1] if not self.config['combine_as_imports']: self.comments['straight'][module] = comments comments = [] del imports[index:index + 2] if import_type == "from": import_from = imports.pop(0) placed_module = self.place_module(import_from) if placed_module == '': print( "WARNING: could not place module {0} of line {1} --" " Do you need to define a default section?".format(import_from, line) ) root = self.imports[placed_module][import_type] for import_name in imports: associated_commment = nested_comments.get(import_name) if associated_commment: self.comments['nested'].setdefault(import_from, {})[import_name] = associated_commment comments.pop(comments.index(associated_commment)) if comments: self.comments['from'].setdefault(import_from, []).extend(comments) if len(self.out_lines) > max(self.import_index, self._first_comment_index_end, 1) - 1: last = self.out_lines and self.out_lines[-1].rstrip() or "" while last.startswith("#") and not last.endswith('"""') and not last.endswith("'''"): self.comments['above']['from'].setdefault(import_from, []).insert(0, self.out_lines.pop(-1)) if len(self.out_lines) > max(self.import_index - 1, self._first_comment_index_end, 1) - 1: last = self.out_lines[-1].rstrip() else: last = "" if self.index - 1 == self.import_index: self.import_index -= len(self.comments['above']['from'].get(import_from, [])) if root.get(import_from, False): root[import_from].update(imports) else: root[import_from] = set(imports) else: for module in imports: if comments: self.comments['straight'][module] = comments comments = None if len(self.out_lines) > max(self.import_index, self._first_comment_index_end, 1) - 1: last = self.out_lines and self.out_lines[-1].rstrip() or "" while last.startswith("#") and not last.endswith('"""') and not last.endswith("'''"): self.comments['above']['straight'].setdefault(module, []).insert(0, self.out_lines.pop(-1)) if len(self.out_lines) > max(self.import_index - 1, self._first_comment_index_end, 1) - 1: last = self.out_lines[-1].rstrip() else: last = "" if self.index - 1 == self.import_index: self.import_index -= len(self.comments['above']['straight'].get(module, [])) placed_module = self.place_module(module) if placed_module == '': print( "WARNING: could not place module {0} of line {1} --" " Do you need to define a default section?".format(import_from, line) ) self.imports[placed_module][import_type].add(module) def coding_check(fname, default='utf-8'): # see https://www.python.org/dev/peps/pep-0263/ pattern = re.compile(br'coding[:=]\s*([-\w.]+)') coding = default with io.open(fname, 'rb') as f: for line_number, line in enumerate(f, 1): groups = re.findall(pattern, line) if groups: coding = groups[0].decode('ascii') break if line_number > 2: break return coding isort-4.2.2/isort/main.py000077500000000000000000000354521260070737300153360ustar00rootroot00000000000000#! /usr/bin/env python ''' Tool for sorting imports alphabetically, and automatically separated into sections. Copyright (C) 2013 Timothy Edmund Crosley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' from __future__ import absolute_import, division, print_function, unicode_literals import argparse import glob import os import sys import setuptools from isort import SortImports, __version__ from isort.settings import DEFAULT_SECTIONS, default, from_path, should_skip from .pie_slice import * INTRO = """ /#######################################################################\\ `sMMy` .yyyy- ` ##soos## ./o. ` ``..-..` ``...`.`` ` ```` ``-ssso``` .s:-y- .+osssssso/. ./ossss+:so+:` :+o-`/osso:+sssssssso/ .s::y- osss+.``.`` -ssss+-.`-ossso` ssssso/::..::+ssss:::. .s::y- /ssss+//:-.` `ssss+ `ssss+ sssso` :ssss` .s::y- `-/+oossssso/ `ssss/ sssso ssss/ :ssss` .y-/y- ````:ssss` ossso. :ssss: ssss/ :ssss. `/so:` `-//::/osss+ `+ssss+-/ossso: /sso- `osssso/. \/ `-/oooo++/- .:/++:/++/-` .. `://++/. isort your Python imports for you so you don't have to VERSION {0} \########################################################################/ """.format(__version__) def iter_source_code(paths, config, skipped): """Iterate over all Python source files defined in paths.""" for path in paths: if os.path.isdir(path): if should_skip(path, config): skipped.append(path) continue for dirpath, dirnames, filenames in os.walk(path, topdown=True): for dirname in list(dirnames): if should_skip(dirname, config): skipped.append(dirname) dirnames.remove(dirname) for filename in filenames: if filename.endswith('.py'): if should_skip(filename, config): skipped.append(filename) else: yield os.path.join(dirpath, filename) else: yield path class ISortCommand(setuptools.Command): """The :class:`ISortCommand` class is used by setuptools to perform imports checks on registered modules. """ description = "Run isort on modules registered in setuptools" user_options = [] def initialize_options(self): default_settings = default.copy() for (key, value) in itemsview(default_settings): setattr(self, key, value) def finalize_options(self): "Get options from config files." self.arguments = {} computed_settings = from_path(os.getcwd()) for (key, value) in itemsview(computed_settings): self.arguments[key] = value def distribution_files(self): """Find distribution packages.""" # This is verbatim from flake8 if self.distribution.packages: package_dirs = self.distribution.package_dir or {} for package in self.distribution.packages: pkg_dir = package if package in package_dirs: pkg_dir = package_dirs[package] elif '' in package_dirs: pkg_dir = package_dirs[''] + os.path.sep + pkg_dir yield pkg_dir.replace('.', os.path.sep) if self.distribution.py_modules: for filename in self.distribution.py_modules: yield "%s.py" % filename # Don't miss the setup.py file itself yield "setup.py" def run(self): arguments = self.arguments wrong_sorted_files = False arguments['check'] = True for path in self.distribution_files(): for python_file in glob.iglob(os.path.join(path, '*.py')): try: incorrectly_sorted = SortImports(python_file, **arguments).incorrectly_sorted if incorrectly_sorted: wrong_sorted_files = True except IOError as e: print("WARNING: Unable to parse file {0} due to {1}".format(file_name, e)) if wrong_sorted_files: exit(1) def create_parser(): 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('-y', '--apply', dest='apply', action='store_true', help='Tells isort to apply changes recursively without asking') 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. If you want to skip multiple ' 'files you should specify twice: --skip file1 --skip file2.', dest='skip', action='append') parser.add_argument('-ns', '--dont-skip', help='Files that sort imports should never skip over.', dest='not_skip', action='append') parser.add_argument('-sg', '--skip-glob', help='Files that sort imports should skip over.', dest='skip_glob', action='append') parser.add_argument('-t', '--top', help='Force specific imports to the top of their appropriate section.', dest='force_to_top', action='append') parser.add_argument('-f', '--future', dest='known_future_library', action='append', help='Force sortImports to recognize a module as part of the future compatibility libraries.') parser.add_argument('-b', '--builtin', dest='known_standard_library', action='append', help='Force sortImports to recognize a module as part of the python standard library.') parser.add_argument('-o', '--thirdparty', dest='known_third_party', action='append', help='Force sortImports to recognize a module as being part of a third party library.') parser.add_argument('-p', '--project', dest='known_first_party', action='append', help='Force sortImports to recognize a module as being part of the current python project.') parser.add_argument('-m', '--multi_line', dest='multi_line_output', type=int, choices=[0, 1, 2, 3, 4, 5], help='Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging, 4-vert-grid, ' '5-vert-grid-grouped).') parser.add_argument('-i', '--indent', help='String to place for indents defaults to " " (4 spaces).', dest='indent', type=str) parser.add_argument('-a', '--add_import', dest='add_imports', action='append', help='Adds the specified import line to all files, ' 'automatically determining correct placement.') parser.add_argument('-af', '--force_adds', dest='force_adds', action='store_true', help='Forces import adds even if the original file is empty.') parser.add_argument('-r', '--remove_import', dest='remove_imports', action='append', help='Removes the specified import from all files.') parser.add_argument('-ls', '--length_sort', help='Sort imports by their string length.', dest='length_sort', action='store_true', default=False) parser.add_argument('-d', '--stdout', help='Force resulting output to stdout, instead of in-place.', dest='write_to_stdout', action='store_true') parser.add_argument('-c', '--check-only', action='store_true', default=False, dest="check", help='Checks the file for unsorted / unformatted imports and prints them to the ' 'command line without modifying the file.') parser.add_argument('-sl', '--force_single_line_imports', dest='force_single_line', action='store_true', help='Forces all from imports to appear on their own line') parser.add_argument('-sd', '--section-default', dest='default_section', help='Sets the default section for imports (by default FIRSTPARTY) options: ' + str(DEFAULT_SECTIONS)) parser.add_argument('-df', '--diff', dest='show_diff', default=False, action='store_true', help="Prints a diff of all the changes isort would make to a file, instead of " "changing it in place") parser.add_argument('-e', '--balanced', dest='balanced_wrapping', action='store_true', help='Balances wrapping to produce the most consistent line length possible') parser.add_argument('-rc', '--recursive', dest='recursive', action='store_true', help='Recursively look for Python files of which to sort imports') parser.add_argument('-ot', '--order-by-type', dest='order_by_type', action='store_true', help='Order imports by type in addition to alphabetically') parser.add_argument('-ac', '--atomic', dest='atomic', action='store_true', help="Ensures the output doesn't save if the resulting file contains syntax errors.") parser.add_argument('-cs', '--combine-star', dest='combine_star', action='store_true', help="Ensures that if a star import is present, nothing else is imported from that namespace.") parser.add_argument('-ca', '--combine-as', dest='combine_as_imports', action='store_true', help="Combines as imports on the same line.") parser.add_argument('-tc', '--trailing-comma', dest='include_trailing_comma', action='store_true', help='Includes a trailing comma on multi line imports that include parentheses.') parser.add_argument('-v', '--version', action='store_true', dest='show_version') parser.add_argument('-vb', '--verbose', action='store_true', dest="verbose", help='Shows verbose output, such as when files are skipped or when a check is successful.') parser.add_argument('-q', '--quiet', action='store_true', dest="quiet", help='Shows extra quiet output, only errors are outputted.') parser.add_argument('-sp', '--settings-path', dest="settings_path", help='Explicitly set the settings path instead of auto determining based on file location.') parser.add_argument('-ff', '--from-first', dest='from_first', help="Switches the typical ordering preference, showing from imports first then straight ones.") parser.add_argument('-wl', '--wrap-length', dest='wrap_length', help="Specifies how long lines that are wrapped should be, if not set line_length is used.") parser.add_argument('-fgw', '--force-grid-wrap', action='store_true', dest="force_grid_wrap", help='Force from imports to be grid wrapped regardless of line length') parser.add_argument('-fas', '--force-alphabetical-sort', action='store_true', dest="force_alphabetical_sort", help='Force all imports to be sorted as a single section') parser.add_argument('-fss', '--force-sort-within-sections', action='store_true', dest="force_sort_within_sections", help='Force imports to be sorted by module, independant of import_type') arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value) return arguments def main(): arguments = create_parser() if arguments.get('show_version'): print(INTRO) return file_names = arguments.pop('files', []) if file_names == ['-']: SortImports(file_contents=sys.stdin.read(), write_to_stdout=True, **arguments) else: if not file_names: file_names = ['.'] arguments['recursive'] = True if not arguments.get('apply', False): arguments['ask_to_apply'] = True config = from_path(os.path.abspath(file_names[0]) or os.getcwd()).copy() config.update(arguments) wrong_sorted_files = False skipped = [] if arguments.get('recursive', False): file_names = iter_source_code(file_names, config, skipped) num_skipped = 0 if config.get('verbose', False) or config.get('show_logo', False): print(INTRO) for file_name in file_names: try: sort_attempt = SortImports(file_name, **arguments) incorrectly_sorted = sort_attempt.incorrectly_sorted if arguments.get('check', False) and incorrectly_sorted: wrong_sorted_files = True if sort_attempt.skipped: num_skipped += 1 except IOError as e: print("WARNING: Unable to parse file {0} due to {1}".format(file_name, e)) if wrong_sorted_files: exit(1) num_skipped += len(skipped) if num_skipped and not arguments.get('quiet', False): if config['verbose']: for was_skipped in skipped: print("WARNING: {0} was skipped as it's listed in 'skip' setting" " or matches a glob in 'skip_glob' setting".format(was_skipped)) print("Skipped {0} files".format(num_skipped)) if __name__ == "__main__": main() isort-4.2.2/isort/natural.py000066400000000000000000000033551260070737300160520ustar00rootroot00000000000000"""isort/natural.py. Enables sorting strings that contain numbers naturally usage: natural.nsorted(list) Copyright (C) 2013 Timothy Edmund Crosley Implementation originally from @HappyLeapSecond stack overflow user in response to: http://stackoverflow.com/questions/5967500/how-to-correctly-sort-a-string-with-a-number-inside Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import re def _atoi(text): return int(text) if text.isdigit() else text def _natural_keys(text): return [_atoi(c) for c in re.split('(\d+)', text)] def nsorted(to_sort, key=None): """Returns a naturally sorted list""" if not key: key_callback = _natural_keys else: key_callback = lambda item: _natural_keys(key(item)) return sorted(to_sort, key=key_callback) isort-4.2.2/isort/pie_slice.py000066400000000000000000000427711260070737300163450ustar00rootroot00000000000000"""pie_slice/overrides.py. Overrides Python syntax to conform to the Python3 version as much as possible using a '*' import Copyright (C) 2013 Timothy Edmund Crosley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copie_slice of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copie_slice or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from __future__ import absolute_import import abc import functools import sys from numbers import Integral __version__ = "1.1.0" PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 VERSION = sys.version_info native_dict = dict native_round = round native_filter = filter native_map = map native_zip = zip native_range = range native_str = str native_chr = chr native_input = input native_next = next native_object = object common = ['native_dict', 'native_round', 'native_filter', 'native_map', 'native_range', 'native_str', 'native_chr', 'native_input', 'PY2', 'PY3', 'u', 'itemsview', 'valuesview', 'keysview', 'execute', 'integer_types', 'native_next', 'native_object', 'with_metaclass', 'OrderedDict', 'lru_cache'] def with_metaclass(meta, *bases): """Enables use of meta classes across Python Versions. taken from jinja2/_compat.py. Use it like this:: class BaseForm(object): pass class FormType(type): pass class Form(with_metaclass(FormType, BaseForm)): pass """ class metaclass(meta): __call__ = type.__call__ __init__ = type.__init__ def __new__(cls, name, this_bases, d): if this_bases is None: return type.__new__(cls, name, (), d) return meta(name, bases, d) return metaclass('temporary_class', None, {}) def unmodified_isinstance(*bases): """When called in the form MyOverrideClass(unmodified_isinstance(BuiltInClass)) it allows calls against passed in built in instances to pass even if there not a subclass """ class UnmodifiedIsInstance(type): if sys.version_info[0] == 2 and sys.version_info[1] <= 6: @classmethod def __instancecheck__(cls, instance): if cls.__name__ in (str(base.__name__) for base in bases): return isinstance(instance, bases) subclass = getattr(instance, '__class__', None) subtype = type(instance) instance_type = getattr(abc, '_InstanceType', None) if not instance_type: class test_object: pass instance_type = type(test_object) if subtype is instance_type: subtype = subclass if subtype is subclass or subclass is None: return cls.__subclasscheck__(subtype) return (cls.__subclasscheck__(subclass) or cls.__subclasscheck__(subtype)) else: @classmethod def __instancecheck__(cls, instance): if cls.__name__ in (str(base.__name__) for base in bases): return isinstance(instance, bases) return type.__instancecheck__(cls, instance) return with_metaclass(UnmodifiedIsInstance, *bases) if PY3: import urllib import builtins from urllib import parse integer_types = (int, ) def u(string): return string def itemsview(collection): return collection.items() def valuesview(collection): return collection.values() def keysview(collection): return collection.keys() urllib.quote = parse.quote urllib.quote_plus = parse.quote_plus urllib.unquote = parse.unquote urllib.unquote_plus = parse.unquote_plus urllib.urlencode = parse.urlencode execute = getattr(builtins, 'exec') if VERSION[1] < 2: def callable(entity): return hasattr(entity, '__call__') common.append('callable') __all__ = common + ['urllib'] else: from itertools import ifilter as filter from itertools import imap as map from itertools import izip as zip from decimal import Decimal, ROUND_HALF_EVEN import codecs str = unicode chr = unichr input = raw_input range = xrange integer_types = (int, long) import sys stdout = sys.stdout stderr = sys.stderr reload(sys) sys.stdout = stdout sys.stderr = stderr sys.setdefaultencoding('utf-8') def _create_not_allowed(name): def _not_allow(*args, **kwargs): raise NameError("name '{0}' is not defined".format(name)) _not_allow.__name__ = name return _not_allow for removed in ('apply', 'cmp', 'coerce', 'execfile', 'raw_input', 'unpacks'): globals()[removed] = _create_not_allowed(removed) def u(s): if isinstance(s, unicode): return s else: return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") def execute(_code_, _globs_=None, _locs_=None): """Execute code in a namespace.""" if _globs_ is None: frame = sys._getframe(1) _globs_ = frame.f_globals if _locs_ is None: _locs_ = frame.f_locals del frame elif _locs_ is None: _locs_ = _globs_ exec("""exec _code_ in _globs_, _locs_""") class _dict_view_base(object): __slots__ = ('_dictionary', ) def __init__(self, dictionary): self._dictionary = dictionary def __repr__(self): return "{0}({1})".format(self.__class__.__name__, str(list(self.__iter__()))) def __unicode__(self): return str(self.__repr__()) def __str__(self): return str(self.__unicode__()) class dict_keys(_dict_view_base): __slots__ = () def __iter__(self): return self._dictionary.iterkeys() class dict_values(_dict_view_base): __slots__ = () def __iter__(self): return self._dictionary.itervalues() class dict_items(_dict_view_base): __slots__ = () def __iter__(self): return self._dictionary.iteritems() def itemsview(collection): return dict_items(collection) def valuesview(collection): return dict_values(collection) def keysview(collection): return dict_keys(collection) class dict(unmodified_isinstance(native_dict)): def has_key(self, *args, **kwargs): return AttributeError("'dict' object has no attribute 'has_key'") def items(self): return dict_items(self) def keys(self): return dict_keys(self) def values(self): return dict_values(self) def round(number, ndigits=None): return_int = False if ndigits is None: return_int = True ndigits = 0 if hasattr(number, '__round__'): return number.__round__(ndigits) if ndigits < 0: raise NotImplementedError('negative ndigits not supported yet') exponent = Decimal('10') ** (-ndigits) d = Decimal.from_float(number).quantize(exponent, rounding=ROUND_HALF_EVEN) if return_int: return int(d) else: return float(d) def next(iterator): try: iterator.__next__() except Exception: native_next(iterator) class FixStr(type): def __new__(cls, name, bases, dct): if '__str__' in dct: dct['__unicode__'] = dct['__str__'] dct['__str__'] = lambda self: self.__unicode__().encode('utf-8') return type.__new__(cls, name, bases, dct) if sys.version_info[1] <= 6: def __instancecheck__(cls, instance): if cls.__name__ == "object": return isinstance(instance, native_object) subclass = getattr(instance, '__class__', None) subtype = type(instance) instance_type = getattr(abc, '_InstanceType', None) if not instance_type: class test_object: pass instance_type = type(test_object) if subtype is instance_type: subtype = subclass if subtype is subclass or subclass is None: return cls.__subclasscheck__(subtype) return (cls.__subclasscheck__(subclass) or cls.__subclasscheck__(subtype)) else: def __instancecheck__(cls, instance): if cls.__name__ == "object": return isinstance(instance, native_object) return type.__instancecheck__(cls, instance) class object(with_metaclass(FixStr, object)): pass __all__ = common + ['round', 'dict', 'apply', 'cmp', 'coerce', 'execfile', 'raw_input', 'unpacks', 'str', 'chr', 'input', 'range', 'filter', 'map', 'zip', 'object'] if sys.version_info[0] == 2 and sys.version_info[1] < 7: # OrderedDict # Copyright (c) 2009 Raymond Hettinger # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. from UserDict import DictMixin class OrderedDict(dict, DictMixin): def __init__(self, *args, **kwds): if len(args) > 1: raise TypeError('expected at most 1 arguments, got %d' % len(args)) try: self.__end except AttributeError: self.clear() self.update(*args, **kwds) def clear(self): self.__end = end = [] end += [None, end, end] # sentinel node for doubly linked list self.__map = {} # key --> [key, prev, next] dict.clear(self) def __setitem__(self, key, value): if key not in self: end = self.__end curr = end[1] curr[2] = end[1] = self.__map[key] = [key, curr, end] dict.__setitem__(self, key, value) def __delitem__(self, key): dict.__delitem__(self, key) key, prev, next = self.__map.pop(key) prev[2] = next next[1] = prev def __iter__(self): end = self.__end curr = end[2] while curr is not end: yield curr[0] curr = curr[2] def __reversed__(self): end = self.__end curr = end[1] while curr is not end: yield curr[0] curr = curr[1] def popitem(self, last=True): if not self: raise KeyError('dictionary is empty') if last: key = reversed(self).next() else: key = iter(self).next() value = self.pop(key) return key, value def __reduce__(self): items = [[k, self[k]] for k in self] tmp = self.__map, self.__end del self.__map, self.__end inst_dict = vars(self).copy() self.__map, self.__end = tmp if inst_dict: return (self.__class__, (items,), inst_dict) return self.__class__, (items,) def keys(self): return list(self) setdefault = DictMixin.setdefault update = DictMixin.update pop = DictMixin.pop values = DictMixin.values items = DictMixin.items iterkeys = DictMixin.iterkeys itervalues = DictMixin.itervalues iteritems = DictMixin.iteritems def __repr__(self): if not self: return '%s()' % (self.__class__.__name__,) return '%s(%r)' % (self.__class__.__name__, self.items()) def copy(self): return self.__class__(self) @classmethod def fromkeys(cls, iterable, value=None): d = cls() for key in iterable: d[key] = value return d def __eq__(self, other): if isinstance(other, OrderedDict): if len(self) != len(other): return False for p, q in zip(self.items(), other.items()): if p != q: return False return True return dict.__eq__(self, other) def __ne__(self, other): return not self == other else: from collections import OrderedDict if sys.version_info < (3, 2): try: from threading import Lock except ImportError: from dummy_threading import Lock from functools import wraps def lru_cache(maxsize=100): """Least-recently-used cache decorator. Taking from: https://github.com/MiCHiLU/python-functools32/blob/master/functools32/functools32.py with slight modifications. If *maxsize* is set to None, the LRU features are disabled and the cache can grow without bound. Arguments to the cached function must be hashable. View the cache statistics named tuple (hits, misses, maxsize, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.__wrapped__. See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used """ def decorating_function(user_function, tuple=tuple, sorted=sorted, len=len, KeyError=KeyError): hits, misses = [0], [0] kwd_mark = (object(),) # separates positional and keyword args lock = Lock() if maxsize is None: CACHE = dict() @wraps(user_function) def wrapper(*args, **kwds): key = args if kwds: key += kwd_mark + tuple(sorted(kwds.items())) try: result = CACHE[key] hits[0] += 1 return result except KeyError: pass result = user_function(*args, **kwds) CACHE[key] = result misses[0] += 1 return result else: CACHE = OrderedDict() @wraps(user_function) def wrapper(*args, **kwds): key = args if kwds: key += kwd_mark + tuple(sorted(kwds.items())) with lock: cached = CACHE.get(key, None) if cached: del CACHE[key] CACHE[key] = cached hits[0] += 1 return cached result = user_function(*args, **kwds) with lock: CACHE[key] = result # record recent use of this key misses[0] += 1 while len(CACHE) > maxsize: CACHE.popitem(last=False) return result def cache_info(): """Report CACHE statistics.""" with lock: return _CacheInfo(hits[0], misses[0], maxsize, len(CACHE)) def cache_clear(): """Clear the CACHE and CACHE statistics.""" with lock: CACHE.clear() hits[0] = misses[0] = 0 wrapper.cache_info = cache_info wrapper.cache_clear = cache_clear return wrapper return decorating_function else: from functools import lru_cache isort-4.2.2/isort/pylama_isort.py000066400000000000000000000013451260070737300171040ustar00rootroot00000000000000import os import sys from pylama.lint import Linter as BaseLinter from .isort import SortImports class Linter(BaseLinter): def allow(self, path): """Determine if this path should be linted.""" return path.endswith('.py') def run(self, path, **meta): """Lint the file. Return an array of error dicts if appropriate.""" with open(os.devnull, 'w') as devnull: # Suppress isort messages sys.stdout = devnull if SortImports(path, check=True).incorrectly_sorted: return [{ 'lnum': 0, 'col': 0, 'text': 'Incorrectly sorted imports.', 'type': 'ISORT' }] isort-4.2.2/isort/settings.py000066400000000000000000000234161260070737300162440ustar00rootroot00000000000000"""isort/settings.py. Defines how the default settings for isort should be loaded (First from the default setting dictionary at the top of the file, then overridden by any settings in ~/.isort.cfg if there are any) Copyright (C) 2013 Timothy Edmund Crosley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from __future__ import absolute_import, division, print_function, unicode_literals import fnmatch import os from collections import namedtuple from .pie_slice import * try: import configparser except ImportError: import ConfigParser as configparser MAX_CONFIG_SEARCH_DEPTH = 25 # The number of parent directories isort will look for a config file within DEFAULT_SECTIONS = ("FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER") WrapModes = ('GRID', 'VERTICAL', 'HANGING_INDENT', 'VERTICAL_HANGING_INDENT', 'VERTICAL_GRID', 'VERTICAL_GRID_GROUPED', 'NOQA') WrapModes = namedtuple('WrapModes', WrapModes)(*range(len(WrapModes))) # Note that none of these lists must be complete as they are simply fallbacks for when included auto-detection fails. default = {'force_to_top': [], 'skip': ['__init__.py', ], 'skip_glob': [], 'line_length': 79, 'wrap_length': 0, 'sections': DEFAULT_SECTIONS, 'known_future_library': ['__future__'], 'known_standard_library': ["abc", "anydbm", "argparse", "array", "asynchat", "asyncore", "atexit", "base64", "BaseHTTPServer", "bisect", "bz2", "calendar", "cgitb", "cmd", "codecs", "collections", "commands", "compileall", "ConfigParser", "contextlib", "Cookie", "copy", "cPickle", "cProfile", "cStringIO", "csv", "datetime", "dbhash", "dbm", "decimal", "difflib", "dircache", "dis", "doctest", "dumbdbm", "EasyDialogs", "errno", "exceptions", "filecmp", "fileinput", "fnmatch", "fractions", "functools", "gc", "gdbm", "getopt", "getpass", "gettext", "glob", "grp", "gzip", "hashlib", "heapq", "hmac", "imaplib", "imp", "inspect", "io", "itertools", "json", "linecache", "locale", "logging", "mailbox", "math", "mhlib", "mmap", "multiprocessing", "operator", "optparse", "os", "pdb", "pickle", "pipes", "pkgutil", "platform", "plistlib", "pprint", "profile", "pstats", "pwd", "pyclbr", "pydoc", "Queue", "random", "re", "readline", "resource", "rlcompleter", "robotparser", "sched", "select", "shelve", "shlex", "shutil", "signal", "SimpleXMLRPCServer", "site", "sitecustomize", "smtpd", "smtplib", "socket", "SocketServer", "sqlite3", "string", "StringIO", "struct", "subprocess", "sys", "sysconfig", "tabnanny", "tarfile", "tempfile", "textwrap", "threading", "time", "timeit", "trace", "traceback", "unittest", "urllib", "urllib2", "urlparse", "usercustomize", "uuid", "warnings", "weakref", "webbrowser", "whichdb", "xml", "xmlrpclib", "zipfile", "zipimport", "zlib", 'builtins', '__builtin__', 'thread', "binascii", "statistics", "unicodedata", "fcntl"], 'known_third_party': ['google.appengine.api'], 'known_first_party': [], 'multi_line_output': WrapModes.GRID, 'forced_separate': [], 'indent': ' ' * 4, 'length_sort': False, 'add_imports': [], 'remove_imports': [], 'force_single_line': False, 'default_section': 'FIRSTPARTY', 'import_heading_future': '', 'import_heading_stdlib': '', 'import_heading_thirdparty': '', 'import_heading_firstparty': '', 'import_heading_localfolder': '', 'balanced_wrapping': False, 'use_parentheses': False, 'order_by_type': True, 'atomic': False, 'lines_after_imports': -1, 'combine_as_imports': False, 'combine_star': False, 'include_trailing_comma': False, 'from_first': False, 'verbose': False, 'quiet': False} @lru_cache() def from_path(path): computed_settings = default.copy() _update_settings_with_config(path, '.editorconfig', '~/.editorconfig', ('*', '*.py', '**.py'), computed_settings) _update_settings_with_config(path, '.isort.cfg', '~/.isort.cfg', ('settings', 'isort'), computed_settings) _update_settings_with_config(path, 'setup.cfg', None, ('isort', ), computed_settings) return computed_settings def _update_settings_with_config(path, name, default, sections, computed_settings): editor_config_file = default and os.path.expanduser(default) tries = 0 current_directory = path while current_directory and tries < MAX_CONFIG_SEARCH_DEPTH: potential_path = os.path.join(current_directory, native_str(name)) if os.path.exists(potential_path): editor_config_file = potential_path break new_directory = os.path.split(current_directory)[0] if current_directory == new_directory: break current_directory = new_directory tries += 1 if editor_config_file and os.path.exists(editor_config_file): _update_with_config_file(editor_config_file, sections, computed_settings) def _update_with_config_file(file_path, sections, computed_settings): settings = _get_config_data(file_path, sections).copy() if not settings: return if file_path.endswith(".editorconfig"): indent_style = settings.pop('indent_style', "").strip() indent_size = settings.pop('indent_size', "").strip() if indent_style == "space": computed_settings['indent'] = " " * (indent_size and int(indent_size) or 4) elif indent_style == "tab": computed_settings['indent'] = "\t" * (indent_size and int(indent_size) or 1) max_line_length = settings.pop('max_line_length', "").strip() if max_line_length: computed_settings['line_length'] = int(max_line_length) for key, value in itemsview(settings): access_key = key.replace('not_', '').lower() existing_value_type = type(default.get(access_key, '')) if existing_value_type in (list, tuple): # sections has fixed order values; no adding or substraction from any set if access_key == 'sections': computed_settings[access_key] = tuple(_as_list(value)) else: existing_data = set(computed_settings.get(access_key, default.get(access_key))) if key.startswith('not_'): computed_settings[access_key] = list(existing_data.difference(_as_list(value))) else: computed_settings[access_key] = list(existing_data.union(_as_list(value))) elif existing_value_type == bool and value.lower().strip() == "false": computed_settings[access_key] = False elif key.startswith('known_'): computed_settings[access_key] = list(_as_list(value)) else: computed_settings[access_key] = existing_value_type(value) def _as_list(value): return filter(bool, [item.strip() for item in value.split(",")]) @lru_cache() def _get_config_data(file_path, sections): with open(file_path, 'rU') as config_file: if file_path.endswith(".editorconfig"): line = "\n" last_position = config_file.tell() while line: line = config_file.readline() if "[" in line: config_file.seek(last_position) break last_position = config_file.tell() config = configparser.SafeConfigParser() config.readfp(config_file) settings = dict() for section in sections: if config.has_section(section): settings.update(dict(config.items(section))) return settings return {} def should_skip(filename, config): """Returns True if the file should be skipped based on the passed in settings.""" for skip_path in config['skip']: if skip_path.endswith(filename): return True position = os.path.split(filename) while position[1]: if position[1] in config['skip']: return True position = os.path.split(position[0]) for glob in config['skip_glob']: if fnmatch.fnmatch(filename, glob): return True return False isort-4.2.2/kate_plugin/000077500000000000000000000000001260070737300151665ustar00rootroot00000000000000isort-4.2.2/kate_plugin/isort_plugin.py000066400000000000000000000061461260070737300202650ustar00rootroot00000000000000""" Sorts Python import definitions, and groups them based on type (stdlib, third-party, local). isort/isort_kate_plugin.py Provides a simple kate plugin that enables the use of isort to sort Python imports in the currently open kate file. Copyright (C) 2013 Timothy Edmund Crosley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import os import kate from isort import SortImports try: from PySide import QtGui except ImportError: from PyQt4 import QtGui def sort_kate_imports(add_imports=(), remove_imports=()): """Sorts imports within Kate while maintaining cursor position and selection, even if length of file changes.""" document = kate.activeDocument() view = document.activeView() position = view.cursorPosition() selection = view.selectionRange() sorter = SortImports(file_contents=document.text(), add_imports=add_imports, remove_imports=remove_imports, settings_path=os.path.dirname(os.path.abspath(str(document.url().path())))) document.setText(sorter.output) position.setLine(position.line() + sorter.length_change) if selection: start = selection.start() start.setLine(start.line() + sorter.length_change) end = selection.end() end.setLine(end.line() + sorter.length_change) selection.setRange(start, end) view.setSelection(selection) view.setCursorPosition(position) @kate.action def sort_imports(): """Sort Imports""" sort_kate_imports() @kate.action def add_imports(): """Add Imports""" text, ok = QtGui.QInputDialog.getText(None, 'Add Import', 'Enter an import line to add (example: from os import path or os.path):') if ok: sort_kate_imports(add_imports=text.split(";")) @kate.action def remove_imports(): """Remove Imports""" text, ok = QtGui.QInputDialog.getText(None, 'Remove Import', 'Enter an import line to remove (example: os.path or from os import path):') if ok: sort_kate_imports(remove_imports=text.split(";")) isort-4.2.2/kate_plugin/isort_plugin_old.py000066400000000000000000000063121260070737300211160ustar00rootroot00000000000000""" Sorts Python import definitions, and groups them based on type (stdlib, third-party, local). isort/isort_kate_plugin.py Provides a simple kate plugin that enables the use of isort to sort Python imports in the currently open kate file. Copyright (C) 2013 Timothy Edmund Crosley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import os import kate from isort import SortImports try: from PySide import QtGui except ImportError: from PyQt4 import QtGui def sort_kate_imports(add_imports=(), remove_imports=()): """Sorts imports within Kate while maintaining cursor position and selection, even if length of file changes.""" document = kate.activeDocument() view = document.activeView() position = view.cursorPosition() selection = view.selectionRange() sorter = SortImports(file_contents=document.text(), add_imports=add_imports, remove_imports=remove_imports, settings_path=os.path.dirname(os.path.abspath(str(document.url().path())))) document.setText(sorter.output) position.setLine(position.line() + sorter.length_change) if selection: start = selection.start() start.setLine(start.line() + sorter.length_change) end = selection.end() end.setLine(end.line() + sorter.length_change) selection.setRange(start, end) view.setSelection(selection) view.setCursorPosition(position) @kate.action(text="Sort Imports", shortcut="Ctrl+[", menu="Python") def sort_imports(): sort_kate_imports() @kate.action(text="Add Import", shortcut="Ctrl+]", menu="Python") def add_imports(): text, ok = QtGui.QInputDialog.getText(None, 'Add Import', 'Enter an import line to add (example: from os import path or os.path):') if ok: sort_kate_imports(add_imports=text.split(";")) @kate.action(text="Remove Import", shortcut="Ctrl+Shift+]", menu="Python") def remove_imports(): text, ok = QtGui.QInputDialog.getText(None, 'Remove Import', 'Enter an import line to remove (example: os.path or from os import path):') if ok: sort_kate_imports(remove_imports=text.split(";")) isort-4.2.2/kate_plugin/isort_plugin_ui.rc000066400000000000000000000013041260070737300207250ustar00rootroot00000000000000 &isort isort-4.2.2/kate_plugin/katepart_isort.desktop000066400000000000000000000002461260070737300216160ustar00rootroot00000000000000[Desktop Entry] Type=Service ServiceTypes=Kate/PythonPlugin X-KDE-Library=isort_plugin Name=isort Comment=Python import sorter and manager X-Python-2-Compatible=true isort-4.2.2/logo.png000066400000000000000000000217411260070737300143370ustar00rootroot00000000000000PNG  IHDRɅbKGDC pHYs  tIME  jtEXtCommentCreated with GIMPW IDATxyXT̰ 0* QbbbCo̓f77io[iiifiѨ D@Dmf`}*;s!k KZqFdee }:;;;\>n޼tF ! jxoV^xuE.O7oƊ+BuEtƍorss[oGYaa!oߎ~wΝtF !Wdl߾Νۯhw۶m.!aUUU;+~;{qVjϘ?'V@pՈ]vY%&i3 !duT){uxb)5xb]&1 o4S$zHtJaB!Sd0[W#A=.*m Ba7q8X (L!d")y „BԎ 0m8t废Sx~0`B34uj1V T`&vB!3N$Ѓ% *1LAABkO6,K-w  B+5x* &R!B !>g!S10a B  2Vz$6>[yxd|*TjB| h. Bo8-H0!/N ѭNKaBP8U}?AvBV΋ƺxH<כW(kTM+17.ԩǯoWZV)1fˆEX$'/f.kTDQEVkG'dtj=X5/?#Aᘿ' 2oxޥNTAk;fADXy\ ulغSǛPڠuHá0!V8T~[/يo*/[6"-Z:Eq18uNj;Wݲ!~I2)[m9G_AFeaH]5Q-sYʬ;:cJCHܝ>-@18Yӎv \K(z|]HOgqw'g.HFSj`obVÁ1Tf[wƓ;3$e_ 9Iki*5{'Emsk_oƋ̓UM3mnƻ ,Vliydt~:C-iwm8TG^=?d]#~MsѾy V~Ør pK6=~ zd#3ޑ)0rҫ^/AKW?3a~r7| $x|,ϐ#,P ?.qg$a~xd:ԃ.a}O)z-=hEH.S5iKPLdL縜Q)9IH \*AT?B>f& Aĕ`4Y,#LyS7kEAn"}|4H<5Ba2EZX(Kɂ\~̉”p$G#5*bpo QR߉q ch oZd-, /\`ϔ_ k]ڽ%J ͎x>Ą%0[l(Į5㚁j ]S$>$0 Ve=(uT  jpkq95siM <ܒbT Fܿ:7OL?rÑذ-Y{uƪ_;Fp0H.XÄW͏qˋj32dx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n/`K_1'e'ʜrMk2p}:lj7>/+_Ubi ÑP xpq#_/K}o/C7ͥڞai1.3ي5hh-7q̮k[|ף0Yz5:;;QTT4@d(((իWbCO~;q~*EqCU<.3["۲O\z f (z-a yy_b3xPm0Hh)jvF7VA5i+SR|u]3gf$w.\.} W t~7*_XYd ,H? A(ABhdAoS=A4qNхN-YKD:uu Memb<| j,LGAn"#ǖK%#ן<#R#Y R<hN?hii 0D% X17کTx#o{;KeCȿwaH-c;E%^iעX=vbeRG_?O۶m6^\("//Z݂Do@Y ,.*uzR ~>XGz*Z]rF&x+U/s,ǜ^#VYHK%xt|ܿ:ݣÂ8r2Y>jrv@!)2ѵü>L%=='(HKddM;^εB3h;"%=5B,u[ :/}qiA6-J`5R[Pig(r~ܼ >m.8SYT6]`KJa=L@,#,, b@,HZ-^i;PצƫS hj[dƇۙݔln\(<5u3y$*dh eUk2E\r¡3,P䆹^q}'˃f1[Z)n& ! tmh8ԠSU!">U.7lAR8VZ{{1zW."ܡsky *XNA;Iw,pp3"4ЏM|6ap !P[[ 6 a8u! oo)2d.{ͼHqAc݀j,KAddrn<.ω@ukߔ$]XYWNJ/nFR~H 2uի?4, 0"P,s%be|\<WdDy b7uROdt0d21}:Lâ:yId9ugib (wγpH~^GR\p32ɂ/M70:b!yؼ.@q wl>ݳ`(ܿ: dĆ"/5KD" 0Pm}hhנSGπjidy[p>whYz> !$BDK"AT?bv{th*.]Zz כGdj /5ODuT=*C'˃48$!„BCTB(L!PB0!B(L!PB0!BaB!PB0!BaB!„B0!BaB!„B !BaB!„B ! B!„B ! B!&B ! B!&B(L! B!&B(L!PB!~ĘFIENDB`isort-4.2.2/setup.cfg000066400000000000000000000002051260070737300145020ustar00rootroot00000000000000[wheel] universal = 1 [flake8] ignore = F401,F403,E502,E123,E127,E128,E303,E713,E111,E241,E302,E121,E261,W391 max-line-length = 160 isort-4.2.2/setup.py000077500000000000000000000052631260070737300144070ustar00rootroot00000000000000#!/usr/bin/env python import subprocess import sys try: from setuptools import setup from setuptools.command.test import test as TestCommand class PyTest(TestCommand): extra_kwargs = {'tests_require': ['pytest', 'mock']} def finalize_options(self): TestCommand.finalize_options(self) self.test_args = [] self.test_suite = True def run_tests(self): import pytest sys.exit(pytest.main(self.test_args)) except ImportError: from distutils.core import setup, Command class PyTest(Command): extra_kwargs = {} user_options = [] def initialize_options(self): pass def finalize_options(self): pass def run(self): raise SystemExit(subprocess.call([sys.executable, 'runtests.py'])) with open('README.rst', 'r') as f: readme = f.read() setup(name='isort', version='4.2.2', 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/4.2.2.tar.gz', license="MIT", entry_points={ 'console_scripts': [ 'isort = isort.main:main', ], 'distutils.commands': ['isort = isort.main:ISortCommand'], 'pylama.linter': ['isort = isort.pylama_isort:Linter'], }, packages=['isort'], cmdclass={'test': PyTest}, keywords='Refactor, Python, Python2, Python3, Refactoring, Imports, Sort, Clean', classifiers=['Development Status :: 6 - Mature', 'Intended Audience :: Developers', 'Natural Language :: English', 'Environment :: Console', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.0', 'Programming Language :: Python :: 3.1', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Topic :: Software Development :: Libraries', 'Topic :: Utilities'], **PyTest.extra_kwargs) isort-4.2.2/test_isort.py000066400000000000000000002361641260070737300154510ustar00rootroot00000000000000# coding: utf-8 """test_isort.py. Tests all major functionality of the isort library Should be ran using py.test by simply running py.test in the isort project directory Copyright (C) 2013 Timothy Edmund Crosley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from __future__ import absolute_import, division, print_function, unicode_literals import codecs import os import shutil import tempfile from isort.isort import SortImports from isort.pie_slice import * from isort.settings import WrapModes SHORT_IMPORT = "from third_party import lib1, lib2, lib3, lib4" REALLY_LONG_IMPORT = ("from third_party import lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11," "lib12, lib13, lib14, lib15, lib16, lib17, lib18, lib20, lib21, lib22") REALLY_LONG_IMPORT_WITH_COMMENT = ("from third_party import lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, " "lib10, lib11, lib12, lib13, lib14, lib15, lib16, lib17, lib18, lib20, lib21, lib22" " # comment") def test_happy_path(): """Test the most basic use case, straight imports no code, simply not organized by category.""" test_input = ("import sys\n" "import os\n" "import myproject.test\n" "import django.settings") test_output = SortImports(file_contents=test_input, known_third_party=['django']).output assert test_output == ("import os\n" "import sys\n" "\n" "import django.settings\n" "\n" "import myproject.test\n") def test_code_intermixed(): """Defines what should happen when isort encounters imports intermixed with code. (it should pull them all to the top) """ test_input = ("import sys\n" "print('yo')\n" "print('I like to put code between imports cause I want stuff to break')\n" "import myproject.test\n") test_output = SortImports(file_contents=test_input).output assert test_output == ("import sys\n" "\n" "import myproject.test\n" "\n" "print('yo')\n" "print('I like to put code between imports cause I want stuff to break')\n") def test_correct_space_between_imports(): """Ensure after imports a correct amount of space (in newlines) is enforced. (2 for method, class, or decorator definitions 1 for anything else) """ test_input_method = ("import sys\n" "def my_method():\n" " print('hello world')\n") test_output_method = SortImports(file_contents=test_input_method).output assert test_output_method == ("import sys\n" "\n" "\n" "def my_method():\n" " print('hello world')\n") test_input_decorator = ("import sys\n" "@my_decorator\n" "def my_method():\n" " print('hello world')\n") test_output_decorator = SortImports(file_contents=test_input_decorator).output assert test_output_decorator == ("import sys\n" "\n" "\n" "@my_decorator\n" "def my_method():\n" " print('hello world')\n") test_input_class = ("import sys\n" "class MyClass(object):\n" " pass\n") test_output_class = SortImports(file_contents=test_input_class).output assert test_output_class == ("import sys\n" "\n" "\n" "class MyClass(object):\n" " pass\n") test_input_other = ("import sys\n" "print('yo')\n") test_output_other = SortImports(file_contents=test_input_other).output assert test_output_other == ("import sys\n" "\n" "print('yo')\n") def test_sort_on_number(): """Ensure numbers get sorted logically (10 > 9 not the other way around)""" test_input = ("import lib10\n" "import lib9\n") test_output = SortImports(file_contents=test_input).output assert test_output == ("import lib9\n" "import lib10\n") def test_line_length(): """Ensure isort enforces the set line_length.""" assert len(SortImports(file_contents=REALLY_LONG_IMPORT, line_length=80).output.split("\n")[0]) <= 80 assert len(SortImports(file_contents=REALLY_LONG_IMPORT, line_length=120).output.split("\n")[0]) <= 120 test_output = SortImports(file_contents=REALLY_LONG_IMPORT, line_length=42).output assert test_output == ("from third_party import (lib1, lib2, lib3,\n" " lib4, lib5, lib6,\n" " lib7, lib8, lib9,\n" " lib10, lib11,\n" " lib12, lib13,\n" " lib14, lib15,\n" " lib16, lib17,\n" " lib18, lib20,\n" " lib21, lib22)\n") test_output = SortImports(file_contents=REALLY_LONG_IMPORT, line_length=42, wrap_length=32).output assert test_output == ("from third_party import (lib1,\n" " lib2,\n" " lib3,\n" " lib4,\n" " lib5,\n" " lib6,\n" " lib7,\n" " lib8,\n" " lib9,\n" " lib10,\n" " lib11,\n" " lib12,\n" " lib13,\n" " lib14,\n" " lib15,\n" " lib16,\n" " lib17,\n" " lib18,\n" " lib20,\n" " lib21,\n" " lib22)\n") def test_output_modes(): """Test setting isort to use various output modes works as expected""" test_output_grid = SortImports(file_contents=REALLY_LONG_IMPORT, multi_line_output=WrapModes.GRID, line_length=40).output assert test_output_grid == ("from third_party import (lib1, lib2,\n" " lib3, lib4,\n" " lib5, lib6,\n" " lib7, lib8,\n" " lib9, lib10,\n" " lib11, lib12,\n" " lib13, lib14,\n" " lib15, lib16,\n" " lib17, lib18,\n" " lib20, lib21,\n" " lib22)\n") test_output_vertical = SortImports(file_contents=REALLY_LONG_IMPORT, multi_line_output=WrapModes.VERTICAL, line_length=40).output assert test_output_vertical == ("from third_party import (lib1,\n" " lib2,\n" " lib3,\n" " lib4,\n" " lib5,\n" " lib6,\n" " lib7,\n" " lib8,\n" " lib9,\n" " lib10,\n" " lib11,\n" " lib12,\n" " lib13,\n" " lib14,\n" " lib15,\n" " lib16,\n" " lib17,\n" " lib18,\n" " lib20,\n" " lib21,\n" " lib22)\n") comment_output_vertical = SortImports(file_contents=REALLY_LONG_IMPORT_WITH_COMMENT, multi_line_output=WrapModes.VERTICAL, line_length=40).output assert comment_output_vertical == ("from third_party import (lib1, # comment\n" " lib2,\n" " lib3,\n" " lib4,\n" " lib5,\n" " lib6,\n" " lib7,\n" " lib8,\n" " lib9,\n" " lib10,\n" " lib11,\n" " lib12,\n" " lib13,\n" " lib14,\n" " lib15,\n" " lib16,\n" " lib17,\n" " lib18,\n" " lib20,\n" " lib21,\n" " lib22)\n") test_output_hanging_indent = SortImports(file_contents=REALLY_LONG_IMPORT, multi_line_output=WrapModes.HANGING_INDENT, line_length=40, indent=" ").output assert test_output_hanging_indent == ("from third_party import lib1, lib2, \\\n" " lib3, lib4, lib5, lib6, lib7, \\\n" " lib8, lib9, lib10, lib11, lib12, \\\n" " lib13, lib14, lib15, lib16, lib17, \\\n" " lib18, lib20, lib21, lib22\n") comment_output_hanging_indent = SortImports(file_contents=REALLY_LONG_IMPORT_WITH_COMMENT, multi_line_output=WrapModes.HANGING_INDENT, line_length=40, indent=" ").output assert comment_output_hanging_indent == ("from third_party import lib1, \\ # comment\n" " lib2, lib3, lib4, lib5, lib6, \\\n" " lib7, lib8, lib9, lib10, lib11, \\\n" " lib12, lib13, lib14, lib15, lib16, \\\n" " lib17, lib18, lib20, lib21, lib22\n") test_output_vertical_indent = SortImports(file_contents=REALLY_LONG_IMPORT, multi_line_output=WrapModes.VERTICAL_HANGING_INDENT, line_length=40, indent=" ").output assert test_output_vertical_indent == ("from third_party import (\n" " lib1,\n" " lib2,\n" " lib3,\n" " lib4,\n" " lib5,\n" " lib6,\n" " lib7,\n" " lib8,\n" " lib9,\n" " lib10,\n" " lib11,\n" " lib12,\n" " lib13,\n" " lib14,\n" " lib15,\n" " lib16,\n" " lib17,\n" " lib18,\n" " lib20,\n" " lib21,\n" " lib22\n" ")\n") comment_output_vertical_indent = SortImports(file_contents=REALLY_LONG_IMPORT_WITH_COMMENT, multi_line_output=WrapModes.VERTICAL_HANGING_INDENT, line_length=40, indent=" ").output assert comment_output_vertical_indent == ("from third_party import ( # comment\n" " lib1,\n" " lib2,\n" " lib3,\n" " lib4,\n" " lib5,\n" " lib6,\n" " lib7,\n" " lib8,\n" " lib9,\n" " lib10,\n" " lib11,\n" " lib12,\n" " lib13,\n" " lib14,\n" " lib15,\n" " lib16,\n" " lib17,\n" " lib18,\n" " lib20,\n" " lib21,\n" " lib22\n" ")\n") test_output_vertical_grid = SortImports(file_contents=REALLY_LONG_IMPORT, multi_line_output=WrapModes.VERTICAL_GRID, line_length=40, indent=" ").output assert test_output_vertical_grid == ("from third_party import (\n" " lib1, lib2, lib3, lib4, lib5, lib6,\n" " lib7, lib8, lib9, lib10, lib11,\n" " lib12, lib13, lib14, lib15, lib16,\n" " lib17, lib18, lib20, lib21, lib22)\n") comment_output_vertical_grid = SortImports(file_contents=REALLY_LONG_IMPORT_WITH_COMMENT, multi_line_output=WrapModes.VERTICAL_GRID, line_length=40, indent=" ").output assert comment_output_vertical_grid == ("from third_party import ( # comment\n" " lib1, lib2, lib3, lib4, lib5, lib6,\n" " lib7, lib8, lib9, lib10, lib11,\n" " lib12, lib13, lib14, lib15, lib16,\n" " lib17, lib18, lib20, lib21, lib22)\n") test_output_vertical_grid_grouped = SortImports(file_contents=REALLY_LONG_IMPORT, multi_line_output=WrapModes.VERTICAL_GRID_GROUPED, line_length=40, indent=" ").output assert test_output_vertical_grid_grouped == ("from third_party import (\n" " lib1, lib2, lib3, lib4, lib5, lib6,\n" " lib7, lib8, lib9, lib10, lib11,\n" " lib12, lib13, lib14, lib15, lib16,\n" " lib17, lib18, lib20, lib21, lib22\n" ")\n") comment_output_vertical_grid_grouped = SortImports(file_contents=REALLY_LONG_IMPORT_WITH_COMMENT, multi_line_output=WrapModes.VERTICAL_GRID_GROUPED, line_length=40, indent=" ").output assert comment_output_vertical_grid_grouped == ("from third_party import ( # comment\n" " lib1, lib2, lib3, lib4, lib5, lib6,\n" " lib7, lib8, lib9, lib10, lib11,\n" " lib12, lib13, lib14, lib15, lib16,\n" " lib17, lib18, lib20, lib21, lib22\n" ")\n") output_noqa = SortImports(file_contents=REALLY_LONG_IMPORT_WITH_COMMENT, multi_line_output=WrapModes.NOQA).output assert output_noqa == "from third_party import lib1 lib2 lib3 lib4 lib5 lib6 lib7 lib8 lib9 lib10 lib11 lib12 lib13 lib14 lib15 lib16 lib17 lib18 lib20 lib21 lib22 # NOQA comment\n" # NOQA def test_qa_comment_case(): test_input = "from veryveryveryveryveryveryveryveryveryveryvery import X # NOQA" test_output = SortImports(file_contents=test_input, line_length=40, multi_line_output=WrapModes.NOQA).output assert test_output == "from veryveryveryveryveryveryveryveryveryveryvery import X # NOQA\n" test_input = "import veryveryveryveryveryveryveryveryveryveryvery # NOQA" test_output = SortImports(file_contents=test_input, line_length=40, multi_line_output=WrapModes.NOQA).output assert test_output == "import veryveryveryveryveryveryveryveryveryveryvery # NOQA\n" def test_length_sort(): """Test setting isort to sort on length instead of alphabetically.""" test_input = ("import medium_sizeeeeeeeeeeeeee\n" "import shortie\n" "import looooooooooooooooooooooooooooooooooooooong\n" "import medium_sizeeeeeeeeeeeeea\n") test_output = SortImports(file_contents=test_input, length_sort=True).output assert test_output == ("import shortie\n" "import medium_sizeeeeeeeeeeeeea\n" "import medium_sizeeeeeeeeeeeeee\n" "import looooooooooooooooooooooooooooooooooooooong\n") def test_convert_hanging(): """Ensure that isort will convert hanging indents to correct indent method.""" test_input = ("from third_party import lib1, lib2, \\\n" " lib3, lib4, lib5, lib6, lib7, \\\n" " lib8, lib9, lib10, lib11, lib12, \\\n" " lib13, lib14, lib15, lib16, lib17, \\\n" " lib18, lib20, lib21, lib22\n") test_output = SortImports(file_contents=test_input, multi_line_output=WrapModes.GRID, line_length=40).output assert test_output == ("from third_party import (lib1, lib2,\n" " lib3, lib4,\n" " lib5, lib6,\n" " lib7, lib8,\n" " lib9, lib10,\n" " lib11, lib12,\n" " lib13, lib14,\n" " lib15, lib16,\n" " lib17, lib18,\n" " lib20, lib21,\n" " lib22)\n") def test_custom_indent(): """Ensure setting a custom indent will work as expected.""" test_output = SortImports(file_contents=REALLY_LONG_IMPORT, multi_line_output=WrapModes.HANGING_INDENT, line_length=40, indent=" ", balanced_wrapping=False).output assert test_output == ("from third_party import lib1, lib2, \\\n" " lib3, lib4, lib5, lib6, lib7, lib8, \\\n" " lib9, lib10, lib11, lib12, lib13, \\\n" " lib14, lib15, lib16, lib17, lib18, \\\n" " lib20, lib21, lib22\n") test_output = SortImports(file_contents=REALLY_LONG_IMPORT, multi_line_output=WrapModes.HANGING_INDENT, line_length=40, indent="' '", balanced_wrapping=False).output assert test_output == ("from third_party import lib1, lib2, \\\n" " lib3, lib4, lib5, lib6, lib7, lib8, \\\n" " lib9, lib10, lib11, lib12, lib13, \\\n" " lib14, lib15, lib16, lib17, lib18, \\\n" " lib20, lib21, lib22\n") test_output = SortImports(file_contents=REALLY_LONG_IMPORT, multi_line_output=WrapModes.HANGING_INDENT, line_length=40, indent="tab", balanced_wrapping=False).output assert test_output == ("from third_party import lib1, lib2, \\\n" "\tlib3, lib4, lib5, lib6, lib7, lib8, \\\n" "\tlib9, lib10, lib11, lib12, lib13, \\\n" "\tlib14, lib15, lib16, lib17, lib18, \\\n" "\tlib20, lib21, lib22\n") test_output = SortImports(file_contents=REALLY_LONG_IMPORT, multi_line_output=WrapModes.HANGING_INDENT, line_length=40, indent=2, balanced_wrapping=False).output assert test_output == ("from third_party import lib1, lib2, \\\n" " lib3, lib4, lib5, lib6, lib7, lib8, \\\n" " lib9, lib10, lib11, lib12, lib13, \\\n" " lib14, lib15, lib16, lib17, lib18, \\\n" " lib20, lib21, lib22\n") def test_use_parentheses(): test_input = ( "from fooooooooooooooooooooooooo.baaaaaaaaaaaaaaaaaaarrrrrrr import \\" " my_custom_function as my_special_function" ) test_output = SortImports( file_contents=test_input, known_third_party=['django'], line_length=79, use_parentheses=True, ).output assert '(' in test_output def test_skip(): """Ensure skipping a single import will work as expected.""" test_input = ("import myproject\n" "import django\n" "print('hey')\n" "import sys # isort:skip this import needs to be placed here\n\n\n\n\n\n\n") test_output = SortImports(file_contents=test_input, known_third_party=['django']).output assert test_output == ("import django\n" "\n" "import myproject\n" "\n" "print('hey')\n" "import sys # isort:skip this import needs to be placed here\n") def test_skip_with_file_name(): """Ensure skipping a file works even when file_contents is provided.""" test_input = ("import django\n" "import myproject\n") skipped = SortImports(file_path='/baz.py', file_contents=test_input, known_third_party=['django'], skip=['baz.py']).skipped assert skipped def test_force_to_top(): """Ensure forcing a single import to the top of its category works as expected.""" test_input = ("import lib6\n" "import lib2\n" "import lib5\n" "import lib1\n") test_output = SortImports(file_contents=test_input, force_to_top=['lib5']).output assert test_output == ("import lib5\n" "import lib1\n" "import lib2\n" "import lib6\n") def test_add_imports(): """Ensures adding imports works as expected.""" test_input = ("import lib6\n" "import lib2\n" "import lib5\n" "import lib1\n\n") test_output = SortImports(file_contents=test_input, add_imports=['import lib4', 'import lib7']).output assert test_output == ("import lib1\n" "import lib2\n" "import lib4\n" "import lib5\n" "import lib6\n" "import lib7\n") # Using simplified syntax test_input = ("import lib6\n" "import lib2\n" "import lib5\n" "import lib1\n\n") test_output = SortImports(file_contents=test_input, add_imports=['lib4', 'lib7', 'lib8.a']).output assert test_output == ("import lib1\n" "import lib2\n" "import lib4\n" "import lib5\n" "import lib6\n" "import lib7\n" "from lib8 import a\n") # On a file that has no pre-existing imports test_input = ('"""Module docstring"""\n' '\n' 'class MyClass(object):\n' ' pass\n') test_output = SortImports(file_contents=test_input, add_imports=['from __future__ import print_function']).output assert test_output == ('"""Module docstring"""\n' 'from __future__ import print_function\n' '\n' '\n' 'class MyClass(object):\n' ' pass\n') # On a file that has no pre-existing imports, and no doc-string test_input = ('class MyClass(object):\n' ' pass\n') test_output = SortImports(file_contents=test_input, add_imports=['from __future__ import print_function']).output assert test_output == ('from __future__ import print_function\n' '\n' '\n' 'class MyClass(object):\n' ' pass\n') # On a file with no content what so ever test_input = ("") test_output = SortImports(file_contents=test_input, add_imports=['lib4']).output assert test_output == ("") # On a file with no content what so ever, after force_adds is set to True test_input = ("") test_output = SortImports(file_contents=test_input, add_imports=['lib4'], force_adds=True).output assert test_output == ("import lib4\n") def test_remove_imports(): """Ensures removing imports works as expected.""" test_input = ("import lib6\n" "import lib2\n" "import lib5\n" "import lib1") test_output = SortImports(file_contents=test_input, remove_imports=['lib2', 'lib6']).output assert test_output == ("import lib1\n" "import lib5\n") # Using natural syntax test_input = ("import lib6\n" "import lib2\n" "import lib5\n" "import lib1\n" "from lib8 import a") test_output = SortImports(file_contents=test_input, remove_imports=['import lib2', 'import lib6', 'from lib8 import a']).output assert test_output == ("import lib1\n" "import lib5\n") def test_explicitly_local_import(): """Ensure that explicitly local imports are separated.""" test_input = ("import lib1\n" "import lib2\n" "import .lib6\n" "from . import lib7") assert SortImports(file_contents=test_input).output == ("import lib1\n" "import lib2\n" "\n" "import .lib6\n" "from . import lib7\n") def test_quotes_in_file(): """Ensure imports within triple quotes don't get imported.""" test_input = ('import os\n' '\n' '"""\n' 'Let us\n' 'import foo\n' 'okay?\n' '"""\n') assert SortImports(file_contents=test_input).output == test_input test_input = ('import os\n' '\n' "'\"\"\"'\n" 'import foo\n') assert SortImports(file_contents=test_input).output == ('import os\n' '\n' 'import foo\n' '\n' "'\"\"\"'\n") test_input = ('import os\n' '\n' '"""Let us"""\n' 'import foo\n' '"""okay?"""\n') assert SortImports(file_contents=test_input).output == ('import os\n' '\n' 'import foo\n' '\n' '"""Let us"""\n' '"""okay?"""\n') test_input = ('import os\n' '\n' '#"""\n' 'import foo\n' '#"""') assert SortImports(file_contents=test_input).output == ('import os\n' '\n' 'import foo\n' '\n' '#"""\n' '#"""\n') test_input = ('import os\n' '\n' "'\\\n" "import foo'\n") assert SortImports(file_contents=test_input).output == test_input test_input = ('import os\n' '\n' "'''\n" "\\'''\n" 'import junk\n' "'''\n") assert SortImports(file_contents=test_input).output == test_input def test_check_newline_in_imports(capsys): """Ensure tests works correctly when new lines are in imports.""" test_input = ('from lib1 import (\n' ' sub1,\n' ' sub2,\n' ' sub3\n)\n') SortImports(file_contents=test_input, multi_line_output=WrapModes.VERTICAL_HANGING_INDENT, line_length=20, check=True, verbose=True) out, err = capsys.readouterr() assert 'SUCCESS' in out def test_forced_separate(): """Ensure that forcing certain sub modules to show separately works as expected.""" test_input = ('import sys\n' 'import warnings\n' 'from collections import OrderedDict\n' '\n' 'from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation\n' 'from django.core.paginator import InvalidPage\n' 'from django.core.urlresolvers import reverse\n' 'from django.db import models\n' 'from django.db.models.fields import FieldDoesNotExist\n' 'from django.utils import six\n' 'from django.utils.deprecation import RenameMethodsBase\n' 'from django.utils.encoding import force_str, force_text\n' 'from django.utils.http import urlencode\n' 'from django.utils.translation import ugettext, ugettext_lazy\n' '\n' 'from django.contrib.admin import FieldListFilter\n' 'from django.contrib.admin.exceptions import DisallowedModelAdminLookup\n' 'from django.contrib.admin.options import IncorrectLookupParameters, IS_POPUP_VAR, TO_FIELD_VAR\n') assert SortImports(file_contents=test_input, forced_separate=['django.contrib'], known_third_party=['django'], line_length=120, order_by_type=False).output == test_input test_input = ('from .foo import bar\n' '\n' 'from .y import ca\n') assert SortImports(file_contents=test_input, forced_separate=['.y'], line_length=120, order_by_type=False).output == test_input def test_default_section(): """Test to ensure changing the default section works as expected.""" test_input = ("import sys\n" "import os\n" "import myproject.test\n" "import django.settings") test_output = SortImports(file_contents=test_input, known_third_party=['django'], default_section="FIRSTPARTY").output assert test_output == ("import os\n" "import sys\n" "\n" "import django.settings\n" "\n" "import myproject.test\n") test_output_custom = SortImports(file_contents=test_input, known_third_party=['django'], default_section="STDLIB").output assert test_output_custom == ("import myproject.test\n" "import os\n" "import sys\n" "\n" "import django.settings\n") def test_first_party_overrides_standard_section(): """Test to ensure changing the default section works as expected.""" test_input = ("import sys\n" "import os\n" "import profile.test\n") test_output = SortImports(file_contents=test_input, known_first_party=['profile']).output assert test_output == ("import os\n" "import sys\n" "\n" "import profile.test\n") def test_thirdy_party_overrides_standard_section(): """Test to ensure changing the default section works as expected.""" test_input = ("import sys\n" "import os\n" "import profile.test\n") test_output = SortImports(file_contents=test_input, known_third_party=['profile']).output assert test_output == ("import os\n" "import sys\n" "\n" "import profile.test\n") def test_force_single_line_imports(): """Test to ensure forcing imports to each have their own line works as expected.""" test_input = ("from third_party import lib1, lib2, \\\n" " lib3, lib4, lib5, lib6, lib7, \\\n" " lib8, lib9, lib10, lib11, lib12, \\\n" " lib13, lib14, lib15, lib16, lib17, \\\n" " lib18, lib20, lib21, lib22\n") test_output = SortImports(file_contents=test_input, multi_line_output=WrapModes.GRID, line_length=40, force_single_line=True).output assert test_output == ("from third_party import lib1\n" "from third_party import lib2\n" "from third_party import lib3\n" "from third_party import lib4\n" "from third_party import lib5\n" "from third_party import lib6\n" "from third_party import lib7\n" "from third_party import lib8\n" "from third_party import lib9\n" "from third_party import lib10\n" "from third_party import lib11\n" "from third_party import lib12\n" "from third_party import lib13\n" "from third_party import lib14\n" "from third_party import lib15\n" "from third_party import lib16\n" "from third_party import lib17\n" "from third_party import lib18\n" "from third_party import lib20\n" "from third_party import lib21\n" "from third_party import lib22\n") def test_force_single_line_long_imports(): test_input = ("from veryveryveryveryveryvery import small, big\n") test_output = SortImports(file_contents=test_input, multi_line_output=WrapModes.NOQA, line_length=40, force_single_line=True).output assert test_output == ("from veryveryveryveryveryvery import big\n" "from veryveryveryveryveryvery import small # NOQA\n") def test_titled_imports(): """Tests setting custom titled/commented import sections.""" test_input = ("import sys\n" "import unicodedata\n" "import statistics\n" "import os\n" "import myproject.test\n" "import django.settings") test_output = SortImports(file_contents=test_input, known_third_party=['django'], import_heading_stdlib="Standard Library", import_heading_firstparty="My Stuff").output assert test_output == ("# Standard Library\n" "import os\n" "import statistics\n" "import sys\n" "import unicodedata\n" "\n" "import django.settings\n" "\n" "# My Stuff\n" "import myproject.test\n") test_second_run = SortImports(file_contents=test_output, known_third_party=['django'], import_heading_stdlib="Standard Library", import_heading_firstparty="My Stuff").output assert test_second_run == test_output def test_balanced_wrapping(): """Tests balanced wrapping mode, where the length of individual lines maintain width.""" test_input = ("from __future__ import (absolute_import, division, print_function,\n" " unicode_literals)") test_output = SortImports(file_contents=test_input, line_length=70, balanced_wrapping=True).output assert test_output == ("from __future__ import (absolute_import, division,\n" " print_function, unicode_literals)\n") def test_relative_import_with_space(): """Tests the case where the relation and the module that is being imported from is separated with a space.""" test_input = ("from ... fields.sproqet import SproqetCollection") assert SortImports(file_contents=test_input).output == ("from ...fields.sproqet import SproqetCollection\n") def test_multiline_import(): """Test the case where import spawns multiple lines with inconsistent indentation.""" test_input = ("from pkg \\\n" " import stuff, other_suff \\\n" " more_stuff") assert SortImports(file_contents=test_input).output == ("from pkg import more_stuff, other_suff, stuff\n") # test again with a custom configuration custom_configuration = {'force_single_line': True, 'line_length': 120, 'known_first_party': ['asdf', 'qwer'], 'default_section': 'THIRDPARTY', 'forced_separate': 'asdf'} expected_output = ("from pkg import more_stuff\n" "from pkg import other_suff\n" "from pkg import stuff\n") assert SortImports(file_contents=test_input, **custom_configuration).output == expected_output def test_atomic_mode(): # without syntax error, everything works OK test_input = ("from b import d, c\n" "from a import f, e\n") assert SortImports(file_contents=test_input, atomic=True).output == ("from a import e, f\n" "from b import c, d\n") # with syntax error content is not changed test_input += "while True print 'Hello world'" # blatant syntax error assert SortImports(file_contents=test_input, atomic=True).output == test_input def test_order_by_type(): test_input = "from module import Class, CONSTANT, function" assert SortImports(file_contents=test_input, order_by_type=True).output == ("from module import CONSTANT, Class, function\n") # More complex sample data test_input = "from module import Class, CONSTANT, function, BASIC, Apple" assert SortImports(file_contents=test_input, order_by_type=True).output == ("from module import BASIC, CONSTANT, Apple, Class, function\n") # Really complex sample data, to verify we don't mess with top level imports, only nested ones test_input = ("import StringIO\n" "import glob\n" "import os\n" "import shutil\n" "import tempfile\n" "import time\n" "from subprocess import PIPE, Popen, STDOUT\n") assert SortImports(file_contents=test_input, order_by_type=True).output == \ ("import glob\n" "import os\n" "import shutil\n" "import StringIO\n" "import tempfile\n" "import time\n" "from subprocess import PIPE, STDOUT, Popen\n") def test_custom_lines_after_import_section(): """Test the case where the number of lines to output after imports has been explicitly set.""" test_input = ("from a import b\n" "foo = 'bar'\n") # default case is one space if not method or class after imports assert SortImports(file_contents=test_input).output == ("from a import b\n" "\n" "foo = 'bar'\n") # test again with a custom number of lines after the import section assert SortImports(file_contents=test_input, lines_after_imports=2).output == ("from a import b\n" "\n" "\n" "foo = 'bar'\n") def test_smart_lines_after_import_section(): """Tests the default 'smart' behavior for dealing with lines after the import section""" # one space if not method or class after imports test_input = ("from a import b\n" "foo = 'bar'\n") assert SortImports(file_contents=test_input).output == ("from a import b\n" "\n" "foo = 'bar'\n") # two spaces if a method or class after imports test_input = ("from a import b\n" "def my_function():\n" " pass\n") assert SortImports(file_contents=test_input).output == ("from a import b\n" "\n" "\n" "def my_function():\n" " pass\n") # two spaces if a method or class after imports - even if comment before function test_input = ("from a import b\n" "# comment should be ignored\n" "def my_function():\n" " pass\n") assert SortImports(file_contents=test_input).output == ("from a import b\n" "\n" "\n" "# comment should be ignored\n" "def my_function():\n" " pass\n") # ensure logic works with both style comments test_input = ("from a import b\n" '"""\n' " comment should be ignored\n" '"""\n' "def my_function():\n" " pass\n") assert SortImports(file_contents=test_input).output == ("from a import b\n" "\n" "\n" '"""\n' " comment should be ignored\n" '"""\n' "def my_function():\n" " pass\n") def test_settings_combine_instead_of_overwrite(): """Test to ensure settings combine logically, instead of fully overwriting.""" assert set(SortImports(known_standard_library=['not_std_library']).config['known_standard_library']) == \ set(SortImports().config['known_standard_library'] + ['not_std_library']) assert set(SortImports(not_known_standard_library=['thread']).config['known_standard_library']) == \ set(item for item in SortImports().config['known_standard_library'] if item != 'thread') def test_combined_from_and_as_imports(): """Test to ensure it's possible to combine from and as imports.""" test_input = ("from translate.misc.multistring import multistring\n" "from translate.storage import base, factory\n" "from translate.storage.placeables import general, parse as rich_parse\n") assert SortImports(file_contents=test_input, combine_as_imports=True).output == test_input def test_as_imports_with_line_length(): """Test to ensure it's possible to combine from and as imports.""" test_input = ("from translate.storage import base as storage_base\n" "from translate.storage.placeables import general, parse as rich_parse\n") assert SortImports(file_contents=test_input, combine_as_imports=False, line_length=40).output == \ ("from translate.storage import \\\n base as storage_base\n" "from translate.storage.placeables import \\\n parse as rich_parse\n" "from translate.storage.placeables import \\\n general\n") def test_keep_comments(): """Test to ensure isort properly keeps comments in tact after sorting.""" # Straight Import test_input = ("import foo # bar\n") assert SortImports(file_contents=test_input).output == test_input # Star import test_input_star = ("from foo import * # bar\n") assert SortImports(file_contents=test_input_star).output == test_input_star # Force Single Line From Import test_input = ("from foo import bar # comment\n") assert SortImports(file_contents=test_input, force_single_line=True).output == test_input # From import test_input = ("from foo import bar # My Comment\n") assert SortImports(file_contents=test_input).output == test_input # More complicated case test_input = ("from a import b # My Comment1\n" "from a import c # My Comment2\n") assert SortImports(file_contents=test_input).output == \ ("from a import b # My Comment1\n" "from a import c # My Comment2\n") # Test case where imports comments make imports extend pass the line length test_input = ("from a import b # My Comment1\n" "from a import c # My Comment2\n" "from a import d\n") assert SortImports(file_contents=test_input, line_length=45).output == \ ("from a import b # My Comment1\n" "from a import c # My Comment2\n" "from a import d\n") # Test case where imports with comments will be beyond line length limit test_input = ("from a import b, c # My Comment1\n" "from a import c, d # My Comment2 is really really really really long\n") assert SortImports(file_contents=test_input, line_length=45).output == \ ("from a import (b, # My Comment1; My Comment2 is really really really really long\n" " c, d)\n") # Test that comments are not stripped from 'import ... as ...' by default test_input = ("from a import b as bb # b comment\n" "from a import c as cc # c comment\n") assert SortImports(file_contents=test_input).output == test_input # Test that 'import ... as ...' comments are not collected inappropriately test_input = ("from a import b as bb # b comment\n" "from a import c as cc # c comment\n" "from a import d\n") assert SortImports(file_contents=test_input).output == test_input assert SortImports(file_contents=test_input, combine_as_imports=True).output == ( "from a import b as bb, c as cc, d # b comment; c comment\n" ) def test_multiline_split_on_dot(): """Test to ensure isort correctly handles multiline imports, even when split right after a '.'""" test_input = ("from my_lib.my_package.test.level_1.level_2.level_3.level_4.level_5.\\\n" " my_module import my_function") assert SortImports(file_contents=test_input, line_length=70).output == \ ("from my_lib.my_package.test.level_1.level_2.level_3.level_4.level_5.my_module import \\\n" " my_function\n") def test_import_star(): """Test to ensure isort handles star imports correctly""" test_input = ("from blah import *\n" "from blah import _potato\n") assert SortImports(file_contents=test_input).output == ("from blah import *\n" "from blah import _potato\n") assert SortImports(file_contents=test_input, combine_star=True).output == ("from blah import *\n") def test_include_trailing_comma(): """Test for the include_trailing_comma option""" test_output_grid = SortImports( file_contents=SHORT_IMPORT, multi_line_output=WrapModes.GRID, line_length=40, include_trailing_comma=True, ).output assert test_output_grid == ( "from third_party import (lib1, lib2,\n" " lib3, lib4,)\n" ) test_output_vertical = SortImports( file_contents=SHORT_IMPORT, multi_line_output=WrapModes.VERTICAL, line_length=40, include_trailing_comma=True, ).output assert test_output_vertical == ( "from third_party import (lib1,\n" " lib2,\n" " lib3,\n" " lib4,)\n" ) test_output_vertical_indent = SortImports( file_contents=SHORT_IMPORT, multi_line_output=WrapModes.VERTICAL_HANGING_INDENT, line_length=40, include_trailing_comma=True, ).output assert test_output_vertical_indent == ( "from third_party import (\n" " lib1,\n" " lib2,\n" " lib3,\n" " lib4,\n" ")\n" ) test_output_vertical_grid = SortImports( file_contents=SHORT_IMPORT, multi_line_output=WrapModes.VERTICAL_GRID, line_length=40, include_trailing_comma=True, ).output assert test_output_vertical_grid == ( "from third_party import (\n" " lib1, lib2, lib3, lib4,)\n" ) test_output_vertical_grid_grouped = SortImports( file_contents=SHORT_IMPORT, multi_line_output=WrapModes.VERTICAL_GRID_GROUPED, line_length=40, include_trailing_comma=True, ).output assert test_output_vertical_grid_grouped == ( "from third_party import (\n" " lib1, lib2, lib3, lib4,\n" ")\n" ) def test_similar_to_std_library(): """Test to ensure modules that are named similarly to a standard library import don't end up clobbered""" test_input = ("import datetime\n" "\n" "import requests\n" "import times\n") assert SortImports(file_contents=test_input, known_third_party=["requests", "times"]).output == test_input def test_correctly_placed_imports(): """Test to ensure comments stay on correct placement after being sorted""" test_input = ("from a import b # comment for b\n" "from a import c # comment for c\n") assert SortImports(file_contents=test_input, force_single_line=True).output == \ ("from a import b # comment for b\n" "from a import c # comment for c\n") assert SortImports(file_contents=test_input).output == ("from a import b # comment for b\n" "from a import c # comment for c\n") # Full example test from issue #143 test_input = ("from itertools import chain\n" "\n" "from django.test import TestCase\n" "from model_mommy import mommy\n" "\n" "from apps.clientman.commands.download_usage_rights import associate_right_for_item_product\n" "from apps.clientman.commands.download_usage_rights import associate_right_for_item_product_d" "efinition\n" "from apps.clientman.commands.download_usage_rights import associate_right_for_item_product_d" "efinition_platform\n" "from apps.clientman.commands.download_usage_rights import associate_right_for_item_product_p" "latform\n" "from apps.clientman.commands.download_usage_rights import associate_right_for_territory_reta" "il_model\n" "from apps.clientman.commands.download_usage_rights import associate_right_for_territory_reta" "il_model_definition_platform_provider # noqa\n" "from apps.clientman.commands.download_usage_rights import clear_right_for_item_product\n" "from apps.clientman.commands.download_usage_rights import clear_right_for_item_product_defini" "tion\n" "from apps.clientman.commands.download_usage_rights import clear_right_for_item_product_defini" "tion_platform\n" "from apps.clientman.commands.download_usage_rights import clear_right_for_item_product_platfo" "rm\n" "from apps.clientman.commands.download_usage_rights import clear_right_for_territory_retail_mo" "del\n" "from apps.clientman.commands.download_usage_rights import clear_right_for_territory_retail_mo" "del_definition_platform_provider # noqa\n" "from apps.clientman.commands.download_usage_rights import create_download_usage_right\n" "from apps.clientman.commands.download_usage_rights import delete_download_usage_right\n" "from apps.clientman.commands.download_usage_rights import disable_download_for_item_product\n" "from apps.clientman.commands.download_usage_rights import disable_download_for_item_product_d" "efinition\n" "from apps.clientman.commands.download_usage_rights import disable_download_for_item_product_d" "efinition_platform\n" "from apps.clientman.commands.download_usage_rights import disable_download_for_item_product_p" "latform\n" "from apps.clientman.commands.download_usage_rights import disable_download_for_territory_reta" "il_model\n" "from apps.clientman.commands.download_usage_rights import disable_download_for_territory_reta" "il_model_definition_platform_provider # noqa\n" "from apps.clientman.commands.download_usage_rights import get_download_rights_for_item\n" "from apps.clientman.commands.download_usage_rights import get_right\n") assert SortImports(file_contents=test_input, force_single_line=True, line_length=140, known_third_party=["django", "model_mommy"]).output == test_input def test_auto_detection(): """Initial test to ensure isort auto-detection works correctly - will grow over time as new issues are raised.""" # Issue 157 test_input = ("import binascii\n" "import os\n" "\n" "import cv2\n" "import requests\n") assert SortImports(file_contents=test_input, known_third_party=["cv2", "requests"]).output == test_input # alternative solution assert SortImports(file_contents=test_input, default_section="THIRDPARTY").output == test_input def test_same_line_statements(): """Ensure isort correctly handles the case where a single line contains multiple statements including an import""" test_input = ("import pdb; import nose\n") assert SortImports(file_contents=test_input).output == ("import pdb\n" "\n" "import nose\n") test_input = ("import pdb; pdb.set_trace()\n" "import nose; nose.run()\n") assert SortImports(file_contents=test_input).output == test_input def test_long_line_comments(): """Ensure isort correctly handles comments at the end of extreamly long lines""" test_input = ("from foo.utils.fabric_stuff.live import check_clean_live, deploy_live, sync_live_envdir, " "update_live_app, update_live_cron # noqa\n" "from foo.utils.fabric_stuff.stage import check_clean_stage, deploy_stage, sync_stage_envdir, " "update_stage_app, update_stage_cron # noqa\n") assert SortImports(file_contents=test_input).output == \ ("from foo.utils.fabric_stuff.live import (check_clean_live, deploy_live, # noqa\n" " sync_live_envdir, update_live_app, update_live_cron)\n" "from foo.utils.fabric_stuff.stage import (check_clean_stage, deploy_stage, # noqa\n" " sync_stage_envdir, update_stage_app, update_stage_cron)\n") def test_tab_character_in_import(): """Ensure isort correctly handles import statements that contain a tab character""" test_input = ("from __future__ import print_function\n" "from __future__ import\tprint_function\n") assert SortImports(file_contents=test_input).output == "from __future__ import print_function\n" def test_split_position(): """Ensure isort splits on import instead of . when possible""" test_input = ("from p24.shared.exceptions.master.host_state_flag_unchanged import HostStateUnchangedException\n") assert SortImports(file_contents=test_input, line_length=80).output == \ ("from p24.shared.exceptions.master.host_state_flag_unchanged import \\\n" " HostStateUnchangedException\n") def test_place_comments(): """Ensure manually placing imports works as expected""" test_input = ("import sys\n" "import os\n" "import myproject.test\n" "import django.settings\n" "\n" "# isort:imports-thirdparty\n" "# isort:imports-firstparty\n" "print('code')\n" "\n" "# isort:imports-stdlib\n") test_output = SortImports(file_contents=test_input, known_third_party=['django']).output assert test_output == ("\n# isort:imports-thirdparty\n" "import django.settings\n" "\n" "# isort:imports-firstparty\n" "import myproject.test\n" "\n" "print('code')\n" "\n" "# 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'], known_third_party=['bottle'], 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") def test_custom_sections(): """Ensure that most specific placement control match wins""" test_input = ("import os\n" "import sys\n" "from django.conf import settings\n" "from bottle import Bottle, redirect, response, run\n" "import p24.imports._argparse as argparse\n" "from django.db import models\n" "import p24.imports._subprocess as subprocess\n" "import pandas as pd\n" "import p24.imports._VERSION as VERSION\n" "import numpy as np\n" "import p24.shared.media_wiki_syntax as syntax\n") test_output = SortImports(file_contents=test_input, known_first_party=['p24', 'p24.imports._VERSION'], import_heading_stdlib='Standard Library', import_heading_thirdparty='Third Party', import_heading_firstparty='First Party', import_heading_django='Django', import_heading_pandas='Pandas', known_standard_library=['p24.imports'], known_third_party=['bottle'], known_django=['django'], known_pandas=['pandas', 'numpy'], default_section="THIRDPARTY", sections=["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "PANDAS", "FIRSTPARTY", "LOCALFOLDER"]).output assert test_output == ("# Standard Library\n" "import os\n" "import p24.imports._argparse as argparse\n" "import p24.imports._subprocess as subprocess\n" "import sys\n" "\n" "# Django\n" "from django.conf import settings\n" "from django.db import models\n" "\n" "# Third Party\n" "from bottle import Bottle, redirect, response, run\n" "\n" "# Pandas\n" "import numpy as np\n" "import pandas as pd\n" "\n" "# First Party\n" "import p24.imports._VERSION as VERSION\n" "import p24.shared.media_wiki_syntax as syntax\n") def test_sticky_comments(): """Test to ensure it is possible to make comments 'stick' above imports""" test_input = ("import os\n" "\n" "# Used for type-hinting (ref: https://github.com/davidhalter/jedi/issues/414).\n" "from selenium.webdriver.remote.webdriver import WebDriver # noqa\n") assert SortImports(file_contents=test_input).output == test_input test_input = ("from django import forms\n" "# While this couples the geographic forms to the GEOS library,\n" "# it decouples from database (by not importing SpatialBackend).\n" "from django.contrib.gis.geos import GEOSException, GEOSGeometry\n" "from django.utils.translation import ugettext_lazy as _\n") assert SortImports(file_contents=test_input).output == test_input def test_zipimport(): """Imports ending in "import" shouldn't be clobbered""" test_input = "from zipimport import zipimport\n" assert SortImports(file_contents=test_input).output == test_input def test_from_ending(): """Imports ending in "from" shouldn't be clobbered.""" test_input = "from foo import get_foo_from, get_foo\n" expected_output = "from foo import get_foo, get_foo_from\n" assert SortImports(file_contents=test_input).output == expected_output def test_from_first(): """Tests the setting from_first works correctly""" test_input = "from os import path\nimport os\n" assert SortImports(file_contents=test_input, from_first=True).output == test_input def test_top_comments(): """Ensure correct behavior with top comments""" test_input = ("# -*- encoding: utf-8 -*-\n" "# Test comment\n" "#\n" "from __future__ import unicode_literals\n") assert SortImports(file_contents=test_input).output == test_input test_input = ("# -*- coding: utf-8 -*-\n" "from django.db import models\n" "from django.utils.encoding import python_2_unicode_compatible\n") assert SortImports(file_contents=test_input).output == test_input test_input = ("# Comment\n" "import sys\n") assert SortImports(file_contents=test_input).output == test_input test_input = ("# -*- coding\n" "import sys\n") assert SortImports(file_contents=test_input).output == test_input def test_consistency(): """Ensures consistency of handling even when dealing with non ordered-by-type imports""" test_input = "from sqlalchemy.dialects.postgresql import ARRAY, array\n" assert SortImports(file_contents=test_input, order_by_type=True).output == test_input def test_force_grid_wrap(): """Ensures removing imports works as expected.""" test_input = ( "from foo import lib6, lib7\n" "from bar import lib2\n" ) test_output = SortImports( file_contents=test_input, force_grid_wrap=True, multi_line_output=WrapModes.VERTICAL_HANGING_INDENT ).output assert test_output == """from bar import lib2 from foo import ( lib6, lib7 ) """ def test_force_grid_wrap_long(): """Ensure that force grid wrap still happens with long line length""" test_input = ( "from foo import lib6, lib7\n" "from bar import lib2\n" "from babar import something_that_is_kind_of_long" ) test_output = SortImports( file_contents=test_input, force_grid_wrap=True, multi_line_output=WrapModes.VERTICAL_HANGING_INDENT, line_length=9999, ).output assert test_output == """from babar import something_that_is_kind_of_long from bar import lib2 from foo import ( lib6, lib7 ) """ def test_uses_jinja_variables(): """Test a basic set of imports that use jinja variables""" test_input = ("import sys\n" "import os\n" "import myproject.{ test }\n" "import django.{ settings }") test_output = SortImports(file_contents=test_input, known_third_party=['django'], known_first_party=['myproject']).output assert test_output == ("import os\n" "import sys\n" "\n" "import django.{ settings }\n" "\n" "import myproject.{ test }\n") test_input = ("import {{ cookiecutter.repo_name }}\n" "from foo import {{ cookiecutter.bar }}\n") assert SortImports(file_contents=test_input).output == test_input def test_fcntl(): """Test to ensure fcntl gets correctly recognized as stdlib import""" test_input = ("import fcntl\n" "import os\n" "import sys\n") assert SortImports(file_contents=test_input).output == test_input def test_import_split_is_word_boundary_aware(): """Test to ensure that isort splits words in a boundry aware mannor""" test_input = ("from mycompany.model.size_value_array_import_func import (" " get_size_value_array_import_func_jobs," ")") test_output = SortImports(file_contents=test_input, multi_line_output=WrapModes.VERTICAL_HANGING_INDENT, line_length=79).output assert test_output == ("from mycompany.model.size_value_array_import_func import \\\n" " get_size_value_array_import_func_jobs\n") def test_other_file_encodings(): """Test to ensure file encoding is respected""" try: tmp_dir = tempfile.mkdtemp() for encoding in ('latin1', 'utf8'): tmp_fname = os.path.join(tmp_dir, 'test_{0}.py'.format(encoding)) with codecs.open(tmp_fname, mode='w', encoding=encoding) as f: file_contents = "# coding: {0}\n\ns = u'ã'\n".format(encoding) f.write(file_contents) assert SortImports(file_path=tmp_fname).output == file_contents finally: shutil.rmtree(tmp_dir, ignore_errors=True) def test_comment_at_top_of_file(): """Test to ensure isort correctly handles top of file comments""" test_input = ("# Comment one\n" "from django import forms\n" "# Comment two\n" "from django.contrib.gis.geos import GEOSException\n") assert SortImports(file_contents=test_input).output == test_input test_input = ("# -*- coding: utf-8 -*-\n" "from django.db import models\n") assert SortImports(file_contents=test_input).output == test_input def test_alphabetic_sorting(): """Test to ensure isort correctly handles top of file comments""" test_input = ("from django.contrib.gis.geos import GEOSException\n" "from plone.app.testing import getRoles\n" "from plone.app.testing import ManageRoles\n" "from plone.app.testing import setRoles\n" "from Products.CMFPlone import utils\n" "\n" "import ABC\n" "import unittest\n" "import Zope\n") options = {'force_single_line': True, 'force_alphabetical_sort': True, } assert SortImports(file_contents=test_input, **options).output == test_input test_input = ("# -*- coding: utf-8 -*-\n" "from django.db import models\n") assert SortImports(file_contents=test_input).output == test_input def test_comments_not_duplicated(): """Test to ensure comments aren't duplicated: issue 303""" test_input = ('from flask import url_for\n' "# Whole line comment\n" 'from service import demo # inline comment\n' 'from service import settings\n') output = SortImports(file_contents=test_input).output assert output.count("# Whole line comment\n") == 1 assert output.count("# inline comment\n") == 1 def test_top_of_line_comments(): """Test to ensure top of line comments stay where they should: issue 260""" test_input = ('# -*- coding: utf-8 -*-\n' 'from django.db import models\n' '#import json as simplejson\n' 'from myproject.models import Servidor\n' '\n' 'import reversion\n' '\n' 'import logging\n') output = SortImports(file_contents=test_input).output assert output.startswith('# -*- coding: utf-8 -*-\n') def test_basic_comment(): """Test to ensure a basic comment wont crash isort""" test_input = ('import logging\n' '# Foo\n' 'import os\n') assert SortImports(file_contents=test_input).output == test_input def test_shouldnt_add_lines(): """Ensure that isort doesn't add a blank line when a top of import comment is present, issue #316""" test_input = ('"""Text"""\n' '# This is a comment\n' 'import pkg_resources\n') assert SortImports(file_contents=test_input).output == test_input def test_sections_parsed_correct(): """Ensure that modules for custom sections parsed as list from config file and isort result is correct""" tmp_conf_dir = None conf_file_data = ( '[settings]\n' 'sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER,COMMON\n' 'known_common=nose\n' 'import_heading_common=Common Library\n' 'import_heading_stdlib=Standard Library\n' ) test_input = ( 'import os\n' 'from nose import *\n' 'import nose\n' 'from os import path' ) correct_output = ( '# Standard Library\n' 'import os\n' 'from os import path\n' '\n' '# Common Library\n' 'import nose\n' 'from nose import *\n' ) try: tmp_conf_dir = tempfile.mkdtemp() tmp_conf_name = os.path.join(tmp_conf_dir, '.isort.cfg') with codecs.open(tmp_conf_name, 'w') as test_config: test_config.writelines(conf_file_data) assert SortImports(file_contents=test_input, settings_path=tmp_conf_dir).output == correct_output finally: shutil.rmtree(tmp_conf_dir, ignore_errors=True) def test_alphabetic_sorting_no_newlines(): '''Test to ensure that alphabetical sort does not erroneously introduce new lines (issue #328)''' test_input = "import os\n" test_output = SortImports(file_contents=test_input,force_alphabetical_sort=True).output assert test_input == test_output test_input = ('from a import b\n' '\n' 'import os\n' 'import unittest\n' '\n' '\n' 'print(1)\n') test_output = SortImports(file_contents=test_input,force_alphabetical_sort=True, lines_after_imports=2).output assert test_input == test_output def test_sort_within_section(): '''Test to ensure its possible to force isort to sort within sections''' test_input = ('from Foob import ar\n' 'import foo\n' 'from foo import bar\n' 'from foo.bar import Quux, baz\n') test_output = SortImports(file_contents=test_input,force_sort_within_sections=True).output assert test_output == test_input test_input = ('import foo\n' 'from foo import bar\n' 'from foo.bar import baz\n' 'from foo.bar import Quux\n' 'from Foob import ar\n') test_output = SortImports(file_contents=test_input,force_sort_within_sections=True, order_by_type=False, force_single_line=True).output assert test_output == test_input def test_sorting_with_two_top_comments(): '''Test to ensure isort will sort files that contain 2 top comments''' test_input = ('#! comment1\n' "''' comment2\n" "'''\n" 'import b\n' 'import a\n') assert SortImports(file_contents=test_input).output == ('#! comment1\n' "''' comment2\n" "'''\n" 'import a\n' 'import b\n') isort-4.2.2/tox.ini000066400000000000000000000007021260070737300141760ustar00rootroot00000000000000# Tox (http://tox.testrun.org/) is a tool for running tests # in multiple virtualenvs. This configuration file will run the # test suite on all supported python versions. To use it, "pip install tox" # and then run "tox" from this directory. [tox] envlist = isort-check, py26, py27, py32, py33, py34, py35, pypy [testenv] commands = py.test {posargs} deps = pytest [testenv:isort-check] commands = python setup.py isort deps =