Merge branch 'release/2.6.0'
diff --git a/README.md b/README.md
index 32cf916..be5d0d6 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,7 @@
[![PyPI version](https://badge.fury.io/py/isort.png)](http://badge.fury.io/py/isort)
[![PyPi downloads](https://pypip.in/d/isort/badge.png)](https://crate.io/packages/isort/)
[![Build Status](https://travis-ci.org/timothycrosley/isort.png?branch=master)](https://travis-ci.org/timothycrosley/isort)
+[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/timothycrosley/isort/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
isort your python imports for you so you don't have to.
@@ -221,6 +222,14 @@
lib5, ...
)
+Alternatively, you can set force_single_line to True (-sl on the command line) and every import will appear on its
+own line
+
+ from third_party import lib1
+ from third_party import lib2
+ from third_party import lib3
+ ...
+
Ordering by import length
======================
diff --git a/isort/__init__.py b/isort/__init__.py
index 2b043d4..dbcfb31 100644
--- a/isort/__init__.py
+++ b/isort/__init__.py
@@ -25,4 +25,4 @@
from . import settings
from .isort import SECTION_NAMES, SECTIONS, SortImports
-__version__ = "2.5.0"
+__version__ = "2.6.0"
diff --git a/isort/isort.py b/isort/isort.py
index 8246b64..92b7135 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -229,6 +229,10 @@
if from_imports:
if "*" in from_imports:
import_statement = "{0}*".format(import_start)
+ elif self.config['force_single_line']:
+ import_statement = import_start + from_imports.pop(0)
+ for from_import in from_imports:
+ import_statement += "\n{0}{1}".format(import_start, from_import)
else:
import_statement = import_start + (", ").join(from_imports)
if len(import_statement) > self.config['line_length'] and len(from_imports) > 1:
diff --git a/isort/settings.py b/isort/settings.py
index 8b51b8c..62f0a11 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -65,6 +65,7 @@
'length_sort': False,
'add_imports': [],
'remove_imports': [],
+ 'force_single_line': False,
'default_section': 'FIRSTPARTY'}
try:
diff --git a/scripts/isort b/scripts/isort
index 8640d99..2726b3f 100755
--- a/scripts/isort
+++ b/scripts/isort
@@ -39,6 +39,8 @@
parser.add_argument('-c', '--check-only', action='store_true', default=False, dest="check",
help='Checks the file for unsorted 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(SECTION_NAMES))
parser.add_argument('-df', '--diff', dest='show_diff', default=False, action='store_true',
diff --git a/setup.py b/setup.py
index 108d1cb..bc40de9 100755
--- a/setup.py
+++ b/setup.py
@@ -37,12 +37,12 @@
setup(name='isort',
- version='2.5.0',
+ version='2.6.0',
description='A Python utility / library to sort Python imports.',
author='Timothy Crosley',
author_email='timothy.crosley@gmail.com',
url='https://github.com/timothycrosley/isort',
- download_url='https://github.com/timothycrosley/isort/archive/2.5.0.tar.gz',
+ download_url='https://github.com/timothycrosley/isort/archive/2.6.0.tar.gz',
license="MIT",
scripts=['scripts/isort'],
packages=['isort'],
diff --git a/test_isort.py b/test_isort.py
index 90e62fc..98cdc6b 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -494,3 +494,37 @@
"import sys\n"
"\n"
"import django.settings\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")