Skip to content

Commit

Permalink
feat: assume style has a .toml extension when it's missing
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Mar 11, 2019
1 parent 0e4cedd commit 5a584ac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
3 changes: 2 additions & 1 deletion flake8_nitpick/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
PROJECT_NAME = "flake8-nitpick"
ERROR_PREFIX = "NIP"
LOG_ROOT = PROJECT_NAME.replace("-", ".")
NITPICK_STYLE_TOML = "nitpick-style.toml"
TOML_EXTENSION = ".toml"
NITPICK_STYLE_TOML = f"nitpick-style{TOML_EXTENSION}"
DEFAULT_NITPICK_STYLE_URL = f"https://raw.githubusercontent.com/andreoliwa/flake8-nitpick/master/{NITPICK_STYLE_TOML}"
ROOT_PYTHON_FILES = ("setup.py", "manage.py", "autoapp.py")
ROOT_FILES = ("requirements*.txt", "Pipfile") + ROOT_PYTHON_FILES
Expand Down
7 changes: 6 additions & 1 deletion flake8_nitpick/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
LOG_ROOT,
NITPICK_STYLE_TOML,
NITPICK_STYLES_INCLUDE_JMEX,
TOML_EXTENSION,
UNIQUE_SEPARATOR,
)
from flake8_nitpick.files.pyproject_toml import PyProjectTomlFile
Expand Down Expand Up @@ -67,8 +68,12 @@ def include_multiple_styles(self, chosen_styles: StrOrList) -> None:
self.include_multiple_styles(sub_styles)

def get_style_path(self, style_uri: str) -> Optional[Path]:
"""Get the style path from the URI."""
"""Get the style path from the URI. Add the .toml extension if it's missing."""
clean_style_uri = style_uri.strip()

if clean_style_uri and not clean_style_uri.endswith(TOML_EXTENSION):
clean_style_uri += TOML_EXTENSION

style_path = None
if is_url(clean_style_uri) or is_url(self._first_full_path):
style_path = self.fetch_style_from_url(clean_style_uri)
Expand Down
48 changes: 24 additions & 24 deletions tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_multiple_styles_overriding_values(request):
).pyproject_toml(
"""
[tool.nitpick]
style = ["isort1.toml", "styles/isort2.toml", "flake8.toml", "black.toml"]
style = ["isort1", "styles/isort2", "flake8.toml", "black"]
[tool.black]
something = 22
"""
Expand Down Expand Up @@ -115,9 +115,9 @@ def test_include_styles_overriding_values(request):
""",
).pyproject_toml(
"""
[tool.nitpick]
style = "isort1.toml"
"""
[tool.nitpick]
style = "isort1"
"""
).lint().assert_errors_contain(
"""
NIP311 File pyproject.toml has missing values. Use this:
Expand Down Expand Up @@ -148,26 +148,26 @@ def test_minimum_version(mocked_version, request):
.named_style(
"parent",
"""
[nitpick.styles]
include = "child.toml"
["pyproject.toml".tool.black]
line-length = 100
""",
[nitpick.styles]
include = "child.toml"
["pyproject.toml".tool.black]
line-length = 100
""",
)
.named_style(
"child",
"""
[nitpick]
minimum_version = "1.0"
""",
[nitpick]
minimum_version = "1.0"
""",
)
.pyproject_toml(
"""
[tool.nitpick]
style = "parent.toml"
[tool.black]
line-length = 100
"""
[tool.nitpick]
style = "parent"
[tool.black]
line-length = 100
"""
)
.lint()
.assert_single_error(
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_relative_and_other_root_dirs(request):
project.pyproject_toml(
f"""
[tool.nitpick]
style = ["{another_dir}/main.toml", "{another_dir}/styles/black.toml"]
style = ["{another_dir}/main", "{another_dir}/styles/black"]
{common_pyproject}
"""
).lint().assert_single_error(expected_error)
Expand All @@ -237,7 +237,7 @@ def test_relative_and_other_root_dirs(request):
project.pyproject_toml(
f"""
[tool.nitpick]
style = ["{another_dir}/main.toml", "styles/black.toml"]
style = ["{another_dir}/main", "styles/black.toml"]
{common_pyproject}
"""
).lint().assert_single_error(expected_error)
Expand All @@ -246,7 +246,7 @@ def test_relative_and_other_root_dirs(request):
project.pyproject_toml(
f"""
[tool.nitpick]
style = ["{another_dir}/styles/black.toml", "../poetry.toml"]
style = ["{another_dir}/styles/black", "../poetry"]
{common_pyproject}
"""
).lint().assert_single_error(
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_symlink_subdir(request):
).pyproject_toml(
f"""
[tool.nitpick]
style = "symlinked-style.toml"
style = "symlinked-style"
"""
).lint().assert_single_error(
"""
Expand Down Expand Up @@ -333,7 +333,7 @@ def test_relative_style_on_urls(request):
project.pyproject_toml(
f"""
[tool.nitpick]
style = ["{base_url}/main.toml", "{base_url}/styles/black.toml"]
style = ["{base_url}/main", "{base_url}/styles/black.toml"]
{common_pyproject}
"""
).lint().assert_single_error(expected_error)
Expand All @@ -342,7 +342,7 @@ def test_relative_style_on_urls(request):
project.pyproject_toml(
f"""
[tool.nitpick]
style = ["{base_url}/main.toml", "styles/black.toml"]
style = ["{base_url}/main.toml", "styles/black"]
{common_pyproject}
"""
).lint().assert_single_error(expected_error)
Expand All @@ -351,7 +351,7 @@ def test_relative_style_on_urls(request):
project.pyproject_toml(
f"""
[tool.nitpick]
style = ["{base_url}/styles/black.toml", "../poetry.toml"]
style = ["{base_url}/styles/black.toml", "../poetry"]
{common_pyproject}
"""
).lint().assert_single_error(
Expand Down

0 comments on commit 5a584ac

Please sign in to comment.