Skip to content

Commit

Permalink
Merge pull request #2 from nichmor/feat/help-tim-uv-0-2-11
Browse files Browse the repository at this point in the history
misc: fix some typos
  • Loading branch information
tdejager authored Jul 8, 2024
2 parents 3bb9748 + 23f4e00 commit 4032ccc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/conda_pypi_clobber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use distribution_types::CachedDist;
use rattler_conda_types::PrefixRecord;
use uv_interpreter::PythonEnvironment;
use uv_toolchain::PythonEnvironment;

use crate::install_wheel::get_wheel_info;

Expand Down
40 changes: 34 additions & 6 deletions src/install_pypi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{borrow::Cow, collections::HashMap, path::Path, str::FromStr, sync::Arc, time::Duration};
use std::{
borrow::Cow, collections::HashMap, fs, path::Path, str::FromStr, sync::Arc, time::Duration,
};

use distribution_filename::WheelFilename;
use distribution_types::{
Expand All @@ -25,18 +27,21 @@ use uv_client::{Connectivity, FlatIndexClient, RegistryClient, RegistryClientBui
use uv_configuration::{ConfigSettings, SetupPyStrategy};
use uv_dispatch::BuildDispatch;
use uv_distribution::{DistributionDatabase, RegistryWheelIndex};
use uv_git::GitResolver;
use uv_installer::{Downloader, InstalledEditable, ResolvedEditable, SitePackages};
use uv_interpreter::{Interpreter, PythonEnvironment};
// use uv_interpreter::{Interpreter, PythonEnvironment};
use uv_configuration::PreviewMode;
use uv_normalize::PackageName;
use uv_resolver::{FlatIndex, InMemoryIndex};
use uv_toolchain::{Interpreter, PythonEnvironment};
use uv_types::HashStrategy;

use crate::{
conda_pypi_clobber::PypiCondaClobberRegistry,
consts::{DEFAULT_PYPI_INDEX_URL, PIXI_UV_INSTALLER, PROJECT_MANIFEST},
lock_file::UvResolutionContext,
prefix::Prefix,
project::manifest::{pypi_options::PypiOptions, SystemRequirements},
project::manifest::{pypi_options::PypiOptions, pyproject::PyProjectToml, SystemRequirements},
pypi_tags::{get_pypi_tags, is_python_record},
uv_reporter::{UvReporter, UvReporterOptions},
};
Expand Down Expand Up @@ -238,7 +243,8 @@ fn convert_to_dist(
VerbatimParsedUrl {
parsed_url: ParsedUrl::Path(ParsedPathUrl {
url: Url::from_file_path(&path).expect("could not convert path to url"),
path: path.clone(),
install_path: path.clone(),
lock_path: path.clone(),
editable: pkg.editable,
}),
verbatim: VerbatimUrl::from_path(&path)?.with_given(path.display().to_string()),
Expand Down Expand Up @@ -660,7 +666,7 @@ async fn resolve_editables(
if ArchiveTimestamp::up_to_date_with(&editable.path, ArchiveTarget::Install(dist))
.into_diagnostic()?
// If the editable is dynamic, we need to rebuild it
&& !uv_installer::is_dynamic(&editable.path)
&& !is_dynamic(&editable.path)
// And the dist is already editable
&& dist.is_editable()
{
Expand Down Expand Up @@ -706,6 +712,7 @@ async fn resolve_editables(
registry_client,
build_dispatch,
uv_context.concurrency.builds,
PreviewMode::Disabled,
);

// Build the editables
Expand Down Expand Up @@ -782,7 +789,7 @@ pub async fn update_python_distributions(
.into_diagnostic()?;
FlatIndex::from_entries(
entries,
&tags,
Some(&tags),
&uv_types::HashStrategy::None,
&uv_context.no_build,
&uv_context.no_binary,
Expand Down Expand Up @@ -1087,6 +1094,27 @@ pub async fn update_python_distributions(
Ok(())
}

/// Returns `true` if the source tree at the given path contains dynamic metadata.
fn is_dynamic(path: &Path) -> bool {
// return true;
// If there's no `pyproject.toml`, we assume it's dynamic.
let Ok(contents) = fs::read_to_string(path.join("pyproject.toml")) else {
return true;
};
let Ok(pyproject_toml) = PyProjectToml::from(&contents) else {
return true;
};
// If `[project]` is not present, we assume it's dynamic.
let Some(project) = pyproject_toml.project else {
// ...unless it appears to be a Poetry project.
return pyproject_toml
.tool
.map_or(true, |tool| tool.poetry.is_none());
};
// `[project.dynamic]` must be present and non-empty.
project.dynamic.is_some_and(|dynamic| !dynamic.is_empty())
}

#[cfg(test)]
mod tests {
use distribution_types::RemoteSource;
Expand Down
2 changes: 1 addition & 1 deletion src/install_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use std::{

use miette::IntoDiagnostic;
use serde::{Deserialize, Serialize};
use uv_interpreter::PythonEnvironment;
use uv_toolchain::PythonEnvironment;

/// Line in a RECORD file
/// <https://www.python.org/dev/peps/pep-0376/#record>
Expand Down
6 changes: 3 additions & 3 deletions src/lock_file/resolve/pypi_editables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,23 @@ pub async fn build_editables(
let reporter_clone = reporter.clone();
let mut build_stream = futures::stream::iter(editables)
.map(|editable| async {
let task = reporter_clone.on_editable_build_start(&editable);
let task = reporter_clone.on_build_start(&editable);
let metadata = build_editable(cache, &editable, build_dispatch).await?;
Ok::<_, BuildEditablesError>((editable, metadata, task))
})
.buffer_unordered(10);

let reporter_clone = reporter.clone();
while let Some((local_editable, metadata, task)) = build_stream.next().await.transpose()? {
reporter_clone.on_editable_build_complete(&local_editable, task);
reporter_clone.on_build_complete(&local_editable, task);

// Convert the metadata into a set of requirements
let requirements = Requirements {
dependencies: metadata
.requires_dist
.iter()
.cloned()
.map(distribution_types::Requirement::from)
.map(pypi_types::Requirement::from)
.collect(),
optional_dependencies: IndexMap::default(),
};
Expand Down
16 changes: 0 additions & 16 deletions src/uv_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,6 @@ impl uv_installer::DownloadReporter for UvReporter {
self.finish(id);
}

fn on_editable_build_start(&self, dist: &distribution_types::LocalEditable) -> usize {
let path = dist.path.file_name();
if let Some(path) = path {
self.start_sync(format!(
"building editable source {}",
path.to_string_lossy()
))
} else {
self.start_sync("building editable source".to_string())
}
}

fn on_editable_build_complete(&self, _dist: &distribution_types::LocalEditable, id: usize) {
self.finish(id);
}

fn on_checkout_start(&self, url: &url::Url, _rev: &str) -> usize {
self.start_sync(format!("cloning {}", url))
}
Expand Down

0 comments on commit 4032ccc

Please sign in to comment.