Skip to content

Commit 6b94d99

Browse files
authored
Merge pull request #426 from sanders41/just
Fix justfile for setuptools
2 parents 6ffaf4a + 9b8cb13 commit 6b94d99

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

src/project_generator.rs

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ fn save_dev_requirements(project_info: &ProjectInfo) -> Result<()> {
489489
Ok(())
490490
}
491491

492-
fn create_justfile(module: &str) -> String {
492+
fn create_poetry_justfile(module: &str) -> String {
493493
format!(
494494
r#"@lint:
495495
echo mypy
@@ -517,16 +517,6 @@ fn create_justfile(module: &str) -> String {
517517
)
518518
}
519519

520-
fn save_justfile(project_info: &ProjectInfo) -> Result<()> {
521-
let module = project_info.source_dir.replace([' ', '-'], "_");
522-
let file_path = project_info.base_dir().join("justfile");
523-
let content = create_justfile(&module);
524-
525-
save_file_with_content(&file_path, &content)?;
526-
527-
Ok(())
528-
}
529-
530520
fn create_pyo3_justfile(module: &str) -> String {
531521
format!(
532522
r#"@develop:
@@ -573,10 +563,42 @@ fn create_pyo3_justfile(module: &str) -> String {
573563
)
574564
}
575565

576-
fn save_pyo3_justfile(project_info: &ProjectInfo) -> Result<()> {
566+
fn create_setuptools_justfile(module: &str) -> String {
567+
format!(
568+
r#"@lint:
569+
echo mypy
570+
just --justfile {{{{justfile()}}}} mypy
571+
echo ruff
572+
just --justfile {{{{justfile()}}}} ruff
573+
echo ruff-format
574+
just --justfile {{{{justfile()}}}} ruff-format
575+
576+
@mypy:
577+
python -m mypy {module} tests
578+
579+
@ruff:
580+
python -m ruff check {module} tests
581+
582+
@ruff-format:
583+
python -m ruff format {module} tests
584+
585+
@test:
586+
-python -m pytest -x
587+
588+
@install:
589+
python -m pip install -r requirements-dev.txt
590+
"#
591+
)
592+
}
593+
594+
fn save_justfile(project_info: &ProjectInfo) -> Result<()> {
577595
let module = project_info.source_dir.replace([' ', '-'], "_");
578596
let file_path = project_info.base_dir().join("justfile");
579-
let content = create_pyo3_justfile(&module);
597+
let content = match &project_info.project_manager {
598+
ProjectManager::Poetry => create_poetry_justfile(&module),
599+
ProjectManager::Maturin => create_pyo3_justfile(&module),
600+
ProjectManager::Setuptools => create_setuptools_justfile(&module),
601+
};
580602

581603
save_file_with_content(&file_path, &content)?;
582604

@@ -643,7 +665,7 @@ pub fn generate_project(project_info: &ProjectInfo) -> Result<()> {
643665
bail!("Error creating requirements-dev.txt file");
644666
}
645667

646-
if save_pyo3_justfile(project_info).is_err() {
668+
if save_justfile(project_info).is_err() {
647669
bail!("Error creating justfile");
648670
}
649671

@@ -1082,7 +1104,7 @@ mod tests {
10821104
let base = project_info.base_dir();
10831105
create_dir_all(&base).unwrap();
10841106
let expected_file = base.join("justfile");
1085-
save_pyo3_justfile(&project_info).unwrap();
1107+
save_justfile(&project_info).unwrap();
10861108

10871109
assert!(expected_file.is_file());
10881110

src/snapshots/python_project__project_generator__tests__save_justfile_setuptools.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
source: src/project_generator.rs
33
expression: content
44
---
5-
"@lint:\n echo mypy\n just --justfile {{justfile()}} mypy\n echo ruff\n just --justfile {{justfile()}} ruff\n echo ruff-format\n just --justfile {{justfile()}} ruff-format\n\n@mypy:\n poetry run mypy my_project tests\n\n@ruff:\n poetry run ruff check my_project tests\n\n@ruff-format:\n poetry run ruff format my_project tests\n\n@test:\n -poetry run pytest -x\n\n@install:\n poetry install\n"
5+
"@lint:\n echo mypy\n just --justfile {{justfile()}} mypy\n echo ruff\n just --justfile {{justfile()}} ruff\n echo ruff-format\n just --justfile {{justfile()}} ruff-format\n\n@mypy:\n python -m mypy my_project tests\n\n@ruff:\n python -m ruff check my_project tests\n\n@ruff-format:\n python -m ruff format my_project tests\n\n@test:\n -python -m pytest -x\n\n@install:\n python -m pip install -r requirements-dev.txt\n"

0 commit comments

Comments
 (0)