Skip to content

Commit

Permalink
Cleanup, better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Apr 11, 2024
1 parent 4e6fe27 commit a575b00
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions rye/src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions rye/src/cli/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions rye/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions rye/src/cli/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`.")
}
Expand Down
14 changes: 7 additions & 7 deletions rye/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit a575b00

Please sign in to comment.