Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Start refactoring the Project struct
Browse files Browse the repository at this point in the history
Goal: get rid of the Project struct altogether and fix #110 properly.

First step:

 * Extract a Context struct to hold paths, venv_runner and python_info


This commit does that for the `install` and `process_scripts` methods
  • Loading branch information
dmerejkowsky committed Nov 6, 2019
1 parent a2c6676 commit e631762
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ pub use crate::cmd::{print_error, print_info_1, print_info_2};
pub use crate::error::*;
use crate::lock::BumpType;
use crate::operations::{InitOptions, UpdateOptions};
use crate::paths::{Paths, PathsResolver};
pub use crate::paths::{DEV_LOCK_FILENAME, PROD_LOCK_FILENAME};
use crate::project::{PostInstallAction, ProcessScriptsMode, Project};
use crate::python_info::PythonInfo;
use crate::run::VenvRunner;
pub use crate::settings::Settings;

struct Context {
paths: Paths,
python_info: PythonInfo,
settings: Settings,
venv_runner: VenvRunner,
}

fn get_context(cmd: &Command) -> Result<Context, Error> {
let project_path = if let Some(p) = &cmd.project_path {
fn init(
project_path: Option<String>,
name: &str,
Expand All @@ -44,6 +55,18 @@ fn init(
if !setup_cfg {
init_options.no_setup_cfg();
};
let python_info = PythonInfo::new(&cmd.python_binary)?;
let python_version = python_info.version.clone();
let settings = Settings::from_shell(&cmd);
let paths_resolver = PathsResolver::new(project_path.clone(), python_version, &settings);
let paths = paths_resolver.paths()?;
let venv_runner = VenvRunner::new(&project_path, &paths.venv);
Ok(Context {
paths,
python_info,
settings,
venv_runner,
})
if let Some(author) = author {
init_options.author(&author);
}
Expand All @@ -63,14 +86,16 @@ pub fn run(cmd: Command) -> Result<(), Error> {
return init(cmd.project_path, name, version, author, !no_setup_cfg);
}

let project_path = if let Some(p) = cmd.project_path {
let python_info = PythonInfo::new(&cmd.python_binary)?;
PathBuf::from(p)
} else {
look_up_for_project_path()?
};
let python_info = PythonInfo::new(&cmd.python_binary)?;
let settings = Settings::from_shell(&cmd);
let project = Project::new(project_path, python_info, settings)?;

let context = get_context(&cmd)?;

match &cmd.sub_cmd {
SubCommand::Install { no_develop } => {
let post_install_action = if *no_develop {
Expand Down

0 comments on commit e631762

Please sign in to comment.