Skip to content

Commit

Permalink
fix: add channels to constructor of Environment (#1051)
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra authored Feb 6, 2025
1 parent dcc0d99 commit 46afb12
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
24 changes: 12 additions & 12 deletions py-rattler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions py-rattler/rattler/lock/environment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from typing import Dict, List, Optional

from rattler.lock.channel import LockChannel
from rattler.lock.package import LockedPackage, PypiLockedPackage
from rattler.platform.platform import Platform
Expand All @@ -15,14 +16,19 @@ class Environment:

_env: PyEnvironment

def __init__(self, name: str, requirements: Dict[Platform, List[RepoDataRecord]]) -> None:
def __init__(
self, name: str, requirements: Dict[Platform, List[RepoDataRecord]], channels: List[LockChannel]
) -> None:
"""
Create a new environment.
"""
self._env = PyEnvironment(
name,
name=name,
# TODO: move this logic to rust
{platform._inner: [record._record for record in records] for (platform, records) in requirements.items()},
records={
platform._inner: [record._record for record in records] for (platform, records) in requirements.items()
},
channels=[channel._channel for channel in channels],
)

def platforms(self) -> List[Platform]:
Expand Down
29 changes: 16 additions & 13 deletions py-rattler/src/lock/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::channel::PyChannel;
use crate::match_spec::PyMatchSpec;
use crate::version::PyVersion;
use crate::{error::PyRattlerError, platform::PyPlatform, record::PyRecord};
Expand All @@ -9,7 +10,7 @@ use rattler_lock::{
PackageHashes, PypiPackageData, PypiPackageEnvironmentData, DEFAULT_ENVIRONMENT_NAME,
};
use std::{
collections::{BTreeSet, HashMap, HashSet},
collections::{BTreeSet, HashMap},
path::PathBuf,
str::FromStr,
};
Expand Down Expand Up @@ -127,21 +128,23 @@ impl PyEnvironment {
#[pymethods]
impl PyEnvironment {
#[new]
pub fn new(name: String, req: HashMap<PyPlatform, Vec<PyRecord>>) -> PyResult<Self> {
pub fn new(
name: String,
records: HashMap<PyPlatform, Vec<PyRecord>>,
channels: Vec<PyChannel>,
) -> PyResult<Self> {
let mut lock = LockFile::builder();
let channels = req
.values()
.flat_map(|records| {
records
.iter()
.filter_map(|r| r.channel().transpose())
.collect::<Vec<PyResult<_>>>()
})
.collect::<PyResult<HashSet<_>>>()?;

lock.set_channels(&name, channels);
lock.set_channels(
&name,
channels.into_iter().map(|c| {
rattler_lock::Channel::from(
c.inner.base_url.as_str().trim_end_matches('/').to_string(),
)
}),
);

for (platform, records) in req {
for (platform, records) in records {
for record in records {
lock.add_conda_package(
&name,
Expand Down
2 changes: 1 addition & 1 deletion py-rattler/tests/unit/test_prefix_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_prefix_paths() -> None:
size_in_bytes=1024,
)

assert str(prefix_paths_entry.relative_path) == "foo/bar/baz"
assert str(prefix_paths_entry.relative_path) == str(Path("foo/bar/baz"))
assert prefix_paths_entry.path_type.hardlink
assert prefix_paths_entry.prefix_placeholder == "placeholder_foo_bar"
assert prefix_paths_entry.file_mode.binary
Expand Down

0 comments on commit 46afb12

Please sign in to comment.