Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mitsuhiko/rye
Browse files Browse the repository at this point in the history
  • Loading branch information
hyyking committed Mar 5, 2024
2 parents 845c4ca + 11af741 commit 73cd886
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 33 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Clippy

on: [push, pull_request]
on:
workflow_dispatch:
push:
branches: [main]
pull_request:

jobs:
build:
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/python-format.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Python format

on: [push, pull_request]
on:
workflow_dispatch:
push:
branches: [main]
pull_request:

jobs:
format:
Expand All @@ -9,6 +13,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: eifinger/setup-rye@v1
- uses: eifinger/setup-rye@v2
- name: Rye fmt
run: rye fmt --check
8 changes: 6 additions & 2 deletions .github/workflows/python-lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Python lint

on: [push, pull_request]
on:
workflow_dispatch:
push:
branches: [main]
pull_request:

jobs:
lint:
Expand All @@ -9,6 +13,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: eifinger/setup-rye@v1
- uses: eifinger/setup-rye@v2
- name: Rye lint
run: rye lint
6 changes: 5 additions & 1 deletion .github/workflows/rustfmt.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Rustfmt

on: [push, pull_request]
on:
workflow_dispatch:
push:
branches: [main]
pull_request:

jobs:
build:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Spelling

on: [push, pull_request]
on:
workflow_dispatch:
push:
branches: [main]
pull_request:

jobs:
typos:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync-python-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install Rye
uses: eifinger/setup-rye@v1
uses: eifinger/setup-rye@v2
with:
enable-cache: true
- name: Sync Python Releases
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync-uv-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install Rye
uses: eifinger/setup-rye@v1
uses: eifinger/setup-rye@v2
with:
enable-cache: true
- name: Sync UV Releases
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Tests

on: [push, pull_request]
on:
workflow_dispatch:
push:
branches: [main]
pull_request:

jobs:
test-latest-linux:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ that were not yet released.

_Unreleased_

- `--skip-existing` is now available with Rye's `publish` command. #831

- Bumped `uv` to 0.1.13. #760, #820

- Bumped `ruff` to 0.3.0. #821
Expand All @@ -16,6 +18,8 @@ _Unreleased_

- Retain markers when adding dependencies with features when uv is used. #807

- Fixed a bug that caused repeated syncs not to recall all previous options. #830

<!-- released start -->

## 0.27.0
Expand Down
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,3 @@ serve-docs = "mkdocs serve"

[tool.rye.workspace]
members = ["rye-devtools"]

[tool.ruff]
# the .rye folder is added by the rye github action
exclude = [".rye", ".venv"]
6 changes: 6 additions & 0 deletions rye/src/cli/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub struct Args {
/// Path to alternate CA bundle.
#[arg(long)]
cert: Option<PathBuf>,
/// Continue uploading files if one already exists (only applies to repositories supporting this feature)
#[arg(long)]
skip_existing: bool,
/// Skip prompts.
#[arg(short, long)]
yes: bool,
Expand Down Expand Up @@ -167,6 +170,9 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
if let Some(cert) = cmd.cert {
publish_cmd.arg("--cert").arg(cert);
}
if cmd.skip_existing {
publish_cmd.arg("--skip-existing");
}

if output == CommandOutput::Quiet {
publish_cmd.stdout(Stdio::null());
Expand Down
50 changes: 31 additions & 19 deletions rye/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static REQUIREMENTS_HEADER: &str = r#"# generated by rye
"#;
static PARAM_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^# (pre|features|all-features|with_sources):\s*(.*?)$").unwrap());
Lazy::new(|| Regex::new(r"^# (pre|features|all-features|with-sources):\s*(.*?)$").unwrap());

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum LockMode {
Expand Down Expand Up @@ -111,7 +111,9 @@ impl LockOptions {
"all-features" => {
rv.all_features = rv.all_features || serde_json::from_str(value)?
}
"with-sources" => rv.with_sources = serde_json::from_str(value)?,
"with-sources" => {
rv.with_sources = rv.with_sources || serde_json::from_str(value)?
}
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -139,7 +141,8 @@ pub fn update_workspace_lockfile(
echo!("Generating {} lockfile: {}", lock_mode, lockfile.display());
}

let features_by_project = collect_workspace_features(lock_options);
let lock_options = restore_lock_options(lockfile, lock_options)?;
let features_by_project = collect_workspace_features(&lock_options);
let mut req_file = NamedTempFile::new()?;

let mut local_projects = HashMap::new();
Expand Down Expand Up @@ -185,14 +188,27 @@ pub fn update_workspace_lockfile(
req_file.path(),
lockfile,
sources,
lock_options,
&lock_options,
&exclusions,
true,
)?;

Ok(())
}

/// Tries to restore the lock options from the given lockfile.
fn restore_lock_options<'o>(
lockfile: &Path,
lock_options: &'o LockOptions,
) -> Result<Cow<'o, LockOptions>, Error> {
if lockfile.is_file() {
let requirements = fs::read_to_string(lockfile)?;
Ok(LockOptions::restore(&requirements, lock_options)?)
} else {
Ok(Cow::Borrowed(lock_options))
}
}

fn format_project_extras<'a>(
features_by_project: Option<&'a HashMap<String, HashSet<&str>>>,
project: &PyProject,
Expand Down Expand Up @@ -307,11 +323,12 @@ pub fn update_single_project_lockfile(
echo!("Generating {} lockfile: {}", lock_mode, lockfile.display());
}

let lock_options = restore_lock_options(lockfile, lock_options)?;
let mut req_file = NamedTempFile::new()?;

// virtual packages are themselves not installed
if !pyproject.is_virtual() {
let features_by_project = collect_workspace_features(lock_options);
let features_by_project = collect_workspace_features(&lock_options);
let applicable_extras = format_project_extras(features_by_project.as_ref(), pyproject)?;
writeln!(
req_file,
Expand Down Expand Up @@ -340,7 +357,7 @@ pub fn update_single_project_lockfile(
req_file.path(),
lockfile,
sources,
lock_options,
&lock_options,
&exclusions,
false,
)?;
Expand All @@ -363,19 +380,14 @@ fn generate_lockfile(
let use_uv = Config::current().use_uv();
let scratch = tempfile::tempdir()?;
let requirements_file = scratch.path().join("requirements.txt");
let lock_options = if lockfile.is_file() {
let requirements = fs::read_to_string(lockfile)?;
fs::write(&requirements_file, &requirements)
if lockfile.is_file() {
fs::copy(lockfile, &requirements_file)
.path_context(&requirements_file, "unable to restore requirements file")?;
LockOptions::restore(&requirements, lock_options)?
} else {
if !use_uv {
fs::write(&requirements_file, b"").path_context(
&requirements_file,
"unable to write empty requirements file",
)?;
}
Cow::Borrowed(lock_options)
} else if !use_uv {
fs::write(&requirements_file, b"").path_context(
&requirements_file,
"unable to write empty requirements file",
)?;
};

let mut cmd = if use_uv {
Expand Down Expand Up @@ -453,7 +465,7 @@ fn generate_lockfile(
workspace_path,
exclusions,
sources,
&lock_options,
lock_options,
)?;

Ok(())
Expand Down
Loading

0 comments on commit 73cd886

Please sign in to comment.