-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve seed packages for non-Puffin-created virtualenvs (#535)
## Summary This PR modifies the install plan to avoid removing seed packages if the virtual environment was created by anyone other than Puffin. Closes #414. ## Test Plan - Ran: `virtualenv .venv`. - Ran: `cargo run -p puffin-cli -- pip-sync scripts/benchmarks/requirements.txt --verbose --no-cache`. - Verified that `pip` et al were not removed, and that the logging including a message around preserving seed packages.
- Loading branch information
1 parent
77b3921
commit 95b8316
Showing
5 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::path::Path; | ||
|
||
use fs_err as fs; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Configuration { | ||
/// The version of the `virtualenv` package used to create the virtual environment, if any. | ||
pub(crate) virtualenv: bool, | ||
/// The version of the `gourgeist` package used to create the virtual environment, if any. | ||
pub(crate) gourgeist: bool, | ||
} | ||
|
||
impl Configuration { | ||
/// Parse a `pyvenv.cfg` file into a [`Configuration`]. | ||
pub fn parse(cfg: impl AsRef<Path>) -> Result<Self, Error> { | ||
let mut virtualenv = false; | ||
let mut gourgeist = false; | ||
|
||
// Per https://snarky.ca/how-virtual-environments-work/, the `pyvenv.cfg` file is not a | ||
// valid INI file, and is instead expected to be parsed by partitioning each line on the | ||
// first equals sign. | ||
let content = fs::read_to_string(&cfg)?; | ||
for line in content.lines() { | ||
let Some((key, _value)) = line.split_once('=') else { | ||
continue; | ||
}; | ||
match key.trim() { | ||
"virtualenv" => { | ||
virtualenv = true; | ||
} | ||
"gourgeist" => { | ||
gourgeist = true; | ||
} | ||
_ => {} | ||
} | ||
} | ||
|
||
Ok(Self { | ||
virtualenv, | ||
gourgeist, | ||
}) | ||
} | ||
|
||
/// Returns true if the virtual environment was created with the `virtualenv` package. | ||
pub fn is_virtualenv(&self) -> bool { | ||
self.virtualenv | ||
} | ||
|
||
/// Returns true if the virtual environment was created with the `gourgeist` package. | ||
pub fn is_gourgeist(&self) -> bool { | ||
self.gourgeist | ||
} | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Io(#[from] std::io::Error), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters