Skip to content

Commit a38431c

Browse files
authored
Merge pull request #63 from sanders41/project-manager
Project manager
2 parents 14fd6bb + c9571fa commit a38431c

File tree

9 files changed

+200
-146
lines changed

9 files changed

+200
-146
lines changed

.github/workflows/testing.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ jobs:
7979
- name: Build package
8080
run: cargo build --release
8181
- name: Run creation
82-
run: ./scripts/ci_run.sh ${{ matrix.project_type }} 2
82+
run: |
83+
./scripts/ci_run.sh ${{ matrix.project_type }} 1
8384
- name: Cache poetry venv
8485
uses: actions/cache@v3
8586
id: poetry-cache
@@ -121,7 +122,7 @@ jobs:
121122
- name: Build package
122123
run: cargo build --release
123124
- name: Run creation
124-
run: ./scripts/ci_run.sh ${{ matrix.project_type }} 1
125+
run: ./scripts/ci_run.sh ${{ matrix.project_type }} 2
125126
- name: Install Dependencies
126127
working-directory: my-project
127128
run: |

scripts/ci_run.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ python_version=""
1313
min_python_version=""
1414
gha_versions=""
1515
application=""
16-
use_pyo3="2"
16+
project_manager="1"
1717

18-
# Check for user provided pyo3 input
18+
# Check for user provided project manager input
1919
if [ $# -gt 1 ]; then
20-
echo "HI"
2120
if [ $2 -lt 1 ] || [ $2 -gt 2 ]; then
22-
echo "Invalid use_pyo3 value"
21+
echo "Invalid project_manager value"
2322
exit 1
2423
else
25-
use_pyo3=$2
24+
project_manager=$2
2625
fi
2726
fi
2827

@@ -57,7 +56,7 @@ $version
5756
$python_version
5857
$min_python_version
5958
$gha_versions
60-
$use_pyo3
59+
$project_manager
6160
$application
6261
$max_line_length
6362
$use_dependabot

src/cli.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clap::{Parser, Subcommand, ValueEnum};
22

3-
use crate::project_info::LicenseType;
3+
use crate::project_info::{LicenseType, ProjectManager};
44

55
#[derive(Clone, Debug, ValueEnum)]
66
pub enum ApplicationOrLib {
@@ -81,10 +81,10 @@ pub enum Param {
8181
value: String,
8282
},
8383

84-
/// Use pyo3
85-
UsePyo3 {
86-
#[clap(help = "Use pyo3")]
87-
value: BooleanChoice,
84+
/// Save a default project manager
85+
ProjectManager {
86+
#[clap(help = "Default project manager")]
87+
value: ProjectManager,
8888
},
8989

9090
/// Save a default value for Is Application

src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use anyhow::{bail, Result};
55
use colored::*;
66
use serde::{Deserialize, Serialize};
77

8-
use crate::project_info::{is_valid_python_version, LicenseType};
8+
use crate::project_info::{is_valid_python_version, LicenseType, ProjectManager};
99

1010
#[derive(Debug, Deserialize, Serialize)]
1111
pub struct Config {
@@ -14,7 +14,7 @@ pub struct Config {
1414
pub license: Option<LicenseType>,
1515
pub python_version: Option<String>,
1616
pub min_python_version: Option<String>,
17-
pub use_pyo3: Option<bool>,
17+
pub project_manager: Option<ProjectManager>,
1818
pub is_application: Option<bool>,
1919
pub github_actions_python_test_versions: Option<Vec<String>>,
2020
pub max_line_length: Option<u8>,
@@ -33,7 +33,7 @@ impl Config {
3333
license: None,
3434
python_version: None,
3535
min_python_version: None,
36-
use_pyo3: None,
36+
project_manager: None,
3737
is_application: None,
3838
github_actions_python_test_versions: None,
3939
max_line_length: None,
@@ -156,9 +156,9 @@ impl Config {
156156
Ok(())
157157
}
158158

159-
pub fn save_use_pyo3(value: bool) -> Result<()> {
159+
pub fn save_project_manager(value: ProjectManager) -> Result<()> {
160160
if let Ok(mut config) = Config::load_config() {
161-
config.use_pyo3 = Some(value);
161+
config.project_manager = Some(value);
162162
if config.save().is_err() {
163163
raise_error()?;
164164
}

src/github_actions.rs

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::PathBuf;
33
use anyhow::Result;
44

55
use crate::file_manager::save_file_with_content;
6+
use crate::project_info::ProjectManager;
67

78
fn build_actions_python_test_versions(github_action_python_test_versions: &[String]) -> String {
89
github_action_python_test_versions
@@ -245,7 +246,7 @@ pub fn save_ci_testing_linux_only_file(
245246
source_dir: &str,
246247
min_python_version: &str,
247248
github_action_python_test_versions: &[String],
248-
use_pyo3: bool,
249+
project_manager: &ProjectManager,
249250
project_root_dir: &Option<PathBuf>,
250251
) -> Result<()> {
251252
let file_path = match project_root_dir {
@@ -255,18 +256,17 @@ pub fn save_ci_testing_linux_only_file(
255256
),
256257
None => format!("{project_slug}/.github/workflows/testing.yml"),
257258
};
258-
let content = if use_pyo3 {
259-
create_ci_testing_linux_only_file_pyo3(
259+
let content = match project_manager {
260+
ProjectManager::Maturin => create_ci_testing_linux_only_file_pyo3(
260261
source_dir,
261262
min_python_version,
262263
github_action_python_test_versions,
263-
)
264-
} else {
265-
create_ci_testing_linux_only_file(
264+
),
265+
ProjectManager::Poetry => create_ci_testing_linux_only_file(
266266
source_dir,
267267
min_python_version,
268268
github_action_python_test_versions,
269-
)
269+
),
270270
};
271271

272272
save_file_with_content(&file_path, &content)?;
@@ -509,7 +509,7 @@ pub fn save_ci_testing_multi_os_file(
509509
source_dir: &str,
510510
min_python_version: &str,
511511
github_action_python_test_versions: &[String],
512-
use_pyo3: bool,
512+
project_manager: &ProjectManager,
513513
project_root_dir: &Option<PathBuf>,
514514
) -> Result<()> {
515515
let file_path = match project_root_dir {
@@ -519,18 +519,17 @@ pub fn save_ci_testing_multi_os_file(
519519
),
520520
None => format!("{project_slug}/.github/workflows/testing.yml"),
521521
};
522-
let content = if use_pyo3 {
523-
create_ci_testing_multi_os_file_pyo3(
522+
let content = match project_manager {
523+
ProjectManager::Maturin => create_ci_testing_multi_os_file_pyo3(
524524
source_dir,
525525
min_python_version,
526526
github_action_python_test_versions,
527-
)
528-
} else {
529-
create_ci_testing_multi_os_file(
527+
),
528+
ProjectManager::Poetry => create_ci_testing_multi_os_file(
530529
source_dir,
531530
min_python_version,
532531
github_action_python_test_versions,
533-
)
532+
),
534533
};
535534

536535
save_file_with_content(&file_path, &content)?;
@@ -589,17 +588,16 @@ updates:
589588

590589
pub fn save_dependabot_file(
591590
project_slug: &str,
592-
use_pyo3: bool,
591+
project_manager: &ProjectManager,
593592
project_root_dir: &Option<PathBuf>,
594593
) -> Result<()> {
595594
let file_path = match project_root_dir {
596595
Some(root) => format!("{}/{project_slug}/.github/dependabot.yml", root.display()),
597596
None => format!("{project_slug}/.github/dependabot.yml"),
598597
};
599-
let content = if use_pyo3 {
600-
create_dependabot_file_pyo3()
601-
} else {
602-
create_dependabot_file()
598+
let content = match project_manager {
599+
ProjectManager::Maturin => create_dependabot_file_pyo3(),
600+
ProjectManager::Poetry => create_dependabot_file(),
603601
};
604602

605603
save_file_with_content(&file_path, &content)?;
@@ -750,7 +748,7 @@ jobs:
750748
pub fn save_pypi_publish_file(
751749
project_slug: &str,
752750
python_version: &str,
753-
use_pyo3: bool,
751+
project_manager: &ProjectManager,
754752
project_root_dir: &Option<PathBuf>,
755753
) -> Result<()> {
756754
let file_path = match project_root_dir {
@@ -760,10 +758,9 @@ pub fn save_pypi_publish_file(
760758
),
761759
None => format!("{project_slug}/.github/workflows/pypi_publish.yml"),
762760
};
763-
let content = if use_pyo3 {
764-
create_pypi_publish_file_pyo3(python_version)
765-
} else {
766-
create_pypi_publish_file(python_version)
761+
let content = match project_manager {
762+
ProjectManager::Maturin => create_pypi_publish_file_pyo3(python_version),
763+
ProjectManager::Poetry => create_pypi_publish_file(python_version),
767764
};
768765

769766
save_file_with_content(&file_path, &content)?;
@@ -968,7 +965,7 @@ jobs:
968965
"3.10".to_string(),
969966
"3.11".to_string(),
970967
],
971-
false,
968+
&ProjectManager::Poetry,
972969
&Some(base),
973970
)
974971
.unwrap();
@@ -1114,7 +1111,7 @@ jobs:
11141111
"3.10".to_string(),
11151112
"3.11".to_string(),
11161113
],
1117-
true,
1114+
&ProjectManager::Maturin,
11181115
&Some(base),
11191116
)
11201117
.unwrap();
@@ -1234,7 +1231,7 @@ jobs:
12341231
"3.10".to_string(),
12351232
"3.11".to_string(),
12361233
],
1237-
false,
1234+
&ProjectManager::Poetry,
12381235
&Some(base),
12391236
)
12401237
.unwrap();
@@ -1382,7 +1379,7 @@ jobs:
13821379
"3.10".to_string(),
13831380
"3.11".to_string(),
13841381
],
1385-
true,
1382+
&ProjectManager::Maturin,
13861383
&Some(base),
13871384
)
13881385
.unwrap();
@@ -1419,7 +1416,7 @@ updates:
14191416
let project_slug = "test-project";
14201417
create_dir_all(base.join(format!("{project_slug}/.github"))).unwrap();
14211418
let expected_file = base.join(format!("{project_slug}/.github/dependabot.yml"));
1422-
save_dependabot_file(project_slug, false, &Some(base)).unwrap();
1419+
save_dependabot_file(project_slug, &ProjectManager::Poetry, &Some(base)).unwrap();
14231420

14241421
assert!(expected_file.is_file());
14251422

@@ -1460,7 +1457,7 @@ updates:
14601457
let project_slug = "test-project";
14611458
create_dir_all(base.join(format!("{project_slug}/.github"))).unwrap();
14621459
let expected_file = base.join(format!("{project_slug}/.github/dependabot.yml"));
1463-
save_dependabot_file(project_slug, true, &Some(base)).unwrap();
1460+
save_dependabot_file(project_slug, &ProjectManager::Maturin, &Some(base)).unwrap();
14641461

14651462
assert!(expected_file.is_file());
14661463

@@ -1506,7 +1503,13 @@ jobs:
15061503
let project_slug = "test-project";
15071504
create_dir_all(base.join(format!("{project_slug}/.github/workflows"))).unwrap();
15081505
let expected_file = base.join(format!("{project_slug}/.github/workflows/pypi_publish.yml"));
1509-
save_pypi_publish_file(project_slug, python_version, false, &Some(base)).unwrap();
1506+
save_pypi_publish_file(
1507+
project_slug,
1508+
python_version,
1509+
&ProjectManager::Poetry,
1510+
&Some(base),
1511+
)
1512+
.unwrap();
15101513

15111514
assert!(expected_file.is_file());
15121515

@@ -1628,7 +1631,13 @@ jobs:
16281631
let project_slug = "test-project";
16291632
create_dir_all(base.join(format!("{project_slug}/.github/workflows"))).unwrap();
16301633
let expected_file = base.join(format!("{project_slug}/.github/workflows/pypi_publish.yml"));
1631-
save_pypi_publish_file(project_slug, python_version, true, &Some(base)).unwrap();
1634+
save_pypi_publish_file(
1635+
project_slug,
1636+
python_version,
1637+
&ProjectManager::Maturin,
1638+
&Some(base),
1639+
)
1640+
.unwrap();
16321641

16331642
assert!(expected_file.is_file());
16341643

src/main.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,12 @@ fn main() {
114114
exit(1);
115115
}
116116
}
117-
Param::UsePyo3 { value } => match value {
118-
BooleanChoice::True => {
119-
if let Err(e) = Config::save_use_pyo3(true) {
120-
print_error(e);
121-
exit(1);
122-
}
123-
}
124-
BooleanChoice::False => {
125-
if let Err(e) = Config::save_use_pyo3(false) {
126-
print_error(e);
127-
exit(1);
128-
}
117+
Param::ProjectManager { value } => {
118+
if let Err(e) = Config::save_project_manager(value) {
119+
print_error(e);
120+
exit(1);
129121
}
130-
},
122+
}
131123
Param::ApplicationOrLibrary { value } => match value {
132124
ApplicationOrLib::Application => {
133125
if let Err(e) = Config::save_is_application(true) {

0 commit comments

Comments
 (0)