Skip to content

Commit

Permalink
Don't warn when encountering non-Python files with multiple dots
Browse files Browse the repository at this point in the history
  • Loading branch information
seddonym committed Jan 8, 2024
1 parent 6a4b0f2 commit f374bc3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Unreleased
----------

* Allow configuring sibling layer independence.
* Fix bug where a warning would be logged if a non-Python file with multiple dots
in the filename was encountered.

3.1 (2023-10-13)
----------------
Expand Down
5 changes: 4 additions & 1 deletion src/grimp/adaptors/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def _is_python_file(self, filename: str, dirpath: str) -> bool:
if filename.startswith("."):
return False

if not filename.endswith(".py"):
return False

# Ignore files like some.module.py.
if filename.count(".") > 1:
logger.warning(
Expand All @@ -82,7 +85,7 @@ def _is_python_file(self, filename: str, dirpath: str) -> bool:
)
return False

return filename.endswith(".py")
return True

def _module_name_from_filename(
self, package_name: str, filename_and_path: str, package_directory: str
Expand Down
29 changes: 20 additions & 9 deletions tests/unit/adaptors/test_modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from grimp.application.ports.modulefinder import FoundPackage, ModuleFile
from grimp.domain.valueobjects import Module
from tests.adaptors.filesystem import DEFAULT_MTIME, FakeFileSystem
import pytest


def test_happy_path():
Expand Down Expand Up @@ -123,18 +124,25 @@ def test_ignores_orphaned_python_files():
)


def test_ignores_dotted_python_files(caplog):
@pytest.mark.parametrize(
"extension, should_warn",
(
("py", True),
("txt", False), # Anything other than .py.
),
)
def test_ignores_dotted_python_files(extension, should_warn, caplog):
# Python files containing dots (other than the one before .py) should not be discovered.
module_finder = ModuleFinder()

file_system = FakeFileSystem(
contents="""
contents=f"""
/path/to/mypackage/
__init__.py
foo.py
bar/
__init__.py
baz.dotted.py
baz.dotted.{extension}
"""
)

Expand All @@ -155,12 +163,15 @@ def test_ignores_dotted_python_files(caplog):
}
),
)
assert caplog.messages == [
(
"Warning: skipping module with too many dots in the name: "
"/path/to/mypackage/bar/baz.dotted.py"
)
]
if should_warn:
assert caplog.messages == [
(
"Warning: skipping module with too many dots in the name: "
f"/path/to/mypackage/bar/baz.dotted.{extension}"
)
]
else:
assert caplog.messages == []


def test_ignores_hidden_directories():
Expand Down

0 comments on commit f374bc3

Please sign in to comment.