Skip to content

Commit

Permalink
Respect installed packages in uv run
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed May 15, 2024
1 parent f7b9ca9 commit 6e3b51f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions crates/uv/src/commands/project/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use uv_configuration::{
Concurrency, ConfigSettings, NoBinary, NoBuild, PreviewMode, SetupPyStrategy,
};
use uv_dispatch::BuildDispatch;
use uv_installer::SitePackages;
use uv_requirements::{ExtrasSpecification, RequirementsSpecification};
use uv_resolver::{FlatIndex, InMemoryIndex, OptionsBuilder};
use uv_types::{BuildIsolation, HashStrategy, InFlight};
Expand Down Expand Up @@ -40,6 +41,9 @@ pub(crate) async fn lock(
// Discover or create the virtual environment.
let venv = project::init(&project, cache, printer)?;

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

// TODO(zanieb): Support client configuration
let client_builder = BaseClientBuilder::default();

Expand Down Expand Up @@ -111,6 +115,7 @@ pub(crate) async fn lock(
// Resolve the requirements.
let resolution = project::resolve(
spec,
&site_packages,
&hasher,
&interpreter,
tags,
Expand Down
6 changes: 3 additions & 3 deletions crates/uv/src/commands/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use uv_resolver::{
Exclusions, FlatIndex, InMemoryIndex, Manifest, Options, PythonRequirement, ResolutionGraph,
Resolver,
};
use uv_types::{EmptyInstalledPackages, HashStrategy, InFlight};
use uv_types::{HashStrategy, InFlight};

use crate::commands::project::discovery::Project;
use crate::commands::reporters::{DownloadReporter, InstallReporter, ResolverReporter};
Expand Down Expand Up @@ -115,6 +115,7 @@ pub(crate) fn init(
#[allow(clippy::too_many_arguments)]
pub(crate) async fn resolve(
spec: RequirementsSpecification,
site_packages: &SitePackages<'_>,
hasher: &HashStrategy,
interpreter: &Interpreter,
tags: &Tags,
Expand All @@ -135,7 +136,6 @@ pub(crate) async fn resolve(
let overrides = Overrides::default();
let python_requirement = PythonRequirement::from_marker_environment(interpreter, markers);
let editables = Vec::new();
let installed_packages = EmptyInstalledPackages;

// Resolve the requirements from the provided sources.
let requirements = {
Expand Down Expand Up @@ -206,7 +206,7 @@ pub(crate) async fn resolve(
index,
hasher,
build_dispatch,
&installed_packages,
site_packages,
DistributionDatabase::new(client, build_dispatch, concurrency.downloads),
)?
.with_reporter(ResolverReporter::from(printer));
Expand Down
3 changes: 2 additions & 1 deletion crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ async fn update_environment(
// Resolve the requirements.
let resolution = match project::resolve(
spec,
&site_packages,
&hasher,
&interpreter,
tags,
Expand All @@ -316,7 +317,7 @@ async fn update_environment(
// Sync the environment.
project::install(
&resolution,
SitePackages::from_executable(&venv)?,
site_packages,
&no_binary,
link_mode,
&index_locations,
Expand Down

0 comments on commit 6e3b51f

Please sign in to comment.