Re-compile when `--compile` is passed to an install operation (#9378)

## Summary

Closes https://github.com/astral-sh/uv/issues/9377.
This commit is contained in:
Charlie Marsh 2024-11-22 20:57:04 -05:00 committed by GitHub
parent 1343b167f9
commit 35ff802e3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 55 additions and 1 deletions

View File

@ -440,7 +440,12 @@ pub(crate) async fn install(
};
// Nothing to do.
if remote.is_empty() && cached.is_empty() && reinstalls.is_empty() && extraneous.is_empty() {
if remote.is_empty()
&& cached.is_empty()
&& reinstalls.is_empty()
&& extraneous.is_empty()
&& !compile
{
logger.on_audit(resolution.len(), start, printer)?;
return Ok(Changelog::default());
}

View File

@ -3292,6 +3292,55 @@ fn compile() -> Result<()> {
Ok(())
}
/// Re-install with bytecode compilation.
#[test]
fn recompile() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str("MarkupSafe==2.1.3")?;
uv_snapshot!(context.pip_sync()
.arg("requirements.txt")
.arg("--strict"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ markupsafe==2.1.3
"###
);
uv_snapshot!(context.pip_sync()
.arg("requirements.txt")
.arg("--compile")
.arg("--strict"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Bytecode compiled 3 files in [TIME]
"###
);
assert!(context
.site_packages()
.join("markupsafe")
.join("__pycache__")
.join("__init__.cpython-312.pyc")
.exists());
context.assert_command("import markupsafe").success();
Ok(())
}
/// Raise an error when an editable's `Requires-Python` constraint is not met.
#[test]
fn requires_python_editable() -> Result<()> {