From a575b0064d60f84e5f2cf80f7d63353521ed732e Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Thu, 11 Apr 2024 10:52:54 +0100 Subject: [PATCH] Cleanup, better naming --- rye/src/cli/add.rs | 4 ++-- rye/src/cli/remove.rs | 4 ++-- rye/src/cli/run.rs | 4 ++-- rye/src/cli/test.rs | 4 ++-- rye/src/sync.rs | 14 +++++++------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/rye/src/cli/add.rs b/rye/src/cli/add.rs index 06ada84b31..c8cb898986 100644 --- a/rye/src/cli/add.rs +++ b/rye/src/cli/add.rs @@ -15,7 +15,7 @@ use crate::config::Config; use crate::consts::VENV_BIN; use crate::pyproject::{BuildSystem, DependencyKind, ExpandedSources, PyProject}; use crate::sources::py::PythonVersion; -use crate::sync::{autosync, sync, SyncOptions}; +use crate::sync::{autosync, sync, SyncOptions, SyncMode}; use crate::utils::{format_requirement, get_venv_python_bin, set_proxy_variables, CommandOutput}; use crate::uv::UvBuilder; @@ -303,7 +303,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> { } if (cfg.autosync() && !cmd.no_sync) || cmd.sync { - autosync(&pyproject_toml, output, false)?; + autosync(&pyproject_toml, output, SyncMode::Regular)?; } Ok(()) diff --git a/rye/src/cli/remove.rs b/rye/src/cli/remove.rs index 8519019e8c..2f20b64775 100644 --- a/rye/src/cli/remove.rs +++ b/rye/src/cli/remove.rs @@ -6,7 +6,7 @@ use pep508_rs::Requirement; use crate::config::Config; use crate::pyproject::{DependencyKind, PyProject}; -use crate::sync::autosync; +use crate::sync::{autosync, SyncMode}; use crate::utils::{format_requirement, CommandOutput}; /// Removes a package from this project. @@ -65,7 +65,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> { } if (Config::current().autosync() && !cmd.no_sync) || cmd.sync { - autosync(&pyproject_toml, output, false)?; + autosync(&pyproject_toml, output, SyncMode::Regular)?; } Ok(()) diff --git a/rye/src/cli/run.rs b/rye/src/cli/run.rs index cdd66a17ef..03cac06a02 100644 --- a/rye/src/cli/run.rs +++ b/rye/src/cli/run.rs @@ -10,7 +10,7 @@ use console::style; use crate::config::Config; use crate::pyproject::{PyProject, Script}; -use crate::sync::{autosync, sync, SyncOptions}; +use crate::sync::{autosync, sync, SyncOptions, SyncMode}; use crate::tui::redirect_to_stderr; use crate::utils::{exec_spawn, get_venv_python_bin, success_status, CommandOutput, IoPathContext}; @@ -53,7 +53,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> { let pyproject = PyProject::load_or_discover(cmd.pyproject.as_deref())?; if (Config::current().autosync_before_run() && !cmd.no_sync) || cmd.sync { - autosync(&pyproject, output, true)?; + autosync(&pyproject, output, SyncMode::OneOffLock)?; } else { // make sure we have the minimal virtualenv. sync(SyncOptions::python_only().pyproject(cmd.pyproject)) diff --git a/rye/src/cli/test.rs b/rye/src/cli/test.rs index 81401c4356..ad1212a4df 100644 --- a/rye/src/cli/test.rs +++ b/rye/src/cli/test.rs @@ -11,7 +11,7 @@ use same_file::is_same_file; use crate::config::Config; use crate::consts::VENV_BIN; use crate::pyproject::{locate_projects, normalize_package_name, DependencyKind, PyProject}; -use crate::sync::autosync; +use crate::sync::{autosync, SyncMode}; use crate::utils::{CommandOutput, QuietExit}; /// Run the tests on the project. @@ -79,7 +79,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> { let has_pytest = has_pytest_dependency(&projects)?; if has_pytest { if (Config::current().autosync_before_run() && !cmd.no_sync) || cmd.sync { - autosync(&projects[0], output, true)?; + autosync(&projects[0], output, SyncMode::OneOffLock)?; } else { bail!("pytest not installed but in dependencies. Run `rye sync`.") } diff --git a/rye/src/sync.rs b/rye/src/sync.rs index 6bcd72867d..c05f108bba 100644 --- a/rye/src/sync.rs +++ b/rye/src/sync.rs @@ -38,7 +38,7 @@ pub enum SyncMode { /// recreate everything Full, /// Recreate if no lock file present, otherwise install without updating - OneOff, + OneOffLock, } /// Updates the virtualenv based on the pyproject.toml @@ -179,18 +179,18 @@ pub fn sync(mut cmd: SyncOptions) -> Result<(), Error> { // hack to make this work for now. We basically sym-link pip itself // into a folder all by itself and place a second file in there which we // can pass to pip-sync to install the local package. - let has_lock = (if cmd.dev { &dev_lockfile } else { &lockfile }).is_file(); + let target_lockfile = if cmd.dev { &dev_lockfile } else { &lockfile }; + let has_lock = target_lockfile.is_file(); if recreate || cmd.mode != SyncMode::PythonOnly { let sources = ExpandedSources::from_sources(&pyproject.sources()?)?; if cmd.no_lock { - let lockfile = if cmd.dev { &dev_lockfile } else { &lockfile }; if !has_lock { bail!( "Locking is disabled but lockfile '{}' does not exist", - lockfile.display() + target_lockfile.display() ); } - } else if cmd.mode == SyncMode::OneOff && has_lock { + } else if cmd.mode == SyncMode::OneOffLock && has_lock { // do nothing } else if let Some(workspace) = pyproject.workspace() { // make sure we have an up-to-date lockfile @@ -315,11 +315,11 @@ pub fn sync(mut cmd: SyncOptions) -> Result<(), Error> { } /// Performs an autosync. -pub fn autosync(pyproject: &PyProject, output: CommandOutput, one_off: bool) -> Result<(), Error> { +pub fn autosync(pyproject: &PyProject, output: CommandOutput, sync_mode: SyncMode) -> Result<(), Error> { sync(SyncOptions { output, dev: true, - mode: if one_off {SyncMode::OneOff} else {SyncMode::Regular}, + mode: sync_mode, force: false, no_lock: false, lock_options: LockOptions::default(),