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:
parent
d79f6f365d
commit
2b0010ffe3
|
@ -109,7 +109,7 @@ fn get_prompt_from_venv(venv_path: &Path) -> Option<String> {
|
||||||
.ok()?
|
.ok()?
|
||||||
.general_section()
|
.general_section()
|
||||||
.get("prompt")
|
.get("prompt")
|
||||||
.map(String::from)
|
.map(|prompt| String::from(prompt.trim_matches(&['(', ')'] as &[_])))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -365,6 +365,33 @@ prompt = 'foo'
|
||||||
dir.close()
|
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>) {
|
fn check_python2_renders(dir: &tempfile::TempDir, starship_config: Option<toml::Value>) {
|
||||||
let config = starship_config.unwrap_or(toml::toml! {
|
let config = starship_config.unwrap_or(toml::toml! {
|
||||||
[python]
|
[python]
|
||||||
|
|
Loading…
Reference in New Issue