From 3780b25f7e4b6d1f339d5fa51b69aea31bf21f9b Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Mon, 25 Mar 2024 11:05:53 +0100 Subject: [PATCH] feat: editable pypi packages --- crates/rattler_lock/src/lib.rs | 5 +++++ crates/rattler_lock/src/parse/v3.rs | 1 + crates/rattler_lock/src/pypi.rs | 9 +++++++++ ...r_lock__test__v4__path-based-lock.yml.snap | 3 ++- py-rattler/rattler/lock/pypi.py | 20 +++++++++++++++++++ py-rattler/src/lock/mod.rs | 5 +++++ test-data/conda-lock/v4/path-based-lock.yml | 1 + 7 files changed, 43 insertions(+), 1 deletion(-) diff --git a/crates/rattler_lock/src/lib.rs b/crates/rattler_lock/src/lib.rs index dd5e7ffc2..840f40644 100644 --- a/crates/rattler_lock/src/lib.rs +++ b/crates/rattler_lock/src/lib.rs @@ -560,6 +560,11 @@ impl PypiPackage { pub fn satisfies(&self, spec: &Requirement) -> bool { self.package_data().satisfies(spec) } + + /// Returns true if this package should be installed in "editable" mode. + pub fn is_editable(&self) -> bool { + self.package_data().editable + } } /// A helper struct to group package and environment data together. diff --git a/crates/rattler_lock/src/parse/v3.rs b/crates/rattler_lock/src/parse/v3.rs index 13932dc02..db6638785 100644 --- a/crates/rattler_lock/src/parse/v3.rs +++ b/crates/rattler_lock/src/parse/v3.rs @@ -185,6 +185,7 @@ pub fn parse_v3_or_lower(document: serde_yaml::Value) -> Result, + + /// Whether the projects should be installed in editable mode or not. + #[serde(default, skip_serializing_if = "should_skip_serializing_editable")] + pub editable: bool, } /// Additional runtime configuration of a package. Multiple environments/platforms might refer to @@ -77,3 +81,8 @@ impl PypiPackageData { true } } + +/// Used in `skip_serializing_if` to skip serializing the `editable` field if it is `false`. +fn should_skip_serializing_editable(editable: &bool) -> bool { + !*editable +} diff --git a/crates/rattler_lock/src/snapshots/rattler_lock__test__v4__path-based-lock.yml.snap b/crates/rattler_lock/src/snapshots/rattler_lock__test__v4__path-based-lock.yml.snap index 6c70cdb0a..6297d4401 100644 --- a/crates/rattler_lock/src/snapshots/rattler_lock__test__v4__path-based-lock.yml.snap +++ b/crates/rattler_lock/src/snapshots/rattler_lock__test__v4__path-based-lock.yml.snap @@ -1,6 +1,6 @@ --- source: crates/rattler_lock/src/lib.rs -assertion_line: 597 +assertion_line: 602 expression: conda_lock --- version: 4 @@ -251,6 +251,7 @@ packages: name: minimal-project version: "0.1" path: "./minimal_project" + editable: true - kind: conda name: openssl version: 3.2.1 diff --git a/py-rattler/rattler/lock/pypi.py b/py-rattler/rattler/lock/pypi.py index a5ed63fd6..740a2acc5 100644 --- a/py-rattler/rattler/lock/pypi.py +++ b/py-rattler/rattler/lock/pypi.py @@ -151,6 +151,26 @@ def requires_python(self) -> Optional[str]: """ return self._data.requires_python + @property + def is_editable(self) -> bool: + """ + Whether the package should be installed in editable mode or not. + + Examples + -------- + ```python + >>> from rattler import LockFile, Platform + >>> lock_file = LockFile.from_path("../test-data/test.lock") + >>> env = lock_file.default_environment() + >>> pypi_packages = env.pypi_packages() + >>> data = pypi_packages[Platform("osx-arm64")][0][0] + >>> data.is_editable + '>=3.7.0' + >>> + ``` + """ + return self._data.is_editable + @classmethod def _from_py_pypi_package_data(cls, pkg_data: PyPypiPackageData) -> PypiPackageData: """ diff --git a/py-rattler/src/lock/mod.rs b/py-rattler/src/lock/mod.rs index 9534ec228..f8c5989d6 100644 --- a/py-rattler/src/lock/mod.rs +++ b/py-rattler/src/lock/mod.rs @@ -341,6 +341,11 @@ impl PyLockedPackage { self.inner.url_or_path().to_string() } + #[getter] + pub fn is_editable(&self) -> bool { + self.inner.is_editable() + } + pub fn as_conda(&self) -> Option { if let Some(pkg) = self.inner.as_conda() { return Some(Into::into(RepoDataRecord { diff --git a/test-data/conda-lock/v4/path-based-lock.yml b/test-data/conda-lock/v4/path-based-lock.yml index 4c8217753..24ee8c851 100644 --- a/test-data/conda-lock/v4/path-based-lock.yml +++ b/test-data/conda-lock/v4/path-based-lock.yml @@ -246,6 +246,7 @@ packages: name: minimal-project version: '0.1' path: ./minimal_project + editable: true - kind: conda name: openssl version: 3.2.1