Skip to content

Commit

Permalink
Add annotations to lockfile and simplify workspace locking (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko authored Feb 11, 2024
1 parent 41efe97 commit 63c66b1
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 20 deletions.
38 changes: 38 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,69 @@
# with-sources: false

-e file:.
# from workspace
certifi==2023.5.7
# via requests
charset-normalizer==3.1.0
# via requests
click==8.1.3
# via mkdocs
colorama==0.4.6
# via mkdocs-material
ghp-import==2.1.0
# via mkdocs
idna==3.4
# via requests
jinja2==3.1.2
# via mkdocs
# via mkdocs-material
markdown==3.3.7
# via mdx-gh-links
# via mkdocs
# via mkdocs-material
# via pymdown-extensions
markupsafe==2.1.2
# via jinja2
mdx-gh-links==0.3
# via rye-dev
mergedeep==1.3.4
# via mkdocs
mkdocs==1.4.3
# via mkdocs-material
# via mkdocs-simple-hooks
# via rye-dev
mkdocs-include-markdown-plugin==4.0.4
# via rye-dev
mkdocs-material==9.1.12
# via rye-dev
mkdocs-material-extensions==1.1.1
# via mkdocs-material
mkdocs-simple-hooks==0.1.5
# via rye-dev
mkdocs-version-annotations==1.0.0
# via rye-dev
packaging==23.1
# via mkdocs
pygments==2.15.1
# via mkdocs-material
pymdown-extensions==9.11
# via mkdocs-material
# via rye-dev
python-dateutil==2.8.2
# via ghp-import
pyyaml==6.0
# via mkdocs
# via pymdown-extensions
# via pyyaml-env-tag
pyyaml-env-tag==0.1
# via mkdocs
regex==2023.5.5
# via mkdocs-material
requests==2.30.0
# via mkdocs-material
six==1.16.0
# via python-dateutil
urllib3==2.0.2
# via requests
watchdog==3.0.0
# via mkdocs
38 changes: 38 additions & 0 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,69 @@
# with-sources: false

-e file:.
# from workspace
certifi==2023.5.7
# via requests
charset-normalizer==3.1.0
# via requests
click==8.1.3
# via mkdocs
colorama==0.4.6
# via mkdocs-material
ghp-import==2.1.0
# via mkdocs
idna==3.4
# via requests
jinja2==3.1.2
# via mkdocs
# via mkdocs-material
markdown==3.3.7
# via mdx-gh-links
# via mkdocs
# via mkdocs-material
# via pymdown-extensions
markupsafe==2.1.2
# via jinja2
mdx-gh-links==0.3
# via rye-dev
mergedeep==1.3.4
# via mkdocs
mkdocs==1.4.3
# via mkdocs-material
# via mkdocs-simple-hooks
# via rye-dev
mkdocs-include-markdown-plugin==4.0.4
# via rye-dev
mkdocs-material==9.1.12
# via rye-dev
mkdocs-material-extensions==1.1.1
# via mkdocs-material
mkdocs-simple-hooks==0.1.5
# via rye-dev
mkdocs-version-annotations==1.0.0
# via rye-dev
packaging==23.1
# via mkdocs
pygments==2.15.1
# via mkdocs-material
pymdown-extensions==9.11
# via mkdocs-material
# via rye-dev
python-dateutil==2.8.2
# via ghp-import
pyyaml==6.0
# via mkdocs
# via pymdown-extensions
# via pyyaml-env-tag
pyyaml-env-tag==0.1
# via mkdocs
regex==2023.5.5
# via mkdocs-material
requests==2.30.0
# via mkdocs-material
six==1.16.0
# via python-dateutil
urllib3==2.0.2
# via requests
watchdog==3.0.0
# via mkdocs
37 changes: 17 additions & 20 deletions rye/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crate::sources::PythonVersion;
use crate::utils::{set_proxy_variables, CommandOutput};

static FILE_EDITABLE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^-e (file://.*?)\s*$").unwrap());
static DEP_COMMENT_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^ # (?:(via)|(?:via (.*?))|(?: (.*?)))$").unwrap());
static REQUIREMENTS_HEADER: &str = r#"# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
Expand Down Expand Up @@ -86,7 +88,6 @@ pub fn update_workspace_lockfile(

let features_by_project = collect_workspace_features(lock_options);
let mut req_file = NamedTempFile::new()?;
let mut local_req_file = NamedTempFile::new()?;

let mut local_projects = HashMap::new();
let mut projects = Vec::new();
Expand All @@ -97,7 +98,7 @@ pub fn update_workspace_lockfile(

// virtual packages are not installed
if !pyproject.is_virtual() {
writeln!(local_req_file, "-e {}{}", rel_url, applicable_extras)?;
writeln!(req_file, "-e {}{}", rel_url, applicable_extras)?;
}

local_projects.insert(pyproject.normalized_name()?, rel_url);
Expand All @@ -118,15 +119,11 @@ pub fn update_workspace_lockfile(
req_file.as_file_mut(),
DependencyKind::Dev,
)?;
dump_dependencies(
pyproject,
&local_projects,
local_req_file.as_file_mut(),
DependencyKind::Dev,
)?;
}
}

req_file.flush()?;

let exclusions = find_exclusions(&projects)?;
generate_lockfile(
output,
Expand All @@ -137,17 +134,6 @@ pub fn update_workspace_lockfile(
sources,
lock_options,
&exclusions,
&[],
)?;
generate_lockfile(
output,
py_ver,
&workspace.path(),
local_req_file.path(),
lockfile,
sources,
lock_options,
&exclusions,
&["--pip-args=--no-deps"],
)?;

Expand Down Expand Up @@ -339,6 +325,7 @@ fn generate_lockfile(
.arg("--strip-extras")
.arg("--allow-unsafe")
.arg("--no-header")
.arg("--annotate")
.arg("--pip-args")
.arg(format!(
"--python-version=\"{}.{}\"",
Expand Down Expand Up @@ -427,9 +414,19 @@ fn finalize_lockfile(
&& (x.version_or_url.is_none() || x.version_or_url == req.version_or_url)
}) {
// skip exclusions
writeln!(rv, "# excluded {}", line)?;
writeln!(rv, "# {} (excluded)", line)?;
continue;
}
} else if let Some(m) = DEP_COMMENT_RE.captures(line) {
if let Some(dep) = m.get(2).or_else(|| m.get(3)).map(|x| x.as_str()) {
if !dep.starts_with("-r ") {
// we cannot tell today based on the output where this comes from. This
// can show up because it's a root dependency, because it's a dev dependency
// or in some cases just because we declared it as a duplicate.
writeln!(rv, " # via {}", dep)?;
}
};
continue;
}
writeln!(rv, "{}", line)?;
}
Expand Down

0 comments on commit 63c66b1

Please sign in to comment.