diff --git a/grayskull/strategy/pypi.py b/grayskull/strategy/pypi.py index 1bed893b7..8fb43d114 100644 --- a/grayskull/strategy/pypi.py +++ b/grayskull/strategy/pypi.py @@ -347,9 +347,14 @@ def get_metadata(recipe, config) -> dict: """Method responsible to get the whole metadata available. It will merge metadata from multiple sources (pypi, setup.py, setup.cfg) """ - name = config.name sdist_metadata, pypi_metadata = get_origin_wise_metadata(config) metadata = merge_pypi_sdist_metadata(pypi_metadata, sdist_metadata, config) + if config.from_local_sdist: + # Overwrite package name from sdist filename with name from metadata + # sdist filename is normalized by setuptools since version 69.3.0 + # See https://github.com/pypa/setuptools/issues/3593 + config.name = metadata["name"] + name = config.name log.debug(f"Data merged from pypi, setup.cfg and setup.py: {metadata}") if metadata.get("scripts") is not None: config.is_arch = True @@ -505,6 +510,9 @@ def update_recipe(recipe: Recipe, config: Configuration, all_sections: List[str] if section == "package": package_metadata = dict(metadata[section]) if package_metadata["name"].lower() == config.name.lower(): + if config.from_local_sdist: + # Initial name set in the recipe came from the sdist filename + set_global_jinja_var(recipe, "name", package_metadata["name"]) package_metadata.pop("name") else: package_metadata["name"] = package_metadata["name"].replace( diff --git a/tests/conftest.py b/tests/conftest.py index 9556de8fc..429f65043 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,7 +15,9 @@ def data_dir() -> str: @fixture(scope="session") def pkg_pytest(tmpdir_factory) -> str: folder = tmpdir_factory.mktemp("test-download-pkg") - dest_pkg = str(folder / "PYTEST-PKG.tar.gz") + # Use different package name and version for the sdist archive on purpose + # Correct info should be extracted from the metadata and not filename + dest_pkg = str(folder / "PYTEST-PKG-1.0.0.tar.gz") download_sdist_pkg( "https://pypi.io/packages/source/p/pytest/pytest-5.3.5.tar.gz", dest_pkg ) diff --git a/tests/test_pypi.py b/tests/test_pypi.py index 1564ee152..2b04ce725 100644 --- a/tests/test_pypi.py +++ b/tests/test_pypi.py @@ -6,6 +6,7 @@ import pytest from colorama import Fore, Style +from souschef.jinja_expression import get_global_jinja_var from souschef.recipe import Recipe from grayskull.base.factory import GrayskullFactory @@ -1257,6 +1258,8 @@ def test_create_recipe_from_local_sdist(pkg_pytest): assert recipe["about"]["summary"] == "pytest: simple powerful testing with Python" assert recipe["about"]["license"] == "MIT" assert recipe["about"]["license_file"] == "LICENSE" + assert get_global_jinja_var(recipe, "name") == "pytest" + assert get_global_jinja_var(recipe, "version") == "5.3.5" @patch("grayskull.strategy.py_base.get_all_toml_info", return_value={})