feat(python): Remove parentheses from pyvenv.cfg prompt parameter (#2551)

* Remove parentheses from pyvenv.cfg prompt

* Apply suggestions from initial code review

Co-authored-by: Dario Vladović <d.vladimyr@gmail.com>

Co-authored-by: Dario Vladović <d.vladimyr@gmail.com>
This commit is contained in:
Charles Swartz 2021-04-05 10:51:01 -04:00 committed by GitHub
parent d79f6f365d
commit 2b0010ffe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 1 deletions

View File

@ -109,7 +109,7 @@ fn get_prompt_from_venv(venv_path: &Path) -> Option<String> {
.ok()?
.general_section()
.get("prompt")
.map(String::from)
.map(|prompt| String::from(prompt.trim_matches(&['(', ')'] as &[_])))
}
#[cfg(test)]
@ -365,6 +365,33 @@ prompt = 'foo'
dir.close()
}
#[test]
fn with_active_venv_and_dirty_prompt() -> io::Result<()> {
let dir = tempfile::tempdir()?;
create_dir_all(dir.path().join("my_venv"))?;
let mut venv_cfg = File::create(dir.path().join("my_venv").join("pyvenv.cfg"))?;
venv_cfg.write_all(
br#"
home = something
prompt = '(foo)'
"#,
)?;
venv_cfg.sync_all()?;
let actual = ModuleRenderer::new("python")
.path(dir.path())
.env("VIRTUAL_ENV", dir.path().join("my_venv").to_str().unwrap())
.collect();
let expected = Some(format!(
"via {}",
Color::Yellow.bold().paint("🐍 v3.8.0 (foo) ")
));
assert_eq!(actual, expected);
dir.close()
}
fn check_python2_renders(dir: &tempfile::TempDir, starship_config: Option<toml::Value>) {
let config = starship_config.unwrap_or(toml::toml! {
[python]