Skip to content

Commit

Permalink
Enforce --pre when auto-syncing (#1107)
Browse files Browse the repository at this point in the history
## Summary

We weren't passing `--pre` when auto-syncing after `rye `add`.

Closes #1102
  • Loading branch information
charliermarsh committed May 22, 2024
1 parent 39fe0d0 commit 6d395c6
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 27 deletions.
34 changes: 23 additions & 11 deletions rye/src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,9 @@ pub struct Args {
/// Add this to an optional dependency group.
#[arg(long, conflicts_with = "dev", conflicts_with = "excluded")]
optional: Option<String>,
/// Include pre-releases when finding a package version.
#[arg(long)]
pre: bool,
/// Overrides the pin operator
#[arg(long)]
pin: Option<Pin>,
/// Attempt to use `keyring` for authentication for index URLs.
#[arg(long, value_enum, default_value_t)]
keyring_provider: KeyringProvider,
/// Runs `sync` even if auto-sync is disabled.
#[arg(long)]
sync: bool,
Expand All @@ -229,6 +223,19 @@ pub struct Args {
/// Turns off all output.
#[arg(short, long, conflicts_with = "verbose")]
quiet: bool,

/// Include pre-releases when finding a package version and automatically syncing the workspace.
#[arg(long)]
pre: bool,
/// Set to `true` to lock with sources in the lockfile when automatically syncing the workspace.
#[arg(long)]
with_sources: bool,
/// Set to `true` to lock with hashes in the lockfile when automatically syncing the workspace.
#[arg(long)]
generate_hashes: bool,
/// Attempt to use `keyring` for authentication for index URLs.
#[arg(long, value_enum, default_value_t)]
keyring_provider: KeyringProvider,
}

pub fn execute(cmd: Args) -> Result<(), Error> {
Expand Down Expand Up @@ -264,8 +271,6 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
requirements.push(requirement);
}

let keyring_provider = cmd.keyring_provider;

if !cmd.excluded {
if cfg.use_uv() {
sync(SyncOptions::python_only().pyproject(None))
Expand All @@ -277,10 +282,10 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
cmd.pre,
output,
&default_operator,
keyring_provider,
cmd.keyring_provider,
)?;
} else {
if keyring_provider != KeyringProvider::Disabled {
if cmd.keyring_provider != KeyringProvider::Disabled {
bail!("`--keyring-provider` option requires the uv backend");
}
for requirement in &mut requirements {
Expand Down Expand Up @@ -314,7 +319,14 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
}

if (cfg.autosync() && !cmd.no_sync) || cmd.sync {
autosync(&pyproject_toml, output, keyring_provider)?;
autosync(
&pyproject_toml,
output,
cmd.pre,
cmd.with_sources,
cmd.generate_hashes,
cmd.keyring_provider,
)?;
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions rye/src/cli/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ pub struct Args {
/// Attempt to use `keyring` for authentication for index URLs.
#[arg(long, value_enum, default_value_t)]
keyring_provider: KeyringProvider,
/// Set to true to lock with hashes in the lockfile.
#[arg(long)]
generate_hashes: bool,
/// Reset prior lock options.
#[arg(long)]
reset: bool,
/// Use this pyproject.toml file
#[arg(long, value_name = "PYPROJECT_TOML")]
pyproject: Option<PathBuf>,
/// Set to true to lock with hashes in the lockfile.
#[arg(long)]
generate_hashes: bool,
}

pub fn execute(cmd: Args) -> Result<(), Error> {
Expand Down
25 changes: 21 additions & 4 deletions rye/src/cli/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,25 @@ pub struct Args {
/// Does not run `sync` even if auto-sync is enabled.
#[arg(long, conflicts_with = "sync")]
no_sync: bool,
/// Attempt to use `keyring` for authentication for index URLs.
#[arg(long, value_enum, default_value_t)]
keyring_provider: KeyringProvider,
/// Enables verbose diagnostics.
#[arg(short, long)]
verbose: bool,
/// Turns off all output.
#[arg(short, long, conflicts_with = "verbose")]
quiet: bool,

/// Include pre-releases when automatically syncing the workspace.
#[arg(long)]
pre: bool,
/// Set to `true` to lock with sources in the lockfile when automatically syncing the workspace.
#[arg(long)]
with_sources: bool,
/// Set to `true` to lock with hashes in the lockfile when automatically syncing the workspace.
#[arg(long)]
generate_hashes: bool,
/// Attempt to use `keyring` for authentication for index URLs.
#[arg(long, value_enum, default_value_t)]
keyring_provider: KeyringProvider,
}

pub fn execute(cmd: Args) -> Result<(), Error> {
Expand Down Expand Up @@ -69,7 +79,14 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
}

if (Config::current().autosync() && !cmd.no_sync) || cmd.sync {
autosync(&pyproject_toml, output, cmd.keyring_provider)?;
autosync(
&pyproject_toml,
output,
cmd.pre,
cmd.with_sources,
cmd.generate_hashes,
cmd.keyring_provider,
)?;
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions rye/src/cli/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ pub struct Args {
/// Attempt to use `keyring` for authentication for index URLs.
#[arg(long, value_enum, default_value_t)]
keyring_provider: KeyringProvider,
/// Set to true to lock with hashes in the lockfile.
#[arg(long)]
generate_hashes: bool,
/// Use this pyproject.toml file
#[arg(long, value_name = "PYPROJECT_TOML")]
pyproject: Option<PathBuf>,
/// Do not reuse (reset) prior lock options.
#[arg(long)]
reset: bool,
/// Set to true to lock with hashes in the lockfile.
#[arg(long)]
generate_hashes: bool,
}

pub fn execute(cmd: Args) -> Result<(), Error> {
Expand Down
27 changes: 22 additions & 5 deletions rye/src/cli/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ pub struct Args {
/// Use this pyproject.toml file
#[arg(long, value_name = "PYPROJECT_TOML")]
pyproject: Option<PathBuf>,
/// Attempt to use `keyring` for authentication for index URLs.
#[arg(long, value_enum, default_value_t)]
keyring_provider: KeyringProvider,
// Disable test output capture to stdout
/// Disable test output capture to stdout.
#[arg(long = "no-capture", short = 's')]
no_capture: bool,
/// Enables verbose diagnostics.
Expand All @@ -44,6 +41,19 @@ pub struct Args {
/// Extra arguments to pytest
#[arg(last = true)]
extra_args: Vec<OsString>,

/// Include pre-releases when automatically syncing the workspace.
#[arg(long)]
pre: bool,
/// Set to `true` to lock with sources in the lockfile when automatically syncing the workspace.
#[arg(long)]
with_sources: bool,
/// Set to `true` to lock with hashes in the lockfile when automatically syncing the workspace.
#[arg(long)]
generate_hashes: bool,
/// Attempt to use `keyring` for authentication for index URLs.
#[arg(long, value_enum, default_value_t)]
keyring_provider: KeyringProvider,
}

pub fn execute(cmd: Args) -> Result<(), Error> {
Expand Down Expand Up @@ -77,7 +87,14 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
let has_pytest = has_pytest_dependency(&projects)?;
if has_pytest {
if Config::current().autosync() {
autosync(&projects[0], output, cmd.keyring_provider)?;
autosync(
&projects[0],
output,
cmd.pre,
cmd.with_sources,
cmd.generate_hashes,
cmd.keyring_provider,
)?;
} else {
bail!("pytest not installed but in dependencies. Run `rye sync`.")
}
Expand Down
10 changes: 9 additions & 1 deletion rye/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ pub fn sync(mut cmd: SyncOptions) -> Result<(), Error> {
pub fn autosync(
pyproject: &PyProject,
output: CommandOutput,
pre: bool,
with_sources: bool,
generate_hashes: bool,
keyring_provider: KeyringProvider,
) -> Result<(), Error> {
sync(SyncOptions {
Expand All @@ -327,7 +330,12 @@ pub fn autosync(
mode: SyncMode::Regular,
force: false,
no_lock: false,
lock_options: LockOptions::default(),
lock_options: LockOptions {
pre,
with_sources,
generate_hashes,
..Default::default()
},
pyproject: Some(pyproject.toml_path().to_path_buf()),
keyring_provider,
})
Expand Down

0 comments on commit 6d395c6

Please sign in to comment.