summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-03-07 23:53:50 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-03-08 00:31:54 -0800
commitffb4288cfb7ae7646ab9c5a84cc4167d4fcf3940 (patch)
tree68645b67b5c239b4c11953e173a888c59da56e5d
parentb2bc1d43a6ec1c19e9057ae30cd147226e11d745 (diff)
downloadisort-ffb4288cfb7ae7646ab9c5a84cc4167d4fcf3940.tar.gz
Fix issue #890
-rw-r--r--CHANGELOG.md1
-rw-r--r--isort/isort.py3
-rw-r--r--isort/main.py2
-rw-r--r--isort/settings.py3
-rw-r--r--test_isort.py21
5 files changed, 28 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 48c2d77e..a73e70c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ Planned:
### 4.3.13 - March 6, 2019 - hot fix release
- Fixed the inability to accurately determine import section when a mix of conda and virtual environments are used.
- Fixed some output being printed even when --quiet mode is enabled.
+- Fixed issue #890 interoperability with PyCharm by allowing case sensitive non type grouped sorting
### 4.3.12 - March 6, 2019 - hot fix release
- Fix error caused when virtual environment not detected
diff --git a/isort/isort.py b/isort/isort.py
index 5b35b0d5..19bdceb2 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -302,7 +302,8 @@ class SortImports(object):
prefix = "B"
else:
prefix = "C"
- module_name = module_name.lower()
+ if not config['case_sensitive']:
+ module_name = module_name.lower()
if section_name is None or 'length_sort_' + str(section_name).lower() not in config:
length_sort = config['length_sort']
else:
diff --git a/isort/main.py b/isort/main.py
index 767927d4..3cc00c30 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -291,6 +291,8 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]:
parser.add_argument('--unsafe', dest='unsafe', action='store_true',
help='Tells isort to look for files in standard library directories, etc. '
'where it may not be safe to operate in')
+ parser.add_argument('--case-sensitive', dest='case_sensitive', action='store_true',
+ help='Tells isort to include casing when sorting module names')
parser.add_argument('files', nargs='*', help='One or more Python source files that need their imports sorted.')
arguments = {key: value for key, value in vars(parser.parse_args(argv)).items() if value}
diff --git a/isort/settings.py b/isort/settings.py
index 43a0f2a4..6504be53 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -167,7 +167,8 @@ default = {'force_to_top': [],
'no_lines_before': [],
'no_inline_sort': False,
'ignore_comments': False,
- 'safety_excludes': True}
+ 'safety_excludes': True,
+ 'case_sensitive': False}
@lru_cache()
diff --git a/test_isort.py b/test_isort.py
index 9b3c1e42..fce3e3f0 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2880,3 +2880,24 @@ def test_extract_multiline_output_wrap_setting_from_a_config_file(tmpdir: py.pat
config = settings.from_path(str(tmpdir))
assert config['multi_line_output'] == WrapModes.VERTICAL_GRID_GROUPED
+
+
+def test_ensure_support_for_non_typed_but_cased_alphabetic_sort_issue_890():
+ test_input = ('from pkg import BALL\n'
+ 'from pkg import RC\n'
+ 'from pkg import Action\n'
+ 'from pkg import Bacoo\n'
+ 'from pkg import RCNewCode\n'
+ 'from pkg import actual\n'
+ 'from pkg import rc\n'
+ 'from pkg import recorder\n')
+ expected_output = ('from pkg import Action\n'
+ 'from pkg import BALL\n'
+ 'from pkg import Bacoo\n'
+ 'from pkg import RC\n'
+ 'from pkg import RCNewCode\n'
+ 'from pkg import actual\n'
+ 'from pkg import rc\n'
+ 'from pkg import recorder\n')
+ assert SortImports(file_contents=test_input, case_sensitive=True, order_by_type=False,
+ force_single_line=True).output == expected_output