diff --git a/README.md b/README.md index 71a6031..d9be6c0 100644 --- a/README.md +++ b/README.md @@ -199,24 +199,6 @@ python-project create -s docs are referencing. For example in this repository the repo url would be `https://github.com/sanders41/python-project-generator` -- Extra Python Dependencies - - These are extra packages you want to include in the project that are not provided by default. - For example specifying `fastapi, camel-converter` here will inculde these two packages in the - dependencies. If the project is an application the version will be pinned to the latest release - of the packages, and if it is a library the latest release will be used for the minimum version. - If you would like to specify a specific version instead you can by specifying the version with an - `@`. For example `fastapi@0.115.0, camel-converter@4.0.0`. When creating an appliction FastAPI - will be pinned to `0.115.0` and Camel Converter will be pinned to `4.0.0`, or if creating a - library these versions will be used for the minimum version. - -- Extra Python Dev Dependencies - - These are extra packages you want to include in the project's dev dependencies that are not - provided by default. For example specifying `pytest-xdist` here will include this package in the - dev dependencies. If you would like to specify a specific version instead of checking for the - latest you can by specifying the version with an `@`. For example `pytest-xdist@3.6.1`. - After running the generator a new directory will be created with the name you used for the `Project Slug`. Change to this directory then install the python packages and pre-commit hooks. diff --git a/src/cli.rs b/src/cli.rs index a280588..4949f59 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -167,18 +167,6 @@ pub enum Param { /// Remove the save download latest packages value ResetDownloadLatestPackages, - /// Extra Python dependencies to include in the project - ExtraPythonPackages { value: Vec }, - - /// Remove the saved extra Python dependencies - ResetExtraPythonPackages, - - /// Extra Python dev dependencies to include in the project - ExtraPythonDevPackages { value: Vec }, - - /// Remove the saved extra Python dev dependencies - ResetExtraPythonDevPackages, - /// Rerset the config to the default values Reset, diff --git a/src/config.rs b/src/config.rs index 6d6d258..0d49d90 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,8 +35,6 @@ pub struct Config { pub use_multi_os_ci: Option, pub include_docs: Option, pub download_latest_packages: Option, - pub extra_python_packages: Option>, - pub extra_python_dev_packages: Option>, #[serde(skip)] config_dir: Rc>, @@ -66,8 +64,6 @@ impl Default for Config { use_multi_os_ci: None, include_docs: None, download_latest_packages: None, - extra_python_packages: None, - extra_python_dev_packages: None, config_dir: config_dir(), config_file_path: config_file_path(), } @@ -101,8 +97,6 @@ impl Config { use_multi_os_ci: config.use_multi_os_ci, include_docs: config.include_docs, download_latest_packages: config.download_latest_packages, - extra_python_packages: config.extra_python_packages, - extra_python_dev_packages: config.extra_python_dev_packages, config_dir: self.config_dir.clone(), config_file_path: self.config_file_path.clone(), }; @@ -362,26 +356,6 @@ impl Config { Ok(()) } - pub fn save_extra_python_packages(&self, value: Vec) -> Result<()> { - self.handle_save_config(|config| &mut config.extra_python_packages, Some(value))?; - Ok(()) - } - - pub fn reset_extra_python_packages(&self) -> Result<()> { - self.handle_save_config(|config| &mut config.extra_python_packages, None)?; - Ok(()) - } - - pub fn save_extra_python_dev_packages(&self, value: Vec) -> Result<()> { - self.handle_save_config(|config| &mut config.extra_python_packages, Some(value))?; - Ok(()) - } - - pub fn reset_extra_python_dev_packages(&self) -> Result<()> { - self.handle_save_config(|config| &mut config.extra_python_packages, None)?; - Ok(()) - } - fn handle_save_config(&self, func: F, value: Option) -> Result<()> where F: FnOnce(&mut Self) -> &mut Option, @@ -436,26 +410,6 @@ impl Config { print_config_value("Use Multi OS CI", &config.use_multi_os_ci); print_config_value("Include Docs", &config.include_docs); print_config_value("Download Latest Packages", &config.download_latest_packages); - let extra_python_packages_label = "Extra Python Packages"; - if let Some(extra_python_packages) = config.extra_python_packages { - let extra_python_packages_str = extra_python_packages.join(", "); - println!( - "{}: {extra_python_packages_str}", - extra_python_packages_label.blue() - ); - } else { - println!("{}: null", extra_python_packages_label.blue()); - } - let extra_python_dev_packages_label = "Extra Python Dev Packages"; - if let Some(extra_python_dev_packages) = config.extra_python_dev_packages { - let extra_python_dev_packages_str = extra_python_dev_packages.join(", "); - println!( - "{}: {extra_python_dev_packages_str}", - extra_python_dev_packages_label.blue() - ); - } else { - println!("{}: null", extra_python_dev_packages_label.blue()); - } } } diff --git a/src/github_actions.rs b/src/github_actions.rs index e584b30..1fa8538 100644 --- a/src/github_actions.rs +++ b/src/github_actions.rs @@ -1580,8 +1580,6 @@ mod tests { use_multi_os_ci: true, include_docs: false, docs_info: None, - extra_python_packages: None, - extra_python_dev_packages: None, download_latest_packages: false, project_root_dir: Some(tempdir().unwrap().path().to_path_buf()), } diff --git a/src/licenses.rs b/src/licenses.rs index 9c48cd4..0f7b8ad 100644 --- a/src/licenses.rs +++ b/src/licenses.rs @@ -289,8 +289,6 @@ mod tests { use_multi_os_ci: true, include_docs: false, docs_info: None, - extra_python_packages: None, - extra_python_dev_packages: None, download_latest_packages: false, project_root_dir: Some(tempdir().unwrap().path().to_path_buf()), } diff --git a/src/main.rs b/src/main.rs index cfb897c..cb6be41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -389,30 +389,6 @@ fn main() { exit(1); } } - Param::ExtraPythonPackages { value } => { - if let Err(e) = Config::default().save_extra_python_packages(value) { - print_error(e); - exit(1); - } - } - Param::ResetExtraPythonPackages {} => { - if let Err(e) = Config::default().reset_extra_python_packages() { - print_error(e); - exit(1); - } - } - Param::ExtraPythonDevPackages { value } => { - if let Err(e) = Config::default().save_extra_python_dev_packages(value) { - print_error(e); - exit(1); - } - } - Param::ResetExtraPythonDevPackages {} => { - if let Err(e) = Config::default().reset_extra_python_dev_packages() { - print_error(e); - exit(1); - } - } Param::Reset => { if Config::reset().is_err() { let message = "Error resetting config."; @@ -468,8 +444,6 @@ mod tests { use_multi_os_ci: true, include_docs: false, docs_info: None, - extra_python_packages: None, - extra_python_dev_packages: None, download_latest_packages: false, project_root_dir: Some(base), }; diff --git a/src/package_version.rs b/src/package_version.rs index 7be7d79..cb82daa 100644 --- a/src/package_version.rs +++ b/src/package_version.rs @@ -137,27 +137,6 @@ impl PythonPackageVersion { } } -#[derive(Debug)] -pub struct ExtraPythonPackageVersion { - pub package: String, - pub version: String, -} - -impl ExtraPythonPackageVersion { - pub fn new(package: String) -> Result { - if let Some(p) = package.split_once("@") { - Ok(ExtraPythonPackageVersion { - package: p.0.to_string(), - version: p.1.to_string(), - }) - } else { - let version = get_latest_python_version(&package)?; - - Ok(ExtraPythonPackageVersion { package, version }) - } - } -} - #[derive(Debug)] pub struct RustPackageVersion { pub name: String, diff --git a/src/project_generator.rs b/src/project_generator.rs index 0172422..e531222 100644 --- a/src/project_generator.rs +++ b/src/project_generator.rs @@ -12,8 +12,7 @@ use crate::github_actions::{ }; use crate::licenses::{generate_license, license_str}; use crate::package_version::{ - ExtraPythonPackageVersion, LatestVersion, PreCommitHook, PreCommitHookVersion, PythonPackage, - PythonPackageVersion, + LatestVersion, PreCommitHook, PreCommitHookVersion, PythonPackage, PythonPackageVersion, }; use crate::project_info::{ProjectInfo, ProjectManager, Pyo3PythonManager}; use crate::python_files::generate_python_files; @@ -433,31 +432,6 @@ fn build_latest_dev_dependencies(project_info: &ProjectInfo) -> Result { } } - if let Some(extras) = &project_info.extra_python_dev_packages { - for extra in extras { - if let Ok(p) = ExtraPythonPackageVersion::new(extra.to_lowercase().clone()) { - match project_info.project_manager { - ProjectManager::Poetry => { - version_string.push_str(&format!("{} = \"{}\"\n", p.package, p.version)) - } - ProjectManager::Uv => { - version_string.push_str(&format!(" \"{}=={}\",\n", p.package, p.version)) - } - ProjectManager::Pixi => { - version_string.push_str(&format!(" \"{}=={}\",\n", p.package, p.version)) - } - _ => version_string.push_str(&format!("{}=={}\n", p.package, p.version)), - } - } else { - let error_message = format!( - "Error retrieving latest python package version for {}, skipping.", - extra - ); - println!("\n{}", error_message.yellow()); - } - } - } - match project_info.project_manager { ProjectManager::Poetry => Ok(version_string.trim().to_string()), ProjectManager::Uv => { @@ -491,56 +465,10 @@ fn build_latest_dev_dependencies(project_info: &ProjectInfo) -> Result { } } -fn build_extra_python_dependencies(project_info: &ProjectInfo) -> Result { - if let Some(extra_python_packages) = &project_info.extra_python_packages { - let mut version_string = if let ProjectManager::Poetry = project_info.project_manager { - String::new() - } else { - "[\n".to_string() - }; - for package in extra_python_packages { - if let Ok(p) = ExtraPythonPackageVersion::new(package.to_lowercase().clone()) { - if let ProjectManager::Poetry = project_info.project_manager { - if project_info.is_application { - version_string.push_str(&format!("{} = \"{}\"\n", p.package, p.version)); - } else { - version_string.push_str(&format!("{} = \">={}\"\n", p.package, p.version)); - } - } else if project_info.is_application { - version_string.push_str(&format!(" \"{}=={}\",\n", p.package, p.version)); - } else { - version_string.push_str(&format!(" \"{}>={}\",\n", p.package, p.version)); - } - } else { - let error_message = format!( - "Error retrieving latest python package version for {}, skipping.", - package - ); - println!("\n{}", error_message.yellow()); - } - } - - if let ProjectManager::Poetry = project_info.project_manager { - Ok(version_string.trim().to_string()) - } else { - version_string.push(']'); - Ok(version_string) - } - } else { - bail!("No extra python packages provided"); - } -} - fn create_pyproject_toml(project_info: &ProjectInfo) -> Result { let module = project_info.source_dir.replace([' ', '-'], "_"); let pyupgrade_version = &project_info.min_python_version.replace(['.', '^'], ""); let license_text = license_str(&project_info.license); - let dependencies = if project_info.extra_python_packages.is_some() { - let d = build_extra_python_dependencies(project_info)?; - Some(d) - } else { - None - }; let mut pyproject = match &project_info.project_manager { ProjectManager::Maturin => { if let Some(pyo3_python_manager) = &project_info.pyo3_python_manager { @@ -560,11 +488,7 @@ license = { file = "LICENSE" } {% endif -%} readme = "README.md" requires-python = ">={{ min_python_version }}" -{%- if dependencies %} -dependencies = {{ dependencies }} -{%- else %} dependencies = [] -{%- endif %} [dependency-groups] dev = {{ dev_dependencies }} @@ -588,11 +512,7 @@ authors = [{name = "{{ creator }}", email = "{{ creator_email }}"}] license = "{{ license }}" {% endif -%} readme = "README.md" -{%- if dependencies %} -dependencies = {{ dependencies }} -{%- else %} dependencies = [] -{%- endif %} [tool.maturin] module-name = "{{ module }}._{{ module }}" @@ -618,9 +538,6 @@ readme = "README.md" [tool.poetry.dependencies] python = "^{{ min_python_version }}" -{%- if dependencies %} -{{ dependencies }} -{%- endif %} [tool.poetry.group.dev.dependencies] {{ dev_dependencies }} @@ -646,11 +563,7 @@ license = { text = "{{ license }}" } {% endif -%} requires-python = ">={{ min_python_version }}" dynamic = ["version", "readme"] -{%- if dependencies %} -dependencies = {{ dependencies }} -{%- else %} dependencies = [] -{%- endif %} [tool.setuptools.dynamic] version = {attr = "{{ module }}.__version__"} @@ -680,11 +593,7 @@ license = { file = "LICENSE" } readme = "README.md" requires-python = ">={{ min_python_version }}" dynamic = ["version"] -{%- if dependencies %} -dependencies = {{ dependencies }} -{%- else %} dependencies = [] -{%- endif %} [dependency-groups] dev = {{ dev_dependencies }} @@ -710,11 +619,7 @@ license = { file = "LICENSE" } readme = "README.md" requires-python = ">={{ min_python_version }}" dynamic = ["version"] -{%- if dependencies %} -dependencies = {{ dependencies }} -{%- else %} dependencies = [] -{%- endif %} [tool.pixi.project] channels = ["conda-forge", "bioconda"] @@ -814,7 +719,6 @@ ignore=[ creator_email => project_info.creator_email, license => license_text, min_python_version => project_info.min_python_version, - dependencies => dependencies, dev_dependencies => build_latest_dev_dependencies(project_info)?, max_line_length => project_info.max_line_length, module => module, @@ -1391,8 +1295,6 @@ mod tests { use_multi_os_ci: true, include_docs: false, docs_info: None, - extra_python_packages: None, - extra_python_dev_packages: None, download_latest_packages: false, project_root_dir: Some(tempdir().unwrap().path().to_path_buf()), } @@ -1478,77 +1380,6 @@ mod tests { ]}, { assert_yaml_snapshot!(content)}); } - #[test] - fn test_save_poetry_pyproject_toml_application_with_python_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Poetry; - project_info.is_application = true; - project_info.extra_python_packages = Some(vec![ - "fastapi@0.115.0".to_string(), - "camel-converter@4.0.0".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r#""\d+\.\d+\.\d+"#, "\"1.0.0"), - (r#"">=\d+\.\d+\.\d+"#, "\">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - - #[test] - fn test_save_poetry_pyproject_toml_lib_with_python_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Poetry; - project_info.is_application = false; - project_info.extra_python_packages = Some(vec![ - "fastapi@0.115.0".to_string(), - "camel-converter@4.0.0".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r#""\d+\.\d+\.\d+"#, "\"1.0.0"), - (r#"">=\d+\.\d+\.\d+"#, "\">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - - #[test] - fn test_save_poetry_pyproject_toml_with_python_dev_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Poetry; - project_info.extra_python_dev_packages = Some(vec![ - "pytest-xdist@3.6.1".to_string(), - "types-ujson@5.10.0.20240515".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r#""\d+\.\d+\.\d+"#, "\"1.0.0"), - (r#"">=\d+\.\d+\.\d+"#, "\">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - #[test] fn test_save_poetry_pyproject_toml_file_apache_application() { let mut project_info = project_info_dummy(); @@ -1633,77 +1464,6 @@ mod tests { ]}, { assert_yaml_snapshot!(content)}); } - #[test] - fn test_save_pyproject_toml_file_pyo3_application_with_python_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Maturin; - project_info.is_application = true; - project_info.extra_python_packages = Some(vec![ - "fastapi@0.115.0".to_string(), - "camel-converter@4.0.0".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - - #[test] - fn test_save_pyproject_toml_file_pyo3_lib_with_python_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Maturin; - project_info.is_application = false; - project_info.extra_python_packages = Some(vec![ - "fastapi@0.115.0".to_string(), - "camel-converter@4.0.0".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - - #[test] - fn test_save_pyo3_pyproject_toml_with_python_dev_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Maturin; - project_info.extra_python_dev_packages = Some(vec![ - "pytest-xdist@3.6.1".to_string(), - "types-ujson@5.10.0.20240515".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - #[test] fn test_save_pyproject_toml_file_apache_pyo3() { let mut project_info = project_info_dummy(); @@ -1767,74 +1527,6 @@ mod tests { ]}, { assert_yaml_snapshot!(content)}); } - #[test] - fn test_save_pyproject_toml_file_setuptools_application_with_python_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Setuptools; - project_info.is_application = true; - project_info.extra_python_packages = Some(vec![ - "fastapi@0.115.0".to_string(), - "camel-converter@4.0.0".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - - #[test] - fn test_save_pyproject_toml_file_setuptools_lib_with_python_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Setuptools; - project_info.is_application = false; - project_info.extra_python_packages = Some(vec![ - "fastapi@0.115.0".to_string(), - "camel-converter@4.0.0".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - - #[test] - fn test_save_setuptools_pyproject_toml_with_python_dev_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Setuptools; - project_info.extra_python_dev_packages = Some(vec![ - "pytest-xdist@3.6.1".to_string(), - "types-ujson@5.10.0.20240515".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - assert_yaml_snapshot!(content); - } - #[test] fn test_save_setuptools_pyproject_toml_file_apache_application() { let mut project_info = project_info_dummy(); @@ -1919,77 +1611,6 @@ mod tests { ]}, { assert_yaml_snapshot!(content)}); } - #[test] - fn test_save_pyproject_toml_file_uv_application_with_python_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Uv; - project_info.is_application = true; - project_info.extra_python_packages = Some(vec![ - "fastapi@0.115.0".to_string(), - "camel-converter@4.0.0".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - - #[test] - fn test_save_pyproject_toml_file_uv_lib_with_python_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Uv; - project_info.is_application = false; - project_info.extra_python_packages = Some(vec![ - "fastapi@0.115.0".to_string(), - "camel-converter@4.0.0".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - - #[test] - fn test_save_uv_pyproject_toml_with_python_dev_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Uv; - project_info.extra_python_dev_packages = Some(vec![ - "pytest-xdist@3.6.1".to_string(), - "types-ujson@5.10.0.20240515".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - #[test] fn test_save_uv_pyproject_toml_file_apache_application() { let mut project_info = project_info_dummy(); @@ -2074,77 +1695,6 @@ mod tests { ]}, { assert_yaml_snapshot!(content)}); } - #[test] - fn test_save_pyproject_toml_file_pixi_application_with_python_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Pixi; - project_info.is_application = true; - project_info.extra_python_packages = Some(vec![ - "fastapi@0.115.0".to_string(), - "camel-converter@4.0.0".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - - #[test] - fn test_save_pyproject_toml_file_pixi_lib_with_python_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Pixi; - project_info.is_application = false; - project_info.extra_python_packages = Some(vec![ - "fastapi@0.115.0".to_string(), - "camel-converter@4.0.0".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - - #[test] - fn test_save_pixi_pyproject_toml_with_python_dev_extras() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Pixi; - project_info.extra_python_dev_packages = Some(vec![ - "pytest-xdist@3.6.1".to_string(), - "types-ujson@5.10.0.20240515".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("pyproject.toml"); - save_pyproject_toml_file(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - #[test] fn test_save_pixi_pyproject_toml_file_apache_application() { let mut project_info = project_info_dummy(); @@ -2266,29 +1816,6 @@ mod tests { ]}, { assert_yaml_snapshot!(content)}); } - #[test] - fn test_save_pyo3_dev_requirements_extras_file() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Maturin; - project_info.extra_python_dev_packages = Some(vec![ - "pytest-xdist@3.6.1".to_string(), - "types-ujson@5.10.0.20240515".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("requirements-dev.txt"); - save_dev_requirements(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - #[test] fn test_save_setuptools_dev_requirements_application_file() { let mut project_info = project_info_dummy(); @@ -2331,29 +1858,6 @@ mod tests { ]}, { assert_yaml_snapshot!(content)}); } - #[test] - fn test_save_setuptools_dev_requirements_extras_file() { - let mut project_info = project_info_dummy(); - project_info.project_manager = ProjectManager::Setuptools; - project_info.extra_python_dev_packages = Some(vec![ - "pytest-xdist@3.6.1".to_string(), - "types-ujson@5.10.0.20240515".to_string(), - ]); - let base = project_info.base_dir(); - create_dir_all(&base).unwrap(); - let expected_file = base.join("requirements-dev.txt"); - save_dev_requirements(&project_info).unwrap(); - - assert!(expected_file.is_file()); - - let content = std::fs::read_to_string(expected_file).unwrap(); - - insta::with_settings!({filters => vec![ - (r"==\d+\.\d+\.\d+", "==1.0.0"), - (r">=\d+\.\d+\.\d+", ">=1.0.0"), - ]}, { assert_yaml_snapshot!(content)}); - } - #[test] fn test_save_mkdocs_yaml() { let mut project_info = project_info_dummy(); diff --git a/src/project_info.rs b/src/project_info.rs index 59a194b..11e998c 100644 --- a/src/project_info.rs +++ b/src/project_info.rs @@ -141,31 +141,6 @@ impl Prompt { Ok(input.trim().to_string()) } - - fn show_optional_prompt(&self) -> Result> { - let mut input = String::new(); - - if let Some(d) = &self.default { - print!("{} ({d}): ", self.prompt_text); - } else { - print!("{}: ", self.prompt_text); - } - - std::io::stdout().flush().unwrap(); - std::io::stdin() - .read_line(&mut input) - .expect("Error: Could not read a line"); - - if input.trim() == "" { - if let Some(d) = &self.default { - return Ok(Some(d.to_string())); - } else { - return Ok(None); - } - } - - Ok(Some(input.trim().to_string())) - } } #[derive(Debug)] @@ -206,8 +181,6 @@ pub struct ProjectInfo { pub include_docs: bool, pub docs_info: Option, pub download_latest_packages: bool, - pub extra_python_packages: Option>, - pub extra_python_dev_packages: Option>, pub project_root_dir: Option, } @@ -297,37 +270,6 @@ fn default_or_prompt_string( Ok(result) } -fn option_vec_string_prompt( - prompt_text: String, - default: Option>, -) -> Result>> { - let default = default.map(|d| d.join(", ")); - let prompt = Prompt { - prompt_text, - default, - }; - if let Some(value) = prompt.show_optional_prompt()? { - let values = value.split(",").map(|v| v.trim().to_string()).collect(); - Ok(Some(values)) - } else { - Ok(None) - } -} - -fn default_or_prompt_option_vec_string( - prompt_text: String, - default: Option>, - use_defaults: bool, -) -> Result>> { - if use_defaults { - return Ok(default); - } - - let result = option_vec_string_prompt(prompt_text, default)?; - - Ok(result) -} - fn dependabot_day_prompt(default: Option) -> Result> { let default_str = match default { Some(s) => match s { @@ -732,18 +674,6 @@ pub fn get_project_info(use_defaults: bool) -> Result { None }; - let extra_python_packages = default_or_prompt_option_vec_string( - "Extra Python Dependencies".to_string(), - config.extra_python_packages, - use_defaults, - )?; - - let extra_python_dev_packages = default_or_prompt_option_vec_string( - "Extra Python Dev Dependencies".to_string(), - config.extra_python_dev_packages, - use_defaults, - )?; - Ok(ProjectInfo { project_name, project_slug, @@ -770,8 +700,6 @@ pub fn get_project_info(use_defaults: bool) -> Result { use_multi_os_ci, include_docs, docs_info, - extra_python_packages, - extra_python_dev_packages, download_latest_packages: false, project_root_dir: None, }) diff --git a/src/python_files.rs b/src/python_files.rs index 49cd195..63d7bd5 100644 --- a/src/python_files.rs +++ b/src/python_files.rs @@ -401,8 +401,6 @@ mod tests { use_multi_os_ci: true, include_docs: false, docs_info: None, - extra_python_packages: None, - extra_python_dev_packages: None, download_latest_packages: false, project_root_dir: Some(tempdir().unwrap().path().to_path_buf()), } diff --git a/src/rust_files.rs b/src/rust_files.rs index 60a2d76..8b3c570 100644 --- a/src/rust_files.rs +++ b/src/rust_files.rs @@ -165,8 +165,6 @@ mod tests { use_multi_os_ci: true, include_docs: false, docs_info: None, - extra_python_packages: None, - extra_python_dev_packages: None, download_latest_packages: false, project_root_dir: Some(tempdir().unwrap().path().to_path_buf()), }