Skip to content

Commit

Permalink
Discover workspaces without using them in resolution (astral-sh#3585)
Browse files Browse the repository at this point in the history
Add minimal support for workspace discovery, only used for determining
paths in the bluejay commands.

We can now discover the workspace structure, namely that the
`pyproject.toml` of a package belongs to a workspace `pyproject.toml`
with members and exclusion. The globbing logic is inspired by cargo. We
don't resolve `workspace = true` metadata declarations yet.
  • Loading branch information
konstin authored May 21, 2024
1 parent 5205165 commit 2ffd453
Show file tree
Hide file tree
Showing 43 changed files with 1,007 additions and 151 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/uv-requirements/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ schemars = ["dep:schemars"]

[dev-dependencies]
indoc = "2.0.5"
insta = "1.38.0"
insta = { version = "1.38.0", features = ["filters", "redactions", "json"] }
regex = { workspace = true }

[lints]
workspace = true
2 changes: 2 additions & 0 deletions crates/uv-requirements/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub use crate::source_tree::*;
pub use crate::sources::*;
pub use crate::specification::*;
pub use crate::unnamed::*;
pub use crate::workspace::*;

mod confirm;
mod lookahead;
Expand All @@ -12,3 +13,4 @@ mod sources;
mod specification;
mod unnamed;
pub mod upgrade;
mod workspace;
22 changes: 11 additions & 11 deletions crates/uv-requirements/src/pyproject.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Reads the following fields from from `pyproject.toml`:
//! Reads the following fields from `pyproject.toml`:
//!
//! * `project.{dependencies,optional-dependencies}`
//! * `tool.uv.sources`
//! * `tool.uv.workspace`
//!
//! Then lowers them into a dependency specification.
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::io;
use std::ops::Deref;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -110,7 +110,7 @@ pub struct Tool {
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct ToolUv {
pub sources: Option<HashMap<PackageName, Source>>,
pub sources: Option<BTreeMap<PackageName, Source>>,
pub workspace: Option<ToolUvWorkspace>,
}

Expand Down Expand Up @@ -238,8 +238,8 @@ impl Pep621Metadata {
extras: &ExtrasSpecification,
pyproject_path: &Path,
project_dir: &Path,
workspace_sources: &HashMap<PackageName, Source>,
workspace_packages: &HashMap<PackageName, String>,
workspace_sources: &BTreeMap<PackageName, Source>,
workspace_packages: &BTreeMap<PackageName, String>,
preview: PreviewMode,
) -> Result<Option<Self>, Pep621Error> {
let project_sources = pyproject
Expand Down Expand Up @@ -323,9 +323,9 @@ pub(crate) fn lower_requirements(
pyproject_path: &Path,
project_name: &PackageName,
project_dir: &Path,
project_sources: &HashMap<PackageName, Source>,
workspace_sources: &HashMap<PackageName, Source>,
workspace_packages: &HashMap<PackageName, String>,
project_sources: &BTreeMap<PackageName, Source>,
workspace_sources: &BTreeMap<PackageName, Source>,
workspace_packages: &BTreeMap<PackageName, String>,
preview: PreviewMode,
) -> Result<Requirements, Pep621Error> {
let dependencies = dependencies
Expand Down Expand Up @@ -386,9 +386,9 @@ pub(crate) fn lower_requirement(
requirement: pep508_rs::Requirement,
project_name: &PackageName,
project_dir: &Path,
project_sources: &HashMap<PackageName, Source>,
workspace_sources: &HashMap<PackageName, Source>,
workspace_packages: &HashMap<PackageName, String>,
project_sources: &BTreeMap<PackageName, Source>,
workspace_sources: &BTreeMap<PackageName, Source>,
workspace_packages: &BTreeMap<PackageName, String>,
preview: PreviewMode,
) -> Result<Requirement, LoweringError> {
let source = project_sources
Expand Down
6 changes: 3 additions & 3 deletions crates/uv-requirements/src/specification.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};

use anyhow::{Context, Result};
Expand Down Expand Up @@ -165,8 +165,8 @@ impl RequirementsSpecification {
.parent()
.context("`pyproject.toml` has no parent directory")?;

let workspace_sources = HashMap::default();
let workspace_packages = HashMap::default();
let workspace_sources = BTreeMap::default();
let workspace_packages = BTreeMap::default();
match Pep621Metadata::try_from(
pyproject,
extras,
Expand Down
Loading

0 comments on commit 2ffd453

Please sign in to comment.