Skip to content

dependatool: Ignore empty go.mod files #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pypi: https://pypi.org/project/aio.run.runner

#### [dependatool](dependatool)

version: 0.2.3.dev0
version: 0.2.3

pypi: https://pypi.org/project/dependatool

Expand Down
2 changes: 1 addition & 1 deletion dependatool/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.3-dev
0.2.3
3 changes: 2 additions & 1 deletion dependatool/dependatool/gomod/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def config(self) -> set:

@async_property(cache=True)
async def gomodfile_dirs(self) -> set[str]:
"""Set of found directories in the repo containing gomodfile.txt."""
"""Set of found directories in the repo containing a go.mod file."""
return set(
os.path.dirname(f"/{f}")
for f in await self.checker.directory.files
Expand Down Expand Up @@ -68,6 +68,7 @@ def dir_matches(self, path: str) -> bool:
parent directory is excluded."""
return (
bool(self.gomodfile_filename.match(os.path.basename(path)))
and os.stat(path).st_size > 1
and not self.checker.ignored_dirs.match(
os.path.dirname(f"/{path}")))

Expand Down
18 changes: 15 additions & 3 deletions dependatool/tests/test_gomod_abstract_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ def test_gomod_abstract_check_errors(patches):

@pytest.mark.parametrize("name_matches", [True, False])
@pytest.mark.parametrize("dir_ignored", [True, False])
def test_gomod_abstract_check_dir_matches(patches, name_matches, dir_ignored):
@pytest.mark.parametrize("size", [0, 1, 2, 3])
def test_gomod_abstract_check_dir_matches(
patches, name_matches, dir_ignored, size):
checker = MagicMock()
check = DummyDependatoolGomodCheck(checker)
patched = patches(
Expand All @@ -175,13 +177,16 @@ def test_gomod_abstract_check_dir_matches(patches, name_matches, dir_ignored):

with patched as (m_bool, m_os, m_filename):
m_bool.return_value = name_matches
m_os.stat.return_value.st_size = size
checker.ignored_dirs.match.return_value = (
True
if dir_ignored
else False)
assert (
check.dir_matches(path)
== (name_matches and not dir_ignored))
== (name_matches
and size > 1
and not dir_ignored))

assert m_os.path.basename.call_args == [(path, ), {}]
assert (
Expand All @@ -192,7 +197,14 @@ def test_gomod_abstract_check_dir_matches(patches, name_matches, dir_ignored):
== [(m_os.path.basename.return_value, ), {}])
if not name_matches:
assert not checker.ignored_dirs.match.called
assert not checker.path.parent.relative_to.called
assert not m_os.path.dirname.called
assert not m_os.stat.called
return
assert (
m_os.stat.call_args
== [(path, ), {}])
if size < 2:
assert not checker.ignored_dirs.match.called
assert not m_os.path.dirname.called
return
assert (
Expand Down