-
Notifications
You must be signed in to change notification settings - Fork 1
Add caching and don't clear environments all the time #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,6 +161,7 @@ where | |
| secrets, | ||
| params, | ||
| env_vars, | ||
| config.cache_dir, | ||
| ) | ||
| .await?; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -94,14 +94,22 @@ async fn test_uv_path(path: &PathBuf) -> Result<(), Error> { | |||||
|
|
||||||
| pub struct Uv { | ||||||
| pub uv_path: PathBuf, | ||||||
|
|
||||||
| // cache_dir is the directory that dependencies should be cached in. | ||||||
| cache_dir: Option<PathBuf>, | ||||||
|
|
||||||
| // protected_mode is a flag that indicates whether the UV instance is in protected mode. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is protected mode something that comes from UV itself or our own terminology?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's my own fancy new term :) We'll need to iterate on this a bit. |
||||||
| // In protected mode, the UV instance do things like clear the environment variables before | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| // use, etc. | ||||||
| protected_mode: bool, | ||||||
| } | ||||||
|
|
||||||
| impl Uv { | ||||||
| pub async fn new() -> Result<Self, Error> { | ||||||
| pub async fn new(cache_dir: Option<PathBuf>, protected_mode: bool) -> Result<Self, Error> { | ||||||
| match install::find_or_setup_uv().await { | ||||||
| Ok(uv_path) => { | ||||||
| test_uv_path(&uv_path).await?; | ||||||
| Ok(Uv { uv_path }) | ||||||
| Ok(Uv { uv_path, cache_dir, protected_mode }) | ||||||
| } | ||||||
| Err(e) => { | ||||||
| debug!("Error setting up UV: {:?}", e); | ||||||
|
|
@@ -117,15 +125,20 @@ impl Uv { | |||||
| ) -> Result<Child, Error> { | ||||||
| debug!("Executing UV ({:?}) venv in {:?}", &self.uv_path, cwd); | ||||||
|
|
||||||
| let child = Command::new(&self.uv_path) | ||||||
| .kill_on_drop(true) | ||||||
| let mut cmd = Command::new(&self.uv_path); | ||||||
| cmd.kill_on_drop(true) | ||||||
| .stdin(Stdio::null()) | ||||||
| .stdout(Stdio::piped()) | ||||||
| .stderr(Stdio::piped()) | ||||||
| .current_dir(cwd) | ||||||
| .arg("venv") | ||||||
| .envs(env_vars) | ||||||
| .spawn()?; | ||||||
| .envs(env_vars); | ||||||
|
|
||||||
| if let Some(dir) = &self.cache_dir { | ||||||
| cmd.arg("--cache-dir").arg(dir); | ||||||
| } | ||||||
|
|
||||||
| let child = cmd.spawn()?; | ||||||
|
|
||||||
| Ok(child) | ||||||
| } | ||||||
|
|
@@ -156,6 +169,10 @@ impl Uv { | |||||
| cmd.process_group(0); | ||||||
| } | ||||||
|
|
||||||
| if let Some(dir) = &self.cache_dir { | ||||||
| cmd.arg("--cache-dir").arg(dir); | ||||||
| } | ||||||
|
|
||||||
| let child = cmd.spawn()?; | ||||||
|
|
||||||
| Ok(child) | ||||||
|
|
@@ -185,6 +202,10 @@ impl Uv { | |||||
| cmd.process_group(0); | ||||||
| } | ||||||
|
|
||||||
| if let Some(dir) = &self.cache_dir { | ||||||
| cmd.arg("--cache-dir").arg(dir); | ||||||
| } | ||||||
|
|
||||||
| let child = cmd.spawn()?; | ||||||
|
|
||||||
| Ok(child) | ||||||
|
|
@@ -219,15 +240,24 @@ impl Uv { | |||||
| .arg("never") | ||||||
| .arg("--no-progress") | ||||||
| .arg("run") | ||||||
| .arg(program) | ||||||
| .env_clear() | ||||||
| .envs(env_vars); | ||||||
|
|
||||||
| .arg(program); | ||||||
|
|
||||||
| #[cfg(unix)] | ||||||
| { | ||||||
| cmd.process_group(0); | ||||||
| } | ||||||
|
|
||||||
| if self.protected_mode { | ||||||
| cmd.env_clear(); | ||||||
| } | ||||||
|
|
||||||
| // Need to do this after env_clear intentionally. | ||||||
| cmd.envs(env_vars); | ||||||
|
|
||||||
| if let Some(dir) = &self.cache_dir { | ||||||
| cmd.arg("--cache-dir").arg(dir); | ||||||
| } | ||||||
|
|
||||||
| let child = cmd.spawn()?; | ||||||
| Ok(child) | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be a hidden folder (prefixed with .)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically it ends up in the
.localdir in your home directory (which is waydata_local_dirresolves to in this package) so it's kinda hidden.