Skip to content

Commit

Permalink
Treat non-existent site-packages as empty (#2413)
Browse files Browse the repository at this point in the history
## Summary

It turns out this doesn't need to exist until something has been
installed into it. See, e.g., #2402.

Closes #2404.
  • Loading branch information
charliermarsh committed Mar 13, 2024
1 parent bfddd72 commit cca9de1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,32 @@ jobs:
- name: "Validate global Python install"
shell: bash -el {0}
run: python ./scripts/check_system_python.py --uv ./uv

system-test-amazonlinux:
needs: build-binary-linux
name: "check system | amazonlinux"
runs-on: ubuntu-latest
container: amazonlinux:2023
steps:
- name: "Install base requirements"
run: |
# Needed for `actions/checkout`
yum install tar gzip which -y
- uses: actions/checkout@v4

- name: "Install Python"
run: yum install python3 python3-pip -y

- name: "Download binary"
uses: actions/download-artifact@v4
with:
name: uv-linux-${{ github.sha }}

- name: "Prepare binary"
run: chmod +x ./uv

- name: "Print Python path"
run: echo $(which python3)

- name: "Validate global Python install"
run: python3 scripts/check_system_python.py --uv ./uv
3 changes: 1 addition & 2 deletions crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
let tags = self.interpreter.tags()?;

// Determine the set of installed packages.
let site_packages =
SitePackages::from_executable(venv).context("Failed to list installed packages")?;
let site_packages = SitePackages::from_executable(venv)?;

let Plan {
local,
Expand Down
16 changes: 15 additions & 1 deletion crates/uv-installer/src/site_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,22 @@ impl<'a> SitePackages<'a> {
let mut by_name = FxHashMap::default();
let mut by_url = FxHashMap::default();

// Read the site-packages directory.
let site_packages = match fs::read_dir(venv.site_packages()) {
Ok(site_packages) => site_packages,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
return Ok(Self {
venv,
distributions,
by_name,
by_url,
});
}
Err(err) => return Err(err).context("Failed to read site-packages directory"),
};

// Index all installed packages by name.
for entry in fs::read_dir(venv.site_packages())? {
for entry in site_packages {
let entry = entry?;
if entry.file_type()?.is_dir() {
let path = entry.path();
Expand Down
3 changes: 1 addition & 2 deletions crates/uv/src/commands/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ pub(crate) async fn pip_install(
let _lock = venv.lock()?;

// Determine the set of installed packages.
let site_packages =
SitePackages::from_executable(&venv).context("Failed to list installed packages")?;
let site_packages = SitePackages::from_executable(&venv)?;

// If the requirements are already satisfied, we're done. Ideally, the resolver would be fast
// enough to let us remove this check. But right now, for large environments, it's an order of
Expand Down
3 changes: 1 addition & 2 deletions crates/uv/src/commands/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ pub(crate) async fn pip_sync(
);

// Determine the set of installed packages.
let site_packages =
SitePackages::from_executable(&venv).context("Failed to list installed packages")?;
let site_packages = SitePackages::from_executable(&venv)?;

// Resolve any editables.
let resolved_editables = resolve_editables(
Expand Down

0 comments on commit cca9de1

Please sign in to comment.