Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use correct dependency location for pixi upgrade #2472

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extend test and make sure that python isn't added to pyproject.toml
Hofer-Julian committed Dec 2, 2024
commit 08855a22ef1be59849011e693bd6b0d680802b68
2 changes: 1 addition & 1 deletion crates/pixi_manifest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ pub use features_ext::FeaturesExt;
pub use has_features_iter::HasFeaturesIter;
pub use has_manifest_ref::HasManifestRef;
use itertools::Itertools;
pub use manifests::{Manifest, ManifestKind, WorkspaceManifest};
pub use manifests::{Manifest, ManifestKind, ManifestSource, WorkspaceManifest};
use miette::Diagnostic;
pub use preview::{KnownPreviewFeature, Preview, PreviewFeature};
pub use pypi::pypi_requirement::PyPiRequirement;
16 changes: 16 additions & 0 deletions src/cli/upgrade.rs
Original file line number Diff line number Diff line change
@@ -195,6 +195,22 @@ fn parse_specs(
None
}
})
// Only upgrade in pyproject.toml if it is explicitly mentioned in `tool.pixi.dependencies.python`
.filter(|(name, _)| {
if name.as_normalized() == "python" {
if let pixi_manifest::ManifestSource::PyProjectToml(document) =
project.manifest.document.clone()
{
if document
.get_nested_table("[tool.pixi.dependencies.python]")
.is_err()
{
return false;
}
}
}
true
})
.collect();
let pypi_deps = pypi_deps_iter
// Don't upgrade excluded packages
10 changes: 10 additions & 0 deletions tests/integration_python/common.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,16 @@
PIXI_VERSION = "0.38.0"


ALL_PLATFORMS = '["linux-64", "osx-64", "win-64", "linux-ppc64le", "linux-aarch64"]'

EMPTY_BOILERPLATE_PROJECT = f"""
[project]
name = "test"
channels = []
platforms = {ALL_PLATFORMS}
"""


class ExitCode(IntEnum):
SUCCESS = 0
FAILURE = 1
30 changes: 17 additions & 13 deletions tests/integration_python/test_main_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from pathlib import Path
from .common import verify_cli_command, ExitCode, PIXI_VERSION

from .common import verify_cli_command, ExitCode, PIXI_VERSION, ALL_PLATFORMS
import tomllib
import json
import pytest
@@ -529,19 +530,19 @@ def test_upgrade_pypi_and_conda_package(pixi: Path, tmp_path: Path) -> None:


@pytest.mark.slow
def test_upgrade_dependency_location(pixi: Path, tmp_path: Path) -> None:
def test_upgrade_dependency_location_pixi(pixi: Path, tmp_path: Path) -> None:
# Test based on https://github.com/prefix-dev/pixi/issues/2470
# Making sure pixi places the upgraded package in the correct location
manifest_path = tmp_path / "pyproject.toml"
pyproject = """
pyproject = f"""
[project]
dependencies = []
name = "test-upgrade"
requires-python = ">= 3.11"
dependencies = ["numpy==1.*"]
requires-python = ">3.10"

[tool.pixi.project]
channels = ["conda-forge"]
platforms = ["linux-64"]
platforms = {ALL_PLATFORMS}

[tool.pixi.pypi-dependencies]
polars = "==0.*"
@@ -555,21 +556,24 @@ def test_upgrade_dependency_location(pixi: Path, tmp_path: Path) -> None:
stderr_contains=["polars"],
)
parsed_manifest = tomllib.loads(manifest_path.read_text())
# Check that the requires-python is modified
requires_python = parsed_manifest["project"]["requires-python"]
assert "3.11" not in requires_python

# Check that `tool.pixi.dependencies.python` doesn't exist
# Check that `tool.pixi.dependencies.python` isn't added
assert "python" not in parsed_manifest.get("tool", {}).get("pixi", {}).get("dependencies", {})

# Check that the pypi-dependency is upgraded
# Check that the pypi-dependencies are upgraded
polars_pypi = parsed_manifest["tool"]["pixi"]["pypi-dependencies"]["polars"]
assert polars_pypi
assert polars_pypi != "==0.*"

# Check that the pypi-dependency doesn't exist in the project dependencies
# Check that project.dependencies are upgraded
numpy_pypi = parsed_manifest["project"]["dependencies"][0]
assert numpy_pypi != "==1.*"

# Check that the polars doesn't exist in the project dependencies
assert "polars" not in parsed_manifest["project"]["dependencies"]

# Check that numpy doesn't exist in the pypi-dependencies
assert "numpy" not in parsed_manifest["tool"]["pixi"]["pypi-dependencies"]


def test_upgrade_keep_info(pixi: Path, tmp_path: Path, multiple_versions_channel_1: str) -> None:
manifest_path = tmp_path / "pixi.toml"
11 changes: 1 addition & 10 deletions tests/integration_python/test_run_cli.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import json
from pathlib import Path
from .common import verify_cli_command, ExitCode, default_env_path
from .common import EMPTY_BOILERPLATE_PROJECT, verify_cli_command, ExitCode, default_env_path
import tempfile
import os

ALL_PLATFORMS = '["linux-64", "osx-64", "win-64", "linux-ppc64le", "linux-aarch64"]'

EMPTY_BOILERPLATE_PROJECT = f"""
[project]
name = "test"
channels = []
platforms = {ALL_PLATFORMS}
"""


def test_run_in_shell_environment(pixi: Path, tmp_path: Path) -> None:
manifest = tmp_path.joinpath("pixi.toml")