Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ni_python_styleguide/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@ def _read_pyproject_toml(ctx, param, value):

def _get_application_import_names(pyproject):
"""Returns the application package name the config."""
# Otherwise override with what was specified
# Use the tool-specific import names if specified
app_name = (
pyproject.get("tool", {})
.get("ni-python-styleguide", {})
.get("application-import-names", "")
)

# Allow the poetry name as a fallback
# Next fall back to project.import-names
if not app_name:
import_names = pyproject.get("project", {}).get("import-names", [])
app_name = ",".join(import_names)

# Next fall back to project.name (replace hyphens)
if not app_name:
app_name = pyproject.get("project", {}).get("name", "").replace("-", "_")

# Next fall back to tool.poetry.name (replace hyphens)
if not app_name:
app_name = pyproject.get("tool", {}).get("poetry", {}).get("name", "").replace("-", "_")

Expand Down
44 changes: 44 additions & 0 deletions tests/test_cli/test_application_import_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Tests for the "_get_application_import_names" method of _cli.py."""

import pytest

from ni_python_styleguide._cli import _get_application_import_names


@pytest.mark.parametrize(
"pyproject_obj, expected_names",
[
(
{
"tool": {
"ni-python-styleguide": {"application-import-names": "ain1,ain2"},
"poetry": {"name": "tool.poetry.name"},
},
"project": {
"import-names": ["import-names1", "import-names2"],
"name": "project.name",
},
},
"ain1,ain2,tests",
),
(
{
"tool": {"poetry": {"name": "tool.poetry.name"}},
"project": {
"import-names": ["import-names1", "import-names2"],
"name": "project.name",
},
},
"import-names1,import-names2,tests",
),
(
{"tool": {"poetry": {"name": "tool.poetry.name"}}, "project": {"name": "project.name"}},
"project.name,tests",
),
({"tool": {"poetry": {"name": "tool.poetry.name"}}}, "tool.poetry.name,tests"),
],
)
def test_get_application_import_names_returns_valid_data(pyproject_obj, expected_names):
"""Tests that _get_application_import_names returns valid data."""
result = _get_application_import_names(pyproject_obj)
assert result == expected_names
Loading