//! JetBrains run configuration import. The fixtures are synthetic: they follow the structure //! PyCharm and WebStorm write (`.run/*.run.xml`, `.idea/workspace.xml`), with invented names and values. use ide_run::RunConfig; use ide_run::import::{RunImport, RunImportSource, SkipReason, available, import}; use std::collections::BTreeMap; use std::fs; use std::path::{Path, PathBuf}; /// IDEA joins `ENV_FILES` with `File.pathSeparator`. const SEP: char = if cfg!(windows) { ';' } else { ':' }; const VENV_PYTHON: &str = if cfg!(windows) { ".venv/Scripts/python.exe" } else { ".venv/bin/python" }; fn env() -> BTreeMap { BTreeMap::from([("HOME".into(), "/home/me".into()), ("USERPROFILE".into(), "/home/me".into())]) } fn write(root: &Path, rel: &str, text: &str) { let path = root.join(rel); fs::create_dir_all(path.parent().unwrap()).unwrap(); fs::write(path, text).unwrap(); } fn run_file(name: &str, body: &str) -> String { format!( "\n {}\n\n", body.replace("name=\"NAME\"", &format!("name=\"{name}\"")) ) } fn workspace(configs: &str) -> String { format!( "\n\n \n \ \n{configs}\n \n \n \ \n \n\n" ) } fn import_from(root: &Path, existing: &[RunConfig]) -> RunImport { import(root, RunImportSource::Jetbrains, existing, &env()).unwrap() } fn get<'a>(r: &'a RunImport, name: &str) -> &'a RunConfig { &r.imported.iter().find(|c| c.config.name == name).unwrap_or_else(|| panic!("{name} not imported: {r:#?}")).config } fn ignored<'a>(r: &'a RunImport, name: &str) -> &'a [String] { &r.imported.iter().find(|c| c.config.name == name).unwrap().ignored } fn reason<'a>(r: &'a RunImport, name: &str) -> &'a SkipReason { &r.skipped.iter().find(|s| s.name == name).unwrap_or_else(|| panic!("{name} not skipped: {r:#?}")).reason } fn s(v: &[&str]) -> Vec { v.iter().map(|a| (*a).to_owned()).collect() } fn cwd(c: &RunConfig) -> Option { c.cwd.as_ref().map(|p| p.as_ref().to_path_buf()) } /// A Django project in `src/` with a root virtualenv. fn django_project() -> tempfile::TempDir { let dir = tempfile::tempdir().unwrap(); write(dir.path(), "src/manage.py", ""); write(dir.path(), VENV_PYTHON, ""); dir } const PY_COMMON: &str = r#"