Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow workspaces to specify member search root #1294

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions docs/guide/workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ members = ["myname-*"]

For more information on that see [Virtual Packages](../virtual/).

Workspaces can optionally be configured to reference members from root directories.
This can be used with more complex project structures to store `pyproject.toml` files
for workspaces separately from the source tree.

```toml
[tool.rye.workspace]
root = ".."
members = ["myname-*"]
```

## Syncing

In a workspace it does not matter which project you are working with, the entire
Expand Down
1 change: 1 addition & 0 deletions rye/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ python-pkginfo = { version = "0.6.0", features = ["serde"] }
home = "0.5.9"
ctrlc = "3.4.2"
dotenvy = "0.15.7"
relative-path = "1.9.3"

[target."cfg(unix)".dependencies]
xattr = "1.3.1"
Expand Down
19 changes: 15 additions & 4 deletions rye/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use pep440_rs::{Operator, Version, VersionSpecifiers};
use pep508_rs::Requirement;
use python_pkginfo::Metadata;
use regex::Regex;
use relative_path::RelativePathBuf;
use serde::Serialize;
use toml_edit::{Array, DocumentMut, Formatted, Item, Table, TableLike, Value};
use url::Url;
Expand Down Expand Up @@ -372,6 +373,7 @@ impl fmt::Display for Script {
#[derive(Debug)]
pub struct Workspace {
root: PathBuf,
search_root: PathBuf,
doc: DocumentMut,
members: Option<Vec<String>>,
}
Expand All @@ -385,6 +387,13 @@ impl Workspace {
.and_then(|x| x.as_table_like())
.map(|workspace| Workspace {
root: path.to_path_buf(),
search_root: workspace
.get("root")
.and_then(|x| x.as_str())
.map_or(RelativePathBuf::from("."), RelativePathBuf::from)
.to_path(path)
.canonicalize()
.unwrap_or(path.into()),
doc: doc.clone(),
members: workspace
.get("members")
Expand Down Expand Up @@ -430,7 +439,9 @@ impl Workspace {

/// Checks if a project is a member of the declared workspace.
pub fn is_member(&self, path: &Path) -> bool {
if let Ok(relative) = path.strip_prefix(&self.root) {
if path.eq(&self.root) {
true
} else if let Ok(relative) = path.strip_prefix(&self.search_root) {
if relative == Path::new("") {
true
} else {
Expand Down Expand Up @@ -469,7 +480,7 @@ impl Workspace {
pub fn iter_projects<'a>(
self: &'a Arc<Self>,
) -> impl Iterator<Item = Result<PyProject, Error>> + 'a {
walkdir::WalkDir::new(&self.root)
walkdir::WalkDir::new(&self.search_root)
.into_iter()
.filter_entry(|entry| {
!(entry.file_type().is_dir() && skip_recurse_into(entry.file_name()))
Expand Down Expand Up @@ -516,14 +527,14 @@ impl Workspace {
/// That is the Python version that appears as lower bound in the
/// pyproject toml.
pub fn target_python_version(&self) -> Option<PythonVersionRequest> {
resolve_target_python_version(&self.doc, &self.root, &self.venv_path())
resolve_target_python_version(&self.doc, &self.search_root, &self.venv_path())
}

/// Returns the project's intended venv python version.
///
/// This is the python version that should be used for virtualenvs.
pub fn venv_python_version(&self) -> Result<PythonVersion, Error> {
resolve_intended_venv_python_version(&self.doc, &self.root)
resolve_intended_venv_python_version(&self.doc, &self.search_root)
}

/// Returns a list of index URLs that should be considered.
Expand Down
1 change: 0 additions & 1 deletion rye/tests/test_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ fn test_basic_tool_behavior() {
deps.push("pytest>=7.0.0");
deps.push("colorama==0.4.6");
let mut workspace_members = Array::new();
workspace_members.push(".");
workspace_members.push("child-dep");
doc["tool"]["rye"]["dev-dependencies"] = value(deps);
doc["tool"]["rye"]["workspace"]["members"] = value(workspace_members);
Expand Down
Loading