generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: drop rattler_installs_packages for uv crates
- Loading branch information
Showing
21 changed files
with
13,510 additions
and
7,771 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
mod interpreter; | ||
mod pth; | ||
mod unpack; | ||
mod venv; | ||
|
||
pub use unpack::unpack_wheel; | ||
pub use venv::create_venv; | ||
|
||
pub(crate) use interpreter::Interpreter; | ||
pub use pth::{PthFile, SymlinkCollisionResolutionStrategy}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,69 @@ | ||
use std::path::Path; | ||
use std::{ | ||
fs, | ||
path::{Path, PathBuf}, | ||
str::FromStr, | ||
}; | ||
|
||
use miette::{miette, IntoDiagnostic, Result}; | ||
use rattler_installs_packages::{ | ||
artifacts::wheel::UnpackWheelOptions, artifacts::Wheel, types::PackageName, | ||
}; | ||
|
||
use crate::Interpreter; | ||
|
||
pub fn unpack_wheel( | ||
python: &Path, | ||
version: &str, | ||
location: &Path, | ||
pkg_name: &str, | ||
wheel: &Path, | ||
) -> Result<()> { | ||
let interpreter = Interpreter::new(python, version)?; | ||
let python_executable = interpreter.executable()?; | ||
let install_paths = interpreter.install_paths(false); | ||
|
||
let unpack_options = UnpackWheelOptions { | ||
installer: Some("Aspect Build rules_py".to_string()), | ||
// launcher_arch: | ||
..UnpackWheelOptions::default() | ||
pub fn unpack_wheel(version: &str, location: &Path, wheel: &Path) -> Result<()> { | ||
let python_version: uv_python::PythonVersion = version | ||
.parse() | ||
.map_err(|_| miette!("Failed to parse Python version"))?; | ||
|
||
let wheel_file_reader = fs::File::open(wheel).into_diagnostic()?; | ||
|
||
let temp = tempfile::tempdir().into_diagnostic()?; | ||
|
||
let _ = uv_extract::unzip(wheel_file_reader, temp.path()).into_diagnostic()?; | ||
|
||
let site_packages_dir = location | ||
.join("lib") | ||
.join(format!( | ||
"python{}.{}", | ||
python_version.major(), | ||
python_version.minor() | ||
)) | ||
.join("site-packages"); | ||
|
||
let scheme = uv_pypi_types::Scheme { | ||
purelib: site_packages_dir.to_path_buf(), | ||
platlib: site_packages_dir.to_path_buf(), | ||
// No windows support. | ||
scripts: location.join("bin"), | ||
data: site_packages_dir.to_path_buf(), | ||
include: location.join("lib").join("include"), | ||
}; | ||
|
||
let package_name: PackageName = pkg_name.parse().unwrap(); | ||
let wheel = Wheel::from_path(wheel, &package_name.into()) | ||
.map_err(|_| miette!("Failed to create wheel from path"))?; | ||
|
||
wheel | ||
.unpack( | ||
&location, | ||
&install_paths, | ||
&python_executable, | ||
&unpack_options, | ||
) | ||
.into_diagnostic()?; | ||
let layout = uv_install_wheel::Layout { | ||
sys_executable: PathBuf::new(), | ||
python_version: (python_version.major(), python_version.minor()), | ||
// Don't stamp in the path to the interpreter into the generated bins | ||
// as we don't want an absolute path here. | ||
// Perhaps this should be set to just "python" so it picks up the one in the venv path? | ||
os_name: "/bin/false".to_string(), | ||
scheme, | ||
}; | ||
|
||
let filename = wheel | ||
.file_name() | ||
.and_then(|f| f.to_str()) | ||
.expect("Exepected to get filename from wheel path"); | ||
let wheel_file_name = | ||
uv_distribution_filename::WheelFilename::from_str(filename).into_diagnostic()?; | ||
|
||
uv_install_wheel::linker::install_wheel( | ||
&layout, | ||
false, | ||
temp.path(), | ||
&wheel_file_name, | ||
None, | ||
None, | ||
Some("aspect_rule_py"), | ||
uv_install_wheel::linker::LinkMode::Copy, | ||
&uv_install_wheel::linker::Locks::default(), | ||
) | ||
.into_diagnostic()?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.