Skip to content

Commit

Permalink
feat: editable pypi packages
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Mar 25, 2024
1 parent d7dec3b commit 3780b25
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions crates/rattler_lock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions crates/rattler_lock/src/parse/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ pub fn parse_v3_or_lower(document: serde_yaml::Value) -> Result<LockFile, ParseC
requires_python: pkg.requires_python,
url_or_path: UrlOrPath::Url(pkg.url),
hash: pkg.hash,
editable: false,
})
.0;
EnvironmentPackageData::Pypi(
Expand Down
9 changes: 9 additions & 0 deletions crates/rattler_lock/src/pypi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub struct PypiPackageData {

/// The python version that this package requires.
pub requires_python: Option<VersionSpecifiers>,

/// 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
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/rattler_lock/src/lib.rs
assertion_line: 597
assertion_line: 602
expression: conda_lock
---
version: 4
Expand Down Expand Up @@ -251,6 +251,7 @@ packages:
name: minimal-project
version: "0.1"
path: "./minimal_project"
editable: true
- kind: conda
name: openssl
version: 3.2.1
Expand Down
20 changes: 20 additions & 0 deletions py-rattler/rattler/lock/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
5 changes: 5 additions & 0 deletions py-rattler/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PyRecord> {
if let Some(pkg) = self.inner.as_conda() {
return Some(Into::into(RepoDataRecord {
Expand Down
1 change: 1 addition & 0 deletions test-data/conda-lock/v4/path-based-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ packages:
name: minimal-project
version: '0.1'
path: ./minimal_project
editable: true
- kind: conda
name: openssl
version: 3.2.1
Expand Down

0 comments on commit 3780b25

Please sign in to comment.