Skip to content

Commit

Permalink
Fix package name based on local sdist archive (#536)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
beenje authored Aug 4, 2024
1 parent 32a7e39 commit fa0b1a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion grayskull/strategy/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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={})
Expand Down

0 comments on commit fa0b1a3

Please sign in to comment.