Skip to content

Commit

Permalink
Merge remote-tracking branch 'mine/self-clobber-test' into self-clobber
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Oct 7, 2024
2 parents 8964416 + 78c54d5 commit f98e892
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 8 deletions.
88 changes: 87 additions & 1 deletion crates/rattler/src/install/clobber_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ mod tests {
.with_prefix_records(&prefix_records)
.finish();

execute_transaction(
let result = execute_transaction(
transaction,
target_prefix.path(),
&reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()),
Expand All @@ -877,6 +877,8 @@ mod tests {
)
.await;

println!("== RESULT: {:?}", result.clobbered_paths);

assert_check_files(
target_prefix.path(),
&[
Expand All @@ -899,6 +901,90 @@ mod tests {
);
}

#[tokio::test]
async fn test_self_clobber_update() {
// Create a transaction
let repodata_record_1 = get_repodata_record(
get_test_data_dir().join("clobber/clobber-1-0.1.0-h4616a5c_0.tar.bz2"),
);

let transaction = transaction::Transaction::<PrefixRecord, RepoDataRecord> {
operations: vec![TransactionOperation::Install(repodata_record_1.clone())],
python_info: None,
current_python_info: None,
platform: Platform::current(),
};

// execute transaction
let target_prefix = tempfile::tempdir().unwrap();

let packages_dir = tempfile::tempdir().unwrap();
let cache = PackageCache::new(packages_dir.path());

execute_transaction(
transaction,
target_prefix.path(),
&reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()),
&cache,
&InstallDriver::default(),
&InstallOptions::default(),
)
.await;

// check that the files are there
assert_check_files(
target_prefix.path(),
&["clobber.txt", "another-clobber.txt"],
);

let mut prefix_records = PrefixRecord::collect_from_prefix(target_prefix.path()).unwrap();
prefix_records.sort_by(|a, b| {
a.repodata_record
.package_record
.name
.as_normalized()
.cmp(b.repodata_record.package_record.name.as_normalized())
});

// Reinstall the same package
let transaction = transaction::Transaction::<PrefixRecord, RepoDataRecord> {
operations: vec![TransactionOperation::Change {
old: prefix_records[0].clone(),
new: repodata_record_1,
}],
python_info: None,
current_python_info: None,
platform: Platform::current(),
};

let install_driver = InstallDriver::builder()
.with_prefix_records(&prefix_records)
.finish();

install_driver
.pre_process(&transaction, target_prefix.path())
.unwrap();
let dl_client = reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new());
for op in &transaction.operations {
execute_operation(
target_prefix.path(),
&dl_client,
&cache,
&install_driver,
op.clone(),
&InstallOptions::default(),
)
.await;
}

// Check what files are in the prefix now (note that unclobbering wasn't run yet)
// But also, this is a reinstall so the files should just be overwritten.
assert_check_files(
target_prefix.path(),
&["clobber.txt", "another-clobber.txt"],
);
}

#[tokio::test]
async fn test_clobber_update_and_remove() {
// Create a transaction
Expand Down
8 changes: 4 additions & 4 deletions py-rattler/Cargo.lock

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

6 changes: 6 additions & 0 deletions py-rattler/rattler/channel/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def __init__(self, name: str, channel_configuration: Optional[ChannelConfig] = N

self._channel = PyChannel(name, channel_configuration._channel_configuration)

@classmethod
def _from_py_channel(cls, py_channel: PyChannel) -> Channel:
channel = cls.__new__(cls)
channel._channel = py_channel
return channel

def to_lock_channel(self) -> LockChannel:
"""
Returns a new [`LockChannel`] from existing channel.
Expand Down
5 changes: 2 additions & 3 deletions py-rattler/rattler/match_spec/match_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ def channel(self) -> Optional[Channel]:
"""
The channel of the package.
"""
if (channel := self._match_spec.channel) is not None:
return Channel(channel.name)
return None
channel = self._match_spec.channel
return channel and Channel._from_py_channel(channel)

@property
def subdir(self) -> Optional[str]:
Expand Down
22 changes: 22 additions & 0 deletions py-rattler/tests/unit/test_matchspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,25 @@ def test_parse_channel_from_url() -> None:
assert m.channel is not None
assert m.channel.name == "conda-forge"
assert m.channel.base_url == "https://conda.anaconda.org/conda-forge/"


def test_parse_channel_from_url_filesystem() -> None:
m = MatchSpec("file:///Users/rattler/channel0::python[version=3.9]")
assert m.channel is not None
assert m.channel.name == "channel0"
assert m.channel.base_url == "file:///Users/rattler/channel0/"


def test_parse_channel_from_url_localhost() -> None:
m = MatchSpec("http://localhost:8000/channel0::python[version=3.9]")
assert m.channel is not None
assert m.channel.name == "channel0"
assert m.channel.base_url == "http://localhost:8000/channel0/"


def test_parse_no_channel() -> None:
m = MatchSpec("python[version=3.9]")
assert m.channel is None
assert m.name is not None
assert m.name.normalized == "python"
assert m.version == "==3.9"

0 comments on commit f98e892

Please sign in to comment.