Repository: timothycrosley/isort (python)

Issue:
 For standard library imports support providing a target python (2 or 3)
Till at least the end of the year, isort will need to be able to support Python2 code. However, some packages defined in Python 2.7 don't exist in Python3.x and vice versa. In order to work around this isort should provide the ability to specify the target version when run, and then identify stdlib imports accordingly.

Pull request description:
Issue 899 - Standard Library For different python versions
Hi, 
I am currently working on a fix for Issue #899. 

My current approach is to get the running python interpreter and then return the correct standard library list based on the version.

I still have a couple of questions:

- Is my approach okay? 
- Is it okay to have the lists in the same file or should I create a new file or maybe save the libraries in a .txt-file?
- Where did you get the list of standard libraries because for instance here: [https://github.com/timothycrosley/isort/blob/47571635eaa44ee6a110139c771df3bf322e54c3/isort/settings.py#L90](https://github.com/timothycrosley/isort/blob/47571635eaa44ee6a110139c771df3bf322e54c3/isort/settings.py#L90)

What is _aetools_ or _aepack_ ? I could not find them here: [Python3.7 standard library](https://docs.python.org/3.7/py-modindex.html)

Best regards! :)

ToDo: 
- [ ] Adjust Python2 Standard Library List
- [x] Throw exception if different version?

EDIT: I just found out that _aetools_  is part of the [Python2.7 standard library](https://docs.python.org/2.7/py-modindex.html). Could it be that the default_standard_library list needs a polish? If so, I could do that as well. Just let me know if it is okay to just get the standard library from the two links I posted! :)

EDIT 2:
Closes #899 


Patch:
diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md
index 432862b7..971ee83c 100644
--- a/ACKNOWLEDGEMENTS.md
+++ b/ACKNOWLEDGEMENTS.md
@@ -80,6 +80,7 @@ Code Contributors
 - Brian F. Baron (@briabar)
 - Madison Caldwell (@madirey)
 - Matt Yule-Bennett (@mattbennett)
+- Jaswanth Kumar (@jaswanth098)
 
 Documenters
 ===================
diff --git a/isort/main.py b/isort/main.py
index 8d5e2353..64bf2f47 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -284,7 +284,7 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]:
                         help='Returns just the current version number without the logo')
     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('-wl', '--wrap-length', dest='wrap_length',
+    parser.add_argument('-wl', '--wrap-length', dest='wrap_length', type=int,
                         help="Specifies how long lines that are wrapped should be, if not set line_length is used.")
     parser.add_argument('-ws', '--ignore-whitespace', action='store_true', dest="ignore_whitespace",
                         help='Tells isort to ignore whitespace differences when --check-only is being used.')
@@ -298,6 +298,9 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]:
     parser.add_argument('--filter-files', dest='filter_files', action='store_true',
                         help='Tells isort to filter files even when they are explicitly passed in as part of the command')
     parser.add_argument('files', nargs='*', help='One or more Python source files that need their imports sorted.')
+    parser.add_argument('-py', '--python-version', action='store', dest='py_version',
+                        help='Tells isort to sort the standard library based on the python version. '
+                             'Default is the version of the running interpreter, for instance: -py 3, -py 2.7')
 
     arguments = {key: value for key, value in vars(parser.parse_args(argv)).items() if value}
     if 'dont_order_by_type' in arguments:
diff --git a/isort/settings.py b/isort/settings.py
index 9ab88f65..bf156ef3 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -28,12 +28,15 @@ import fnmatch
 import os
 import posixpath
 import re
+import sys
 import warnings
 from distutils.util import strtobool
 from functools import lru_cache
 from pathlib import Path
-from typing import Any, Callable, Dict, Iterable, List, Mapping, MutableMapping, Union
+from typing import Any, Callable, Dict, Iterable, List, Mapping, MutableMapping, Optional, Union
 
+from .stdlibs.py_three import standard_library_3
+from .stdlibs.py_two import standard_library_2
 from .utils import difference, union
 
 try:
@@ -53,7 +56,7 @@ DEFAULT_SECTIONS = ('FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER
 
 safety_exclude_re = re.compile(
     r"/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|\.pants\.d"
-    r"|lib/python[0-9].[0-9]+)/"
+    r"|lib/python[0-9].[0-9]+|node_modules)/"
 )
 
 
@@ -72,6 +75,48 @@ class WrapModes(enum.Enum):
         return getattr(WrapModes, str(value), None) or WrapModes(int(value))
 
 
+def _get_default(py_version: Optional[str]) -> dict:
+    """
+    Returns the correct standard library based on either the passed py_version flag or the python interpreter
+    Additionaly users have the option to pass all as value instead of an
+    version. As an result code will be checked against both standard libraries - python2 & python3
+
+    See Issue 889 and 778 for more information
+    """
+
+    if py_version is None:
+        major, minor = sys.version_info[0:2]
+    elif py_version is not "all":
+        minor = 0
+
+        # we have a minor
+        if "." in py_version:
+            # we do not care about patches just major and minor
+            splits = py_version.split(".")[0:2]
+            major = int(splits[0])
+            minor = int(splits[1])
+        else:
+            major = int(py_version)
+
+    _default = default.copy()
+
+    if py_version is "all":
+        standard_library = list(set(standard_library_3 + standard_library_2))
+    elif major == 3:
+        standard_library = standard_library_3
+    elif major == 2 and minor == 7:
+        standard_library = standard_library_2
+    else:
+        raise ValueError(
+            "The python version %s is not supported. "
+            "You can set a python version with the -py or --python-version flag " % py_version
+        )
+
+    _default['known_standard_library'] = standard_library
+
+    return _default
+
+
 # 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': [],
@@ -82,51 +127,6 @@ default = {'force_to_top': [],
            'sections': DEFAULT_SECTIONS,
            'no_sections': False,
            'known_future_library': ['__future__'],
-           'known_standard_library': ['AL', 'BaseHTTPServer', 'Bastion', 'CGIHTTPServer', 'Carbon', 'ColorPicker',
-                                      'ConfigParser', 'Cookie', 'DEVICE', 'DocXMLRPCServer', 'EasyDialogs', 'FL',
-                                      'FrameWork', 'GL', 'HTMLParser', 'MacOS', 'MimeWriter', 'MiniAEFrame', 'Nav',
-                                      'PixMapWrapper', 'Queue', 'SUNAUDIODEV', 'ScrolledText', 'SimpleHTTPServer',
-                                      'SimpleXMLRPCServer', 'SocketServer', 'StringIO', 'Tix', 'Tkinter', 'UserDict',
-                                      'UserList', 'UserString', 'W', '__builtin__', 'abc', 'aepack', 'aetools',
-                                      'aetypes', 'aifc', 'al', 'anydbm', 'applesingle', 'argparse', 'array', 'ast',
-                                      'asynchat', 'asyncio', 'asyncore', 'atexit', 'audioop', 'autoGIL', 'base64',
-                                      'bdb', 'binascii', 'binhex', 'bisect', 'bsddb', 'buildtools', 'builtins',
-                                      'bz2', 'cPickle', 'cProfile', 'cStringIO', 'calendar', 'cd', 'cfmfile', 'cgi',
-                                      'cgitb', 'chunk', 'cmath', 'cmd', 'code', 'codecs', 'codeop', 'collections',
-                                      'colorsys', 'commands', 'compileall', 'compiler', 'concurrent', 'configparser',
-                                      'contextlib', 'contextvars', 'cookielib', 'copy', 'copy_reg', 'copyreg', 'crypt', 'csv',
-                                      'ctypes', 'curses', 'dataclasses', 'datetime', 'dbhash', 'dbm', 'decimal', 'difflib',
-                                      'dircache', 'dis', 'distutils', 'dl', 'doctest', 'dumbdbm', 'dummy_thread',
-                                      'dummy_threading', 'email', 'encodings', 'ensurepip', 'enum', 'errno',
-                                      'exceptions', 'faulthandler', 'fcntl', 'filecmp', 'fileinput', 'findertools',
-                                      'fl', 'flp', 'fm', 'fnmatch', 'formatter', 'fpectl', 'fpformat', 'fractions',
-                                      'ftplib', 'functools', 'future_builtins', 'gc', 'gdbm', 'gensuitemodule',
-                                      'getopt', 'getpass', 'gettext', 'gl', 'glob', 'grp', 'gzip', 'hashlib',
-                                      'heapq', 'hmac', 'hotshot', 'html', 'htmlentitydefs', 'htmllib', 'http',
-                                      'httplib', 'ic', 'icopen', 'imageop', 'imaplib', 'imgfile', 'imghdr', 'imp',
-                                      'importlib', 'imputil', 'inspect', 'io', 'ipaddress', 'itertools', 'jpeg',
-                                      'json', 'keyword', 'lib2to3', 'linecache', 'locale', 'logging', 'lzma',
-                                      'macerrors', 'macostools', 'macpath', 'macresource', 'mailbox', 'mailcap',
-                                      'marshal', 'math', 'md5', 'mhlib', 'mimetools', 'mimetypes', 'mimify', 'mmap',
-                                      'modulefinder', 'msilib', 'msvcrt', 'multifile', 'multiprocessing', 'mutex',
-                                      'netrc', 'new', 'nis', 'nntplib', 'numbers', 'operator', 'optparse', 'os',
-                                      'ossaudiodev', 'parser', 'pathlib', 'pdb', 'pickle', 'pickletools', 'pipes',
-                                      'pkgutil', 'platform', 'plistlib', 'popen2', 'poplib', 'posix', 'posixfile',
-                                      'pprint', 'profile', 'pstats', 'pty', 'pwd', 'py_compile', 'pyclbr', 'pydoc',
-                                      'queue', 'quopri', 'random', 're', 'readline', 'reprlib', 'resource', 'rexec',
-                                      'rfc822', 'rlcompleter', 'robotparser', 'runpy', 'sched', 'secrets', 'select',
-                                      'selectors', 'sets', 'sgmllib', 'sha', 'shelve', 'shlex', 'shutil', 'signal',
-                                      'site', 'sitecustomize', 'smtpd', 'smtplib', 'sndhdr', 'socket', 'socketserver',
-                                      'spwd', 'sqlite3', 'ssl', 'stat', 'statistics', 'statvfs', 'string', 'stringprep',
-                                      'struct', 'subprocess', 'sunau', 'sunaudiodev', 'symbol', 'symtable', 'sys',
-                                      'sysconfig', 'syslog', 'tabnanny', 'tarfile', 'telnetlib', 'tempfile', 'termios',
-                                      'test', 'textwrap', 'this', 'thread', 'threading', 'time', 'timeit', 'tkinter',
-                                      'token', 'tokenize', 'trace', 'traceback', 'tracemalloc', 'ttk', 'tty', 'turtle',
-                                      'turtledemo', 'types', 'typing', 'unicodedata', 'unittest', 'urllib', 'urllib2',
-                                      'urlparse', 'usercustomize', 'uu', 'uuid', 'venv', 'videoreader',
-                                      'warnings', 'wave', 'weakref', 'webbrowser', 'whichdb', 'winreg', 'winsound',
-                                      'wsgiref', 'xdrlib', 'xml', 'xmlrpc', 'xmlrpclib', 'zipapp', 'zipfile',
-                                      'zipimport', 'zlib'],
            'known_third_party': ['google.appengine.api'],
            'known_first_party': [],
            'multi_line_output': WrapModes.GRID,
@@ -173,8 +173,8 @@ default = {'force_to_top': [],
 
 
 @lru_cache()
-def from_path(path: Union[str, Path]) -> Dict[str, Any]:
-    computed_settings = default.copy()
+def from_path(path: Union[str, Path], py_version: Optional[str] = None) -> Dict[str, Any]:
+    computed_settings = _get_default(py_version)
     isort_defaults = ['~/.isort.cfg']
     if appdirs:
         isort_defaults = [appdirs.user_config_dir('isort.cfg')] + isort_defaults
@@ -191,7 +191,8 @@ def from_path(path: Union[str, Path]) -> Dict[str, Any]:
 
 
 def prepare_config(settings_path: Path, **setting_overrides: Any) -> Dict[str, Any]:
-    config = from_path(settings_path).copy()
+    py_version = setting_overrides.pop("py_version", None)
+    config = from_path(settings_path, py_version).copy()
     for key, value in setting_overrides.items():
         access_key = key.replace('not_', '').lower()
         # The sections config needs to retain order and can't be converted to a set.
diff --git a/isort/stdlibs/__init__.py b/isort/stdlibs/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/isort/stdlibs/py_three.py b/isort/stdlibs/py_three.py
new file mode 100644
index 00000000..744e19d1
--- /dev/null
+++ b/isort/stdlibs/py_three.py
@@ -0,0 +1,52 @@
+"""
+File contains the standard library of python3
+
+If in any minor the standard library changes, a new list should be
+created and the names adjusted
+"""
+
+standard_library_3 = ['AL', 'BaseHTTPServer', 'Bastion', 'CGIHTTPServer', 'Carbon', 'ColorPicker',
+                      'ConfigParser', 'Cookie', 'DEVICE', 'DocXMLRPCServer', 'EasyDialogs', 'FL',
+                      'FrameWork', 'GL', 'HTMLParser', 'MacOS', 'MimeWriter', 'MiniAEFrame', 'Nav',
+                      'PixMapWrapper', 'Queue', 'SUNAUDIODEV', 'ScrolledText', 'SimpleHTTPServer',
+                      'SimpleXMLRPCServer', 'SocketServer', 'StringIO', 'Tix', 'Tkinter', 'UserDict',
+                      'UserList', 'UserString', 'W', '__builtin__', 'abc', 'aepack', 'aetools',
+                      'aetypes', 'aifc', 'al', 'anydbm', 'applesingle', 'argparse', 'array', 'ast',
+                      'asynchat', 'asyncio', 'asyncore', 'atexit', 'audioop', 'autoGIL', 'base64',
+                      'bdb', 'binascii', 'binhex', 'bisect', 'bsddb', 'buildtools', 'builtins',
+                      'bz2', 'cPickle', 'cProfile', 'cStringIO', 'calendar', 'cd', 'cfmfile', 'cgi',
+                      'cgitb', 'chunk', 'cmath', 'cmd', 'code', 'codecs', 'codeop', 'collections',
+                      'colorsys', 'commands', 'compileall', 'compiler', 'concurrent', 'configparser',
+                      'contextlib', 'contextvars', 'cookielib', 'copy', 'copy_reg', 'copyreg', 'crypt', 'csv',
+                      'ctypes', 'curses', 'dataclasses', 'datetime', 'dbhash', 'dbm', 'decimal', 'difflib',
+                      'dircache', 'dis', 'distutils', 'dl', 'doctest', 'dumbdbm', 'dummy_thread',
+                      'dummy_threading', 'email', 'encodings', 'ensurepip', 'enum', 'errno',
+                      'exceptions', 'faulthandler', 'fcntl', 'filecmp', 'fileinput', 'findertools',
+                      'fl', 'flp', 'fm', 'fnmatch', 'formatter', 'fpectl', 'fpformat', 'fractions',
+                      'ftplib', 'functools', 'future_builtins', 'gc', 'gdbm', 'gensuitemodule',
+                      'getopt', 'getpass', 'gettext', 'gl', 'glob', 'grp', 'gzip', 'hashlib',
+                      'heapq', 'hmac', 'hotshot', 'html', 'htmlentitydefs', 'htmllib', 'http',
+                      'httplib', 'ic', 'icopen', 'imageop', 'imaplib', 'imgfile', 'imghdr', 'imp',
+                      'importlib', 'imputil', 'inspect', 'io', 'ipaddress', 'itertools', 'jpeg',
+                      'json', 'keyword', 'lib2to3', 'linecache', 'locale', 'logging', 'lzma',
+                      'macerrors', 'macostools', 'macpath', 'macresource', 'mailbox', 'mailcap',
+                      'marshal', 'math', 'md5', 'mhlib', 'mimetools', 'mimetypes', 'mimify', 'mmap',
+                      'modulefinder', 'msilib', 'msvcrt', 'multifile', 'multiprocessing', 'mutex',
+                      'netrc', 'new', 'nis', 'nntplib', 'numbers', 'operator', 'optparse', 'os',
+                      'ossaudiodev', 'parser', 'pathlib', 'pdb', 'pickle', 'pickletools', 'pipes',
+                      'pkgutil', 'platform', 'plistlib', 'popen2', 'poplib', 'posix', 'posixfile',
+                      'pprint', 'profile', 'pstats', 'pty', 'pwd', 'py_compile', 'pyclbr', 'pydoc',
+                      'queue', 'quopri', 'random', 're', 'readline', 'reprlib', 'resource', 'rexec',
+                      'rfc822', 'rlcompleter', 'robotparser', 'runpy', 'sched', 'secrets', 'select',
+                      'selectors', 'sets', 'sgmllib', 'sha', 'shelve', 'shlex', 'shutil', 'signal',
+                      'site', 'sitecustomize', 'smtpd', 'smtplib', 'sndhdr', 'socket', 'socketserver',
+                      'spwd', 'sqlite3', 'ssl', 'stat', 'statistics', 'statvfs', 'string', 'stringprep',
+                      'struct', 'subprocess', 'sunau', 'sunaudiodev', 'symbol', 'symtable', 'sys',
+                      'sysconfig', 'syslog', 'tabnanny', 'tarfile', 'telnetlib', 'tempfile', 'termios',
+                      'test', 'textwrap', 'this', 'thread', 'threading', 'time', 'timeit', 'tkinter',
+                      'token', 'tokenize', 'trace', 'traceback', 'tracemalloc', 'ttk', 'tty', 'turtle',
+                      'turtledemo', 'types', 'typing', 'unicodedata', 'unittest', 'urllib', 'urllib2',
+                      'urlparse', 'usercustomize', 'uu', 'uuid', 'venv', 'videoreader',
+                      'warnings', 'wave', 'weakref', 'webbrowser', 'whichdb', 'winreg', 'winsound',
+                      'wsgiref', 'xdrlib', 'xml', 'xmlrpc', 'xmlrpclib', 'zipapp', 'zipfile',
+                      'zipimport', 'zlib']
diff --git a/isort/stdlibs/py_two.py b/isort/stdlibs/py_two.py
new file mode 100644
index 00000000..f00c6f3e
--- /dev/null
+++ b/isort/stdlibs/py_two.py
@@ -0,0 +1,49 @@
+"""
+File contains the standard library of python 2.7
+"""
+
+standard_library_2 = ['AL', 'BaseHTTPServer', 'Bastion', 'CGIHTTPServer', 'Carbon', 'ColorPicker',
+                      'ConfigParser', 'Cookie', 'DEVICE', 'DocXMLRPCServer', 'EasyDialogs', 'FL',
+                      'FrameWork', 'GL', 'HTMLParser', 'MacOS', 'MimeWriter', 'MiniAEFrame', 'Nav',
+                      'PixMapWrapper', 'Queue', 'SUNAUDIODEV', 'ScrolledText', 'SimpleHTTPServer',
+                      'SimpleXMLRPCServer', 'SocketServer', 'StringIO', 'Tix', 'Tkinter', 'UserDict',
+                      'UserList', 'UserString', 'W', '__builtin__', 'abc', 'aepack', 'aetools',
+                      'aetypes', 'aifc', 'al', 'anydbm', 'applesingle', 'argparse', 'array', 'ast',
+                      'asynchat', 'asyncio', 'asyncore', 'atexit', 'audioop', 'autoGIL', 'base64',
+                      'bdb', 'binascii', 'binhex', 'bisect', 'bsddb', 'buildtools', 'builtins',
+                      'bz2', 'cPickle', 'cProfile', 'cStringIO', 'calendar', 'cd', 'cfmfile', 'cgi',
+                      'cgitb', 'chunk', 'cmath', 'cmd', 'code', 'codecs', 'codeop', 'collections',
+                      'colorsys', 'commands', 'compileall', 'compiler', 'concurrent', 'configparser',
+                      'contextlib', 'contextvars', 'cookielib', 'copy', 'copy_reg', 'copyreg', 'crypt', 'csv',
+                      'ctypes', 'curses', 'dataclasses', 'datetime', 'dbhash', 'dbm', 'decimal', 'difflib',
+                      'dircache', 'dis', 'distutils', 'dl', 'doctest', 'dumbdbm', 'dummy_thread',
+                      'dummy_threading', 'email', 'encodings', 'ensurepip', 'enum', 'errno',
+                      'exceptions', 'faulthandler', 'fcntl', 'filecmp', 'fileinput', 'findertools',
+                      'fl', 'flp', 'fm', 'fnmatch', 'formatter', 'fpectl', 'fpformat', 'fractions',
+                      'ftplib', 'functools', 'future_builtins', 'gc', 'gdbm', 'gensuitemodule',
+                      'getopt', 'getpass', 'gettext', 'gl', 'glob', 'grp', 'gzip', 'hashlib',
+                      'heapq', 'hmac', 'hotshot', 'html', 'htmlentitydefs', 'htmllib', 'http',
+                      'httplib', 'ic', 'icopen', 'imageop', 'imaplib', 'imgfile', 'imghdr', 'imp',
+                      'importlib', 'imputil', 'inspect', 'io', 'ipaddress', 'itertools', 'jpeg',
+                      'json', 'keyword', 'lib2to3', 'linecache', 'locale', 'logging', 'lzma',
+                      'macerrors', 'macostools', 'macpath', 'macresource', 'mailbox', 'mailcap',
+                      'marshal', 'math', 'md5', 'mhlib', 'mimetools', 'mimetypes', 'mimify', 'mmap',
+                      'modulefinder', 'msilib', 'msvcrt', 'multifile', 'multiprocessing', 'mutex',
+                      'netrc', 'new', 'nis', 'nntplib', 'numbers', 'operator', 'optparse', 'os',
+                      'ossaudiodev', 'parser', 'pathlib', 'pdb', 'pickle', 'pickletools', 'pipes',
+                      'pkgutil', 'platform', 'plistlib', 'popen2', 'poplib', 'posix', 'posixfile',
+                      'pprint', 'profile', 'pstats', 'pty', 'pwd', 'py_compile', 'pyclbr', 'pydoc',
+                      'queue', 'quopri', 'random', 're', 'readline', 'reprlib', 'resource', 'rexec',
+                      'rfc822', 'rlcompleter', 'robotparser', 'runpy', 'sched', 'secrets', 'select',
+                      'selectors', 'sets', 'sgmllib', 'sha', 'shelve', 'shlex', 'shutil', 'signal',
+                      'site', 'sitecustomize', 'smtpd', 'smtplib', 'sndhdr', 'socket', 'socketserver',
+                      'spwd', 'sqlite3', 'ssl', 'stat', 'statistics', 'statvfs', 'string', 'stringprep',
+                      'struct', 'subprocess', 'sunau', 'sunaudiodev', 'symbol', 'symtable', 'sys',
+                      'sysconfig', 'syslog', 'tabnanny', 'tarfile', 'telnetlib', 'tempfile', 'termios',
+                      'test', 'textwrap', 'this', 'thread', 'threading', 'time', 'timeit', 'tkinter',
+                      'token', 'tokenize', 'trace', 'traceback', 'tracemalloc', 'ttk', 'tty', 'turtle',
+                      'turtledemo', 'types', 'typing', 'unicodedata', 'unittest', 'urllib', 'urllib2',
+                      'urlparse', 'user', 'usercustomize', 'uu', 'uuid', 'venv', 'videoreader',
+                      'warnings', 'wave', 'weakref', 'webbrowser', 'whichdb', 'winreg', 'winsound',
+                      'wsgiref', 'xdrlib', 'xml', 'xmlrpc', 'xmlrpclib', 'zipapp', 'zipfile',
+                      'zipimport', 'zlib']
diff --git a/setup.py b/setup.py
index 7ca16da3..f1e0747c 100755
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-from setuptools import setup
+from setuptools import find_packages, setup
 
 with open('README.rst') as f:
     readme = f.read()
@@ -20,7 +20,7 @@ setup(name='isort',
         'distutils.commands': ['isort = isort.main:ISortCommand'],
         'pylama.linter': ['isort = isort.pylama_isort:Linter'],
       },
-      packages=['isort'],
+      packages=find_packages(),
       extras_require={
           'pipfile': ['pipreqs', 'requirementslib'],
           'pyproject': ['toml'],


Test patch:
diff --git a/test_isort.py b/test_isort.py
index 86c7d868..bb5305ac 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -3352,3 +3352,28 @@ def test_pyi_formatting_issue_942(tmpdir):
     source_pyi = tmpdir.join('source.pyi')
     source_pyi.write(test_input)
     assert SortImports(file_path=str(source_pyi)).output.splitlines() == expected_pyi_output
+
+
+def test_python_version():
+    from isort.main import parse_args
+
+    # test that the py_version can be added as flag
+    args = parse_args(['-py=2.7'])
+    assert args["py_version"] == "2.7"
+
+    args = parse_args(['--python-version=3'])
+    assert args["py_version"] == "3"
+
+    test_input = ('import os\n'
+                  '\n'
+                  'import user\n')
+    assert SortImports(file_contents=test_input, py_version="3").output == test_input
+
+    # user is part of the standard library in python 2
+    output_python_2 = ('import os\n'
+                       'import user\n')
+    assert SortImports(file_contents=test_input, py_version="2.7").output == output_python_2
+
+    test_input = ('import os\nimport xml')
+
+    print(SortImports(file_contents=test_input, py_version="all").output )