Skip to content

Commit

Permalink
Ignore licenses in hidden directories
Browse files Browse the repository at this point in the history
When searching for licenses, files in hidden directories (like .eggs/LICENSE) were
excluded but not the directories under (.eggs/foo/)..

Don't just hope over hidden directories but remove them from the list
of directories to search.

Fix conda#398
  • Loading branch information
beenje committed Oct 9, 2022
1 parent 6221399 commit 77d9be2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 2 additions & 3 deletions grayskull/license/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def _get_api_github_url(github_url: str, version: Optional[str] = None) -> str:

def search_license_folder(
path: Union[str, Path], default: Optional[str] = None
) -> Optional[ShortLicense]:
) -> list[ShortLicense]:
"""Search for the license in the given folder
:param path: Sdist folder
Expand All @@ -283,12 +283,11 @@ def search_license_folder(
)
all_licences = []
for folder_path, dirnames, filenames in os.walk(str(path)):
if os.path.basename(folder_path).startswith("."):
continue
dirnames[:] = [
folder
for folder in dirnames
if folder not in ("doc", "theme", "themes", "docs")
and not folder.startswith(".")
]
for one_file in filenames:
if re_search.match(one_file):
Expand Down
15 changes: 15 additions & 0 deletions tests/license/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ def test_search_license_folder(pkg_pytest):
assert license_folder.name == "MIT"


def test_search_license_folder_hidden_folder(tmp_path, license_pytest_5_3_1):
d = tmp_path / "mypackage"
d.mkdir()
license_path = d / "LICENSE"
license_path.write_text(license_pytest_5_3_1)
# Following licences under hidden directory should be ignored
egg_info = d / ".eggs" / "setuptools_scm-7.0.5-py3.10.egg" / "EGG-INFO"
egg_info.mkdir(parents=True)
for lic in (d / ".eggs" / "LICENSE", egg_info / "LICENSE"):
lic.write_text(license_pytest_5_3_1)
all_licenses = search_license_folder(tmp_path)
assert len(all_licenses) == 1
assert all_licenses[0].path == str(license_path)


@pytest.mark.xfail(
reason="This test may fail because github has limitation regarding the"
" number of requisitions we can do to their api."
Expand Down

0 comments on commit 77d9be2

Please sign in to comment.