Skip to content

Commit fa0b1a3

Browse files
authored
Fix package name based on local sdist archive (#536)
* Add test on local sdist package name * Fix package name based on local sdist archive When using a local sdist as source, the package name of the conda recipe was based on the sdist filename. This used to be the same but since setuptools 69.3.0, the sdist filename is now normalized. For example, if a package name contains a dash, it's converted to underscore. The package name should be extracted from the metadata and not the sdist filename.
1 parent 32a7e39 commit fa0b1a3

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

grayskull/strategy/pypi.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,14 @@ def get_metadata(recipe, config) -> dict:
347347
"""Method responsible to get the whole metadata available. It will
348348
merge metadata from multiple sources (pypi, setup.py, setup.cfg)
349349
"""
350-
name = config.name
351350
sdist_metadata, pypi_metadata = get_origin_wise_metadata(config)
352351
metadata = merge_pypi_sdist_metadata(pypi_metadata, sdist_metadata, config)
352+
if config.from_local_sdist:
353+
# Overwrite package name from sdist filename with name from metadata
354+
# sdist filename is normalized by setuptools since version 69.3.0
355+
# See https://github.com/pypa/setuptools/issues/3593
356+
config.name = metadata["name"]
357+
name = config.name
353358
log.debug(f"Data merged from pypi, setup.cfg and setup.py: {metadata}")
354359
if metadata.get("scripts") is not None:
355360
config.is_arch = True
@@ -505,6 +510,9 @@ def update_recipe(recipe: Recipe, config: Configuration, all_sections: List[str]
505510
if section == "package":
506511
package_metadata = dict(metadata[section])
507512
if package_metadata["name"].lower() == config.name.lower():
513+
if config.from_local_sdist:
514+
# Initial name set in the recipe came from the sdist filename
515+
set_global_jinja_var(recipe, "name", package_metadata["name"])
508516
package_metadata.pop("name")
509517
else:
510518
package_metadata["name"] = package_metadata["name"].replace(

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def data_dir() -> str:
1515
@fixture(scope="session")
1616
def pkg_pytest(tmpdir_factory) -> str:
1717
folder = tmpdir_factory.mktemp("test-download-pkg")
18-
dest_pkg = str(folder / "PYTEST-PKG.tar.gz")
18+
# Use different package name and version for the sdist archive on purpose
19+
# Correct info should be extracted from the metadata and not filename
20+
dest_pkg = str(folder / "PYTEST-PKG-1.0.0.tar.gz")
1921
download_sdist_pkg(
2022
"https://pypi.io/packages/source/p/pytest/pytest-5.3.5.tar.gz", dest_pkg
2123
)

tests/test_pypi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import pytest
88
from colorama import Fore, Style
9+
from souschef.jinja_expression import get_global_jinja_var
910
from souschef.recipe import Recipe
1011

1112
from grayskull.base.factory import GrayskullFactory
@@ -1257,6 +1258,8 @@ def test_create_recipe_from_local_sdist(pkg_pytest):
12571258
assert recipe["about"]["summary"] == "pytest: simple powerful testing with Python"
12581259
assert recipe["about"]["license"] == "MIT"
12591260
assert recipe["about"]["license_file"] == "LICENSE"
1261+
assert get_global_jinja_var(recipe, "name") == "pytest"
1262+
assert get_global_jinja_var(recipe, "version") == "5.3.5"
12601263

12611264

12621265
@patch("grayskull.strategy.py_base.get_all_toml_info", return_value={})

0 commit comments

Comments
 (0)