diff --git a/example_shared_isort_profile/example_shared_isort_profile.py b/example_shared_isort_profile/example_shared_isort_profile.py new file mode 100644 index 000000000..986ddd5de --- /dev/null +++ b/example_shared_isort_profile/example_shared_isort_profile.py @@ -0,0 +1,7 @@ +PROFILE = { + "multi_line_output": 3, + "include_trailing_comma": True, + "force_grid_wrap": 0, + "use_parentheses": True, + "line_length": 100, +} diff --git a/example_shared_isort_profile/poetry.lock b/example_shared_isort_profile/poetry.lock new file mode 100644 index 000000000..12fbad913 --- /dev/null +++ b/example_shared_isort_profile/poetry.lock @@ -0,0 +1,7 @@ +package = [] + +[metadata] +content-hash = "8165d934e932435bf4742b9198674202413b43524911713d5c7c55cb8d314618" +python-versions = "^3.5" + +[metadata.files] diff --git a/example_shared_isort_profile/pyproject.toml b/example_shared_isort_profile/pyproject.toml new file mode 100644 index 000000000..7a290ddc0 --- /dev/null +++ b/example_shared_isort_profile/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "example_shared_isort_profile" +version = "0.0.1" +description = "An example shared isort profile" +authors = ["Timothy Crosley "] +license = "MIT" + +[tool.poetry.plugins."isort.profiles"] +example = "example_shared_isort_profile:PROFILE" + +[tool.poetry.dependencies] +python = "^3.6" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry>=0.12"] +build-backend = "poetry.masonry.api" diff --git a/isort/main.py b/isort/main.py index 3ccf0d14d..c90b824ad 100644 --- a/isort/main.py +++ b/isort/main.py @@ -569,9 +569,9 @@ def _build_arg_parser() -> argparse.ArgumentParser: parser.add_argument( "--profile", dest="profile", - choices=list(profiles.keys()), type=str, - help="Base profile type to use for configuration.", + help="Base profile type to use for configuration. " + f"Profiles include: {', '.join(profiles.keys())}. As well as any shared profiles.", ) parser.add_argument( "--interactive", diff --git a/isort/settings.py b/isort/settings.py index 09255c819..b6eebb237 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -265,7 +265,7 @@ def __init__( import pkg_resources for plugin in pkg_resources.iter_entry_points("isort.profiles"): - profiles.setdefault(plugin.name, plugin.load().PROFILE) # pragma: no cover + profiles.setdefault(plugin.name, plugin.load()) if profile_name not in profiles: raise ProfileDoesNotExist(profile_name) diff --git a/poetry.lock b/poetry.lock index b1bdaa498..1e81bd69d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -259,6 +259,14 @@ toml = "*" [package.extras] pipenv = ["pipenv"] +[[package]] +category = "dev" +description = "An example shared isort profile" +name = "example-shared-isort-profile" +optional = false +python-versions = ">=3.6,<4.0" +version = "0.0.1" + [[package]] category = "dev" description = "Tests and Documentation Done by Example." @@ -1532,7 +1540,7 @@ pipfile_deprecated_finder = ["pipreqs", "tomlkit", "requirementslib"] requirements_deprecated_finder = ["pipreqs", "pip-api"] [metadata] -content-hash = "ace34d56082ee3f0ccfa77f6c8b6a6e8a6449a1e51a0e31a69368c697af7384b" +content-hash = "4db91d831e91eff8a42ff63d3ba2683d3575886c5d23c09cd27dc4196d41b28b" python-versions = "^3.6" [metadata.files] @@ -1657,6 +1665,10 @@ dparse = [ {file = "dparse-0.5.1-py3-none-any.whl", hash = "sha256:e953a25e44ebb60a5c6efc2add4420c177f1d8404509da88da9729202f306994"}, {file = "dparse-0.5.1.tar.gz", hash = "sha256:a1b5f169102e1c894f9a7d5ccf6f9402a836a5d24be80a986c7ce9eaed78f367"}, ] +example-shared-isort-profile = [ + {file = "example_shared_isort_profile-0.0.1-py3-none-any.whl", hash = "sha256:3fa3e2d093e68285fc7893704b727791ed3e0969d07bdd2733e366303d1a2582"}, + {file = "example_shared_isort_profile-0.0.1.tar.gz", hash = "sha256:fc2a0fa892611d6c1c2060dc0ca8e511e3f65fad8e4e449e8a375ef49549e710"}, +] examples = [ {file = "examples-1.0.2-py3-none-any.whl", hash = "sha256:372fefd15d5a17bda3b003cf26edbc2d29632bc63f29c816b55ed33dcccb3e65"}, {file = "examples-1.0.2.tar.gz", hash = "sha256:f29ba443f158bb47913ac21f098306a9749ed459a2290540ff1f86baac074597"}, diff --git a/pyproject.toml b/pyproject.toml index 464e8f059..43b71a910 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,6 +75,7 @@ pip-shims = "^0.5.2" smmap2 = "^3.0.1" gitdb2 = "^4.0.2" httpx = "^0.13.3" +example_shared_isort_profile = "^0.0.1" [tool.poetry.scripts] isort = "isort.main:main" diff --git a/tests/test_ticketed_features.py b/tests/test_ticketed_features.py index e57b32d91..cfb586e47 100644 --- a/tests/test_ticketed_features.py +++ b/tests/test_ticketed_features.py @@ -6,7 +6,7 @@ import pytest import isort -from isort import Config +from isort import Config, exceptions def test_semicolon_ignored_for_dynamic_lines_after_import_issue_1178(): @@ -200,7 +200,7 @@ def test_isort_warns_when_known_sections_dont_match_issue_1331(): ) -def test_isort_supports_append_only_imports_727(): +def test_isort_supports_append_only_imports_issue_727(): """Test to ensure isort provides a way to only add imports as an append. See: https://github.com/timothycrosley/isort/issues/727. """ @@ -212,3 +212,13 @@ def test_isort_supports_append_only_imports_727(): import os """ ) + + +def test_isort_supports_shared_profiles_issue_970(): + """Test to ensure isort provides a way to use shared profiles. + See: https://github.com/timothycrosley/isort/issues/970. + """ + assert isort.code("import a", profile="example") == "import a\n" # shared profile + assert isort.code("import a", profile="black") == "import a\n" # bundled profile + with pytest.raises(exceptions.ProfileDoesNotExist): + assert isort.code("import a", profile="madeupfake") == "import a\n" # non-existent profile