Skip to content

Commit f79db6e

Browse files
Merge branch 'main' into pre-commit-ci-update-config
2 parents 7179abc + 391b7cc commit f79db6e

File tree

6 files changed

+71
-23
lines changed

6 files changed

+71
-23
lines changed

grayskull/license/discovery.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ def get_all_licenses_from_spdx() -> List:
6262
]
6363

6464

65+
def _match_scrambled_exact(candidate, licenses) -> str | None:
66+
"""
67+
Return license with rearranged word order only.
68+
69+
Fancy scorer confuses BSD-3-Clause with DEC-3-Clause.
70+
"""
71+
bag = set(re.findall(r"\w+", candidate.lower()))
72+
for license in licenses:
73+
if bag == set(re.findall(r"\w+", license.lower())):
74+
return license
75+
return None
76+
77+
6578
def match_license(name: str) -> dict:
6679
"""Match if the given license name matches any license present on
6780
spdx.org
@@ -75,11 +88,16 @@ def match_license(name: str) -> dict:
7588
name = re.sub(r"\s+license\s*", "", name.strip(), flags=re.IGNORECASE)
7689
name = name.strip()
7790

78-
best_matches = process.extract(
79-
name, _get_all_license_choice(all_licenses), scorer=partial_ratio
80-
)
81-
best_matches = process.extract(name, [lc for lc, *_ in best_matches])
82-
spdx_license = best_matches[0]
91+
exact_match = _match_scrambled_exact(name, _get_all_license_choice(all_licenses))
92+
if exact_match:
93+
best_matches = [(exact_match, 100, 0)]
94+
spdx_license = best_matches[0]
95+
else:
96+
best_matches = process.extract(
97+
name, _get_all_license_choice(all_licenses), scorer=partial_ratio
98+
)
99+
best_matches = process.extract(name, [lc for lc, *_ in best_matches])
100+
spdx_license = best_matches[0]
83101

84102
if spdx_license[1] < 100:
85103
# Prefer "-or-later" licenses over the "-only"

grayskull/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,10 @@ def generate_recipes_from_list(list_pkgs, args):
332332
args.output = pkg_name
333333
try:
334334
# TODO: Remove before 3.0 release
335-
if args.url_pypi_metadata_deprecated and args.url_pypi_metadata:
335+
if (
336+
args.url_pypi_metadata_deprecated
337+
and args.url_pypi_metadata != DEFAULT_PYPI_META_URL
338+
):
336339
raise RuntimeError(
337340
"--pypi-url is deprecated in favor of --pypi-url-metadata "
338341
+ "and may not be passed in conjunction with --pypi-url-metadata"

grayskull/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ def generate_recipe(
218218
logging.debug(f"Generating recipe on: {recipe_dir}")
219219
if not recipe_dir.is_dir():
220220
recipe_dir.mkdir()
221-
recipe_path = recipe_dir / "recipe.yaml" if use_v1_format else "meta.yaml"
221+
recipe_path = (
222+
recipe_dir / "recipe.yaml" if use_v1_format else recipe_dir / "meta.yaml"
223+
)
222224
recipe_folder = recipe_dir
223225
add_new_lines_after_section(recipe.yaml)
224226

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def pkg_pytest(tmpdir_factory) -> str:
1919
# Correct info should be extracted from the metadata and not filename
2020
dest_pkg = str(folder / "PYTEST-PKG-1.0.0.tar.gz")
2121
download_sdist_pkg(
22-
"https://pypi.io/packages/source/p/pytest/pytest-5.3.5.tar.gz", dest_pkg
22+
"https://pypi.org/packages/source/p/pytest/pytest-5.3.5.tar.gz", dest_pkg
2323
)
2424
shutil.unpack_archive(dest_pkg, str(folder))
2525
return dest_pkg

tests/data/poetry/langchain-expected.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package:
66
version: {{ version }}
77

88
source:
9-
url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/langchain-{{ version }}.tar.gz
9+
url: https://pypi.org/packages/source/{{ name[0] }}/{{ name }}/langchain-{{ version }}.tar.gz
1010
sha256: 95a93c966b1a2ff056c43870747aba1c39924c145179f0b8ffa27fef6a525610
1111

1212
build:

tests/test_pypi.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_get_extra_from_requires_dist():
179179
def dask_sdist_metadata():
180180
config = Configuration(name="dask")
181181
return get_sdist_metadata(
182-
"https://pypi.io/packages/source/d/dask/dask-2022.6.1.tar.gz",
182+
"https://pypi.org/packages/source/d/dask/dask-2022.6.1.tar.gz",
183183
config,
184184
)
185185

@@ -283,7 +283,7 @@ def test_compose_test_section_with_console_scripts():
283283
config = Configuration(name="pytest", version="7.1.2")
284284
metadata1 = get_pypi_metadata(config)
285285
metadata2 = get_sdist_metadata(
286-
"https://pypi.io/packages/source/p/pytest/pytest-7.1.2.tar.gz", config
286+
"https://pypi.org/packages/source/p/pytest/pytest-7.1.2.tar.gz", config
287287
)
288288
metadata = merge_pypi_sdist_metadata(metadata1, metadata2, config)
289289
test_requirements = []
@@ -604,7 +604,7 @@ def test_get_sha256_from_pypi_metadata():
604604
def test_injection_distutils(name):
605605
config = Configuration(name="hypothesis")
606606
data = get_sdist_metadata(
607-
"https://pypi.io/packages/source/h/hypothesis/hypothesis-5.5.1.tar.gz",
607+
"https://pypi.org/packages/source/h/hypothesis/hypothesis-5.5.1.tar.gz",
608608
config,
609609
)
610610
assert sorted(data["install_requires"]) == sorted(
@@ -621,7 +621,7 @@ def test_injection_distutils(name):
621621
def test_injection_distutils_pytest():
622622
config = Configuration(name="pytest", version="5.3.2")
623623
data = get_sdist_metadata(
624-
"https://pypi.io/packages/source/p/pytest/pytest-5.3.2.tar.gz", config
624+
"https://pypi.org/packages/source/p/pytest/pytest-5.3.2.tar.gz", config
625625
)
626626
assert sorted(data["install_requires"]) == sorted(
627627
[
@@ -644,31 +644,42 @@ def test_injection_distutils_pytest():
644644

645645

646646
def test_injection_distutils_compiler_gsw():
647-
config = Configuration(name="gsw", version="3.3.1")
647+
config = Configuration(name="gsw", version="3.6.19")
648648
data = get_sdist_metadata(
649-
"https://pypi.io/packages/source/g/gsw/gsw-3.3.1.tar.gz", config
649+
"https://pypi.org/packages/source/g/gsw/gsw-3.6.19.tar.gz", config
650650
)
651651
assert data.get("compilers") == ["c"]
652-
assert data["packages"] == ["gsw"]
652+
assert data["name"] == "gsw"
653653

654654

655655
def test_injection_distutils_setup_reqs_ensure_list():
656656
pkg_name, pkg_ver = "pyinstaller-hooks-contrib", "2020.7"
657657
config = Configuration(name=pkg_name, version=pkg_ver)
658658
data = get_sdist_metadata(
659-
f"https://pypi.io/packages/source/p/{pkg_name}/{pkg_name}-{pkg_ver}.tar.gz",
659+
f"https://pypi.org/packages/source/p/{pkg_name}/{pkg_name}-{pkg_ver}.tar.gz",
660660
config,
661661
)
662662
assert data.get("setup_requires") == ["setuptools >= 30.3.0"]
663663

664664

665665
def test_merge_pypi_sdist_metadata():
666-
config = Configuration(name="gsw", version="3.3.1")
666+
config = Configuration(name="gsw", version="3.6.19")
667667
pypi_metadata = get_pypi_metadata(config)
668668
sdist_metadata = get_sdist_metadata(pypi_metadata["sdist_url"], config)
669669
merged_data = merge_pypi_sdist_metadata(pypi_metadata, sdist_metadata, config)
670670
assert merged_data["compilers"] == ["c"]
671-
assert sorted(merged_data["setup_requires"]) == sorted(["numpy"])
671+
assert sorted(merged_data["setup_requires"]) == sorted(
672+
[
673+
"build",
674+
'numpy<3,>=2.0.0rc1; python_version >= "3.9"',
675+
'oldest-supported-numpy; python_version < "3.9"',
676+
"pip>9.0.1",
677+
"setuptools>=42",
678+
"setuptools_scm[toml]>=3.4",
679+
"wheel",
680+
"python >=3.8",
681+
]
682+
)
672683

673684

674685
def test_update_requirements_with_pin():
@@ -809,13 +820,22 @@ def test_download_pkg_sdist(pkg_pytest):
809820

810821
def test_ciso_recipe():
811822
recipe = GrayskullFactory.create_recipe(
812-
"pypi", Configuration(name="ciso", version="0.1.0")
823+
"pypi", Configuration(name="ciso", version="0.2.2")
813824
)
814825
assert sorted(recipe["requirements"]["host"]) == sorted(
815-
["cython", "numpy", "pip", "python"]
826+
[
827+
"cython >=3",
828+
"numpy >=2.0.0rc1",
829+
"oldest-supported-numpy",
830+
"pip",
831+
"python >=3.9",
832+
"setuptools >=41.2",
833+
"setuptools-scm",
834+
"wheel",
835+
]
816836
)
817837
assert sorted(recipe["requirements"]["run"]) == sorted(
818-
["cython", "python", "<{ pin_compatible('numpy') }}"]
838+
["<{ pin_compatible('numpy') }}", "oldest-supported-numpy", "python >=3.9"]
819839
)
820840
assert recipe["test"]["commands"] == ["pip check"]
821841
assert recipe["test"]["requires"] == ["pip"]
@@ -1112,7 +1132,7 @@ def test_recipe_extension():
11121132
recipe = create_python_recipe("azure-identity=1.3.1")[0]
11131133
assert (
11141134
recipe["source"]["url"]
1115-
== "https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/"
1135+
== "https://pypi.org/packages/source/{{ name[0] }}/{{ name }}/"
11161136
"azure-identity-{{ version }}.zip"
11171137
)
11181138

@@ -1288,6 +1308,11 @@ def test_notice_file_different_licence():
12881308
assert recipe["about"]["license"] in ["MIT AND Apache-2.0", "Apache-2.0 AND MIT"]
12891309

12901310

1311+
# Need to find another package for this test
1312+
@pytest.mark.skipif(
1313+
sys.version_info >= (3, 12),
1314+
reason="consolemd setup.py requires lower than python 3.12",
1315+
)
12911316
def test_console_script_toml_format():
12921317
recipe, _ = create_python_recipe("consolemd", version="0.5.1")
12931318
assert recipe["build"]["entry_points"] == ["consolemd = consolemd.cli:cli"]

0 commit comments

Comments
 (0)