Skip to content

Commit

Permalink
first fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Feb 26, 2025
1 parent f7034c7 commit b726cba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
14 changes: 7 additions & 7 deletions tests/test_pixi_to_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ def test_extract_name_version_from_url() -> None:
assert name_tar == "python"
assert version_tar == "3.13.2"

# Test package with no version
url_no_version = "https://conda.anaconda.org/conda-forge/osx-arm64/python.conda"
name_no_version, version_no_version = ptcl.extract_name_version_from_url(
url_no_version,
# Test with dash
url_with_dash = "https://conda.anaconda.org/conda-forge/osx-arm64/ca-certificates-2025.1.31-hf0a4a13_0.conda"
name_with_dash, version_with_dash = ptcl.extract_name_version_from_url(
url_with_dash,
)
assert name_no_version == "python"
assert version_no_version == ""
assert name_with_dash == "ca-certificates"
assert version_with_dash == "2025.1.31"


def test_parse_dependencies_from_repodata() -> None:
Expand Down Expand Up @@ -274,7 +274,7 @@ def test_create_conda_package_entry_fallback() -> None:
"""Test creating a conda package entry using fallback."""
url = "https://conda.anaconda.org/conda-forge/osx-arm64/python-3.13.2-hfd29fff_1_cp313t.conda"
package_info = {
"depends": {"bzip2": ">=1.0.8,<2.0a0", "libexpat": ">=2.6.4,<3.0a0"},
"depends": ["bzip2 >=1.0.8,<2.0a0", "libexpat >=2.6.4,<3.0a0"],
"md5": "9d0ae3f3e43c192a992827c0abffe284",
"sha256": "a64466b8f65b77604c3c87092c65d9e51e7db44b11eaa6c469894f0b88b1af5a",
}
Expand Down
15 changes: 6 additions & 9 deletions unidep/pixi_to_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,7 @@ def extract_name_version_from_url(url: str) -> tuple[str, str]:
filename_no_ext = filename

Check warning on line 164 in unidep/pixi_to_conda_lock.py

View check run for this annotation

Codecov / codecov/patch

unidep/pixi_to_conda_lock.py#L164

Added line #L164 was not covered by tests

# Split by hyphens to separate name, version, and build
parts = filename_no_ext.split("-")

# For simplicity in the fallback, assume the first part is the name
# and the second part is the version
name = parts[0]
version = parts[1] if len(parts) > 1 else ""
name, version, _build_string = filename_no_ext.rsplit("-", 2)

logging.debug("Extracted name: %s, version: %s", name, version)
return name, version
Expand Down Expand Up @@ -230,13 +225,15 @@ def create_conda_package_entry_fallback(
logging.debug("Creating conda package entry using fallback for: %s", url)
platform = extract_platform_from_url(url)
name, version = extract_name_version_from_url(url)

print(package_info)
package_entry = {
"name": name,
"version": version,
"manager": "conda",
"platform": platform,
"dependencies": dict(package_info.get("depends", {}).items()),
"dependencies": parse_dependencies_from_repodata(
package_info.get("depends", []),
),
"url": url,
"hash": {
"md5": package_info.get("md5", ""),
Expand Down Expand Up @@ -365,7 +362,7 @@ def process_conda_packages(
base_entry = create_conda_package_entry(url, repodata_info)
else:
# Fallback to parsing the URL if repodata doesn't have the package
logging.debug("Repodata not found, using fallback method")
logging.warning("Repodata not found, using fallback method")
base_entry = create_conda_package_entry_fallback(url, package_info)

Check warning on line 366 in unidep/pixi_to_conda_lock.py

View check run for this annotation

Codecov / codecov/patch

unidep/pixi_to_conda_lock.py#L365-L366

Added lines #L365 - L366 were not covered by tests

# If the package is noarch, replicate it for each platform.
Expand Down

0 comments on commit b726cba

Please sign in to comment.