Skip to content

Commit

Permalink
Merge pull request #32 from miki725/windows
Browse files Browse the repository at this point in the history
Fix for importanize on Windows
  • Loading branch information
miki725 committed Jul 28, 2015
2 parents 385c44b + d75ff24 commit 0fc5b5f
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ script:

after_success:
coveralls

sudo: false
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
History
-------

0.4.1 (2015-07-28)
~~~~~~~~~~~~~~~~~~

* Fixed a bug where ``importanize`` did not correctly detect stdlibs on Windows
(see `#29 <https://github.com/miki725/importanize/issues/29/>`_)
* Removed ``future`` dependency since ``six>=1.9`` includes all the used features
* Fixed tests to be executable on Windows

0.4 (2015-04-13)
~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test-coverage:
test-all:
tox

check: clean-build clean-pyc clean-test lint test-coverage
check: lint clean-build clean-pyc clean-test test-coverage

release: clean
python setup.py sdist upload
Expand Down
18 changes: 9 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ Config file is simply a ``json`` file like this::
"path/to/file",
"path/to/files/ignore_*.py"
],
"formatter": 'grouped',
"formatter": "grouped",
"groups": [
{
"type": "stdlib",
"type": "stdlib"
},
{
"type": "remainder",
"type": "remainder"
},
{
"type": "packages",
Expand All @@ -78,24 +78,24 @@ Config file is simply a ``json`` file like this::
]
},
{
"type": "local",
"type": "local"
}
],
]
}

Default config looks something like::

{ "groups": [
{
"type": "stdlib",
"type": "stdlib"
},
{
"type": "remainder",
"type": "remainder"
},
{
"type": "local",
"type": "local"
}
],
]
}

Currently the only required key is ``"groups"`` which must be an array
Expand Down
5 changes: 4 additions & 1 deletion importanize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

__author__ = 'Miroslav Shubernetskiy'
__email__ = '[email protected]'
__version__ = '0.4'
__version__ = '0.4.1'
__description__ = (
'Utility for organizing Python imports using PEP8 or custom rules'
)
6 changes: 3 additions & 3 deletions importanize/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from collections import OrderedDict, defaultdict
from functools import reduce

from future.utils import python_2_unicode_compatible
import six

from .formatters import DEFAULT_FORMATTER
from .utils import is_std_lib


@python_2_unicode_compatible
@six.python_2_unicode_compatible
class BaseImportGroup(object):
def __init__(self, config=None, **kwargs):
self.config = config or {}
Expand Down Expand Up @@ -125,7 +125,7 @@ def should_add_statement(self, statement):
))


@python_2_unicode_compatible
@six.python_2_unicode_compatible
class ImportGroups(object):
def __init__(self, **kwargs):
self.groups = []
Expand Down
16 changes: 11 additions & 5 deletions importanize/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import six

from . import __version__, formatters
from . import __description__, __version__, formatters
from .formatters import DEFAULT_FORMATTER
from .groups import ImportGroups
from .parser import (
Expand Down Expand Up @@ -79,8 +79,7 @@ def find_config():
default_config, found_default = find_config()

parser = argparse.ArgumentParser(
description='Utility for organizing Python imports '
'using PEP8 or custom rules',
description=__description__,
)
parser.add_argument(
'path',
Expand Down Expand Up @@ -231,8 +230,15 @@ def main():
log.debug('Running importanize with {}'.format(args))

if args.version:
msg = 'importanize version: {}'
print(msg.format(__version__))
msg = (
'importanize\n'
'===========\n'
'{}\n\n'
'version: {}\n'
'python: {}\n'
'source: https://github.com/miki725/importanize'
)
print(msg.format(__description__, __version__, sys.executable))
sys.exit(0)

if args.config is None:
Expand Down
6 changes: 3 additions & 3 deletions importanize/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import operator
import re

from future.utils import python_2_unicode_compatible
import six

from .formatters import DEFAULT_FORMATTER
from .mixin import ComparatorMixin
Expand All @@ -13,7 +13,7 @@
DOTS = re.compile(r'^(\.+)(.*)')


@python_2_unicode_compatible
@six.python_2_unicode_compatible
class ImportLeaf(ComparatorMixin):
"""
Data-structure about each import statement leaf-module.
Expand Down Expand Up @@ -82,7 +82,7 @@ def _type(obj):
return self.name > other.name


@python_2_unicode_compatible
@six.python_2_unicode_compatible
class ImportStatement(ComparatorMixin):
"""
Data-structure to store information about
Expand Down
3 changes: 2 additions & 1 deletion importanize/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def ignore_site_packages_paths():
sys.path = list(set(filter(
None,
filter(lambda i: all(('site-packages' not in i,
'python' in i or 'pypy' in i)), sys.path)
'python' in i or 'pypy' in i)),
map(operator.methodcaller('lower'), sys.path))
)))
yield
sys.path = paths
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
future
six
six>=1.9
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from setuptools import find_packages, setup

from importanize import __author__, __version__
from importanize import __author__, __description__, __version__


def read(fname):
Expand All @@ -31,7 +31,7 @@ def read(fname):
name='importanize',
version=__version__,
author=__author__,
description='Utility for organizing Python imports using PEP8 or custom rules',
description=__description__,
long_description='\n\n'.join([readme, history, authors, licence]),
url='https://github.com/miki725/importanize',
license='MIT',
Expand Down
18 changes: 10 additions & 8 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_run_folder(self,
conf,
)
mock_run_importanize.assert_called_once_with(
'root/foo.py',
os.path.join('root', 'foo.py'),
mock.sentinel.config,
conf,
)
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_run_folder_exception(self,
conf,
)
mock_run_importanize.assert_called_once_with(
'root/foo.py',
os.path.join('root', 'foo.py'),
mock.sentinel.config,
conf,
)
Expand All @@ -247,12 +247,12 @@ def test_run_folder_exception(self,
@mock.patch('os.path.exists')
@mock.patch('os.getcwd')
def test_find_config(self, mock_getcwd, mock_exists):
mock_getcwd.return_value = '/path/to/importanize'
mock_getcwd.return_value = os.path.join('path', 'to', 'importanize')
mock_exists.side_effect = False, True

config, found = find_config()

self.assertEqual(config, '/path/to/.importanizerc')
self.assertEqual(config, os.path.join('path', 'to', '.importanizerc'))
self.assertTrue(bool(found))

@mock.patch(TESTING_MODULE + '.run')
Expand All @@ -265,7 +265,7 @@ def test_main_without_config(self,
args = mock.MagicMock(
verbose=1,
version=False,
path=['/path/../'],
path=[os.path.join('path', '..')],
config=None,
)
mock_parse_args.return_value = args
Expand All @@ -275,7 +275,7 @@ def test_main_without_config(self,
mock_parse_args.assert_called_once_with()
mock_get_logger.assert_called_once_with('')
mock_get_logger().setLevel.assert_called_once_with(logging.INFO)
mock_run.assert_called_once_with('/', PEP8_CONFIG, args)
mock_run.assert_called_once_with(os.getcwd(), PEP8_CONFIG, args)

@mock.patch(TESTING_MODULE + '.read')
@mock.patch(TESTING_MODULE + '.run')
Expand All @@ -291,7 +291,7 @@ def test_main_with_config(self,
args = mock.MagicMock(
verbose=1,
version=False,
path=['/path/../'],
path=[os.path.join('path', '..')],
config=mock.sentinel.config,
)
mock_parse_args.return_value = args
Expand All @@ -303,7 +303,9 @@ def test_main_with_config(self,
mock_get_logger().setLevel.assert_called_once_with(logging.INFO)
mock_read.assert_called_once_with(mock.sentinel.config)
mock_loads.assert_called_once_with(mock_read.return_value)
mock_run.assert_called_once_with('/', mock_loads.return_value, args)
mock_run.assert_called_once_with(
os.getcwd(), mock_loads.return_value, args
)

@mock.patch(TESTING_MODULE + '.print', create=True)
@mock.patch('sys.exit')
Expand Down
1 change: 0 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def test_is_std_lib(self):
'collections',
'copy',
'csv',
'curses',
'datetime',
'decimal',
'fileinput',
Expand Down

0 comments on commit 0fc5b5f

Please sign in to comment.