Skip to content

Commit a612bad

Browse files
authored
add --preset base (#17)
* pc autoupdate * add --preset base * clean * clean * clean
1 parent 0105767 commit a612bad

File tree

19 files changed

+195
-101
lines changed

19 files changed

+195
-101
lines changed
File renamed without changes.
File renamed without changes.

.github/workflows/ci.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ name: CI
22

33
on:
44
pull_request: # Start the job on all PRs
5-
branches: [master, main]
6-
types: [synchronize, opened, reopened, ready_for_review]
7-
push: # Start the job on all main branch push
8-
branches: [master, main]
95

106
jobs:
117
precommit:

.pre-commit-config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
# Misc
77
#############################################################################
88
- repo: https://github.com/pre-commit/pre-commit-hooks
9-
rev: v4.5.0
9+
rev: v4.6.0
1010
hooks:
1111
- id: check-merge-conflict # Searches for merge conflict markers within files.
1212
- id: check-added-large-files # Blocks commits that add large files. Default limit is 500kB.
@@ -24,7 +24,7 @@ repos:
2424
# JSON, TOML
2525
#############################################################################
2626
- repo: https://github.com/pre-commit/pre-commit-hooks
27-
rev: v4.5.0
27+
rev: v4.6.0
2828
hooks:
2929
- id: check-json # Validates JSON files to ensure they are properly formatted and syntactically correct.
3030
types: [json]
@@ -46,15 +46,15 @@ repos:
4646
# Python
4747
#############################################################################
4848
- repo: https://github.com/PyCQA/autoflake
49-
rev: v2.2.1
49+
rev: v2.3.1
5050
hooks:
5151
- id: autoflake # Removes unused imports and unused variables from Python code.
5252
args:
5353
- --in-place
5454
- --remove-all-unused-imports
5555

5656
- repo: https://github.com/pycqa/isort
57-
rev: 5.12.0
57+
rev: 5.13.2
5858
hooks:
5959
- id: isort # Sorts Python imports into sections and by alphabetical order.
6060
args:
@@ -64,7 +64,7 @@ repos:
6464
- python
6565

6666
- repo: https://github.com/psf/black
67-
rev: 23.10.1
67+
rev: 24.4.2
6868
hooks:
6969
- id: black # Formats Python code to conform to the Black code style.
7070
args:
@@ -75,11 +75,11 @@ repos:
7575
exclude: templates/
7676

7777
- repo: https://github.com/pycqa/flake8
78-
rev: 6.1.0
78+
rev: 7.0.0
7979
hooks:
8080
- id: flake8 # Lints Python code for errors and code style issues based on PEP8.
8181
args:
82-
- --config=.cpa/flake8.cfg
82+
- --config=.ci/flake8.cfg
8383
types:
8484
- python
8585
exclude: templates/
@@ -99,11 +99,11 @@ repos:
9999
# CSS, Markdown, JavaScript, TypeScript, YAML style formatter
100100
#############################################################################
101101
- repo: https://github.com/pre-commit/mirrors-prettier
102-
rev: v3.0.3
102+
rev: v4.0.0-alpha.8
103103
hooks:
104104
- id: prettier # An opinionated code formatter supporting multiple languages.
105105
name: prettier
106-
args: [--config, .cpa/prettier.json, --write]
106+
args: [--config, .ci/prettier.json, --write]
107107
types_or:
108108
- css
109109
- scss
@@ -112,7 +112,7 @@ repos:
112112
- javascript
113113
- yaml
114114
- markdown
115-
exclude: templates/.pre-commit-config.yaml|templates/.github/workflows/ci.yaml
115+
exclude: templates/.pre-commit-config.yaml|templates/.github/workflows/ci.yaml|templates/base/ci.yaml
116116

117117
#############################################################################
118118
# Rust

example/python/.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ repos:
7777
hooks:
7878
- id: flake8 # Lints Python code for errors and code style issues based on PEP8.
7979
args:
80-
- --config=.cpa/flake8.cfg
80+
- --config=.ci/flake8.cfg
8181
types:
8282
- python
8383

@@ -100,7 +100,7 @@ repos:
100100
hooks:
101101
- id: prettier # An opinionated code formatter supporting multiple languages.
102102
name: prettier
103-
args: [--config, .cpa/prettier.json, --write]
103+
args: [--config, .ci/prettier.json, --write]
104104
types_or:
105105
- css
106106
- scss

example/python/.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"editor.formatOnSave": true,
55
"editor.defaultFormatter": "ms-python.black-formatter"
66
},
7-
"flake8.args": ["--config=.cpa/flake8.cfg"],
7+
"flake8.args": ["--config=.ci/flake8.cfg"],
88
"files.insertFinalNewline": true
99
}

example/rust/.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ repos:
5959
hooks:
6060
- id: prettier # An opinionated code formatter supporting multiple languages.
6161
name: prettier
62-
args: [--config, .cpa/prettier.json, --write]
62+
args: [--config, .ci/prettier.json, --write]
6363
types_or:
6464
- css
6565
- scss

example/rust/.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"editor.formatOnSave": true,
55
"editor.defaultFormatter": "ms-python.black-formatter"
66
},
7-
"flake8.args": ["--config=.cpa/flake8.cfg"],
7+
"flake8.args": ["--config=.ci/flake8.cfg"],
88
"files.insertFinalNewline": true
99
}

src/main.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod presets;
33
use std::process;
44

55
use clap::Parser;
6-
use presets::{common, python, rust};
6+
use presets::{base, common, python, rust};
77
use regex::Regex;
88

99
#[derive(Parser)]
@@ -46,6 +46,13 @@ pub struct Language {
4646

4747
#[allow(clippy::needless_return)]
4848
fn validate_preset(preset: &str) -> Language {
49+
if preset == "base" {
50+
return Language {
51+
language: "base".to_string(),
52+
ver: "".to_string(),
53+
};
54+
}
55+
4956
if preset == "rust" {
5057
return Language {
5158
language: "rust".to_string(),
@@ -78,6 +85,8 @@ fn main() {
7885
} else if lang.language == "rust" {
7986
let prefix = common(&args.name, create, &lang);
8087
rust(&args.name, &prefix);
88+
} else if lang.language == "base" {
89+
let _prefix = base(&args.name, create, &lang);
8190
} else {
8291
eprintln!("Preset: {:?} not supported", args.preset);
8392
}
@@ -93,6 +102,8 @@ fn main() {
93102
} else if lang.language == "rust" {
94103
let prefix = common(&args.name, create, &lang);
95104
rust(&args.name, &prefix);
105+
} else if lang.language == "base" {
106+
let _prefix = base(&args.name, create, &lang);
96107
} else {
97108
eprintln!("Preset: {:?} not supported", args.preset);
98109
}

src/presets.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ pub struct Makefile {}
4545
pub struct GhCI {}
4646

4747
#[derive(Template)]
48-
#[template(path = ".cpa/prettier.json", escape = "none")]
48+
#[template(path = "base/ci.yaml", escape = "none")]
49+
pub struct GhCIBase {}
50+
51+
#[derive(Template)]
52+
#[template(path = ".ci/prettier.json", escape = "none")]
4953
pub struct Prettier {}
5054

5155
#[derive(Template)]
@@ -54,17 +58,17 @@ pub struct PreCommitConfig {
5458
pub language: String,
5559
}
5660

61+
#[derive(Template)]
62+
#[template(path = "base/.pre-commit-config.yaml", escape = "none")]
63+
pub struct PreCommitConfigBase {}
64+
5765
////////////////////////////////////
5866
// PYTHON
5967
////////////////////////////////////
6068
#[derive(Template)]
6169
#[template(path = "python/Dockerfile", escape = "none")]
6270
pub struct PyDockerfile {}
6371

64-
#[derive(Template)]
65-
#[template(path = "python/main.py", escape = "none")]
66-
pub struct PyMain {}
67-
6872
#[derive(Template)]
6973
#[template(path = "python/pyproject.toml", escape = "none")]
7074
pub struct PyProject {
@@ -74,7 +78,7 @@ pub struct PyProject {
7478
}
7579

7680
#[derive(Template)]
77-
#[template(path = ".cpa/flake8.cfg", escape = "none")]
81+
#[template(path = ".ci/flake8.cfg", escape = "none")]
7882
pub struct Flake8 {}
7983

8084
////////////////////////////////////
@@ -98,7 +102,7 @@ pub fn common(name: &str, create: bool, lang: &Language) -> String {
98102
let prefix: String = if create { format!("./{}", name) } else { "./".to_string() };
99103

100104
// Create needed dirs
101-
let _ = fs::create_dir_all(format!("{}/.cpa", prefix));
105+
let _ = fs::create_dir_all(format!("{}/.ci", prefix));
102106
let _ = fs::create_dir_all(format!("{}/.vscode", prefix));
103107
let _ = fs::create_dir_all(format!("{}/.github/workflows", prefix));
104108

@@ -110,7 +114,7 @@ pub fn common(name: &str, create: bool, lang: &Language) -> String {
110114
language: lang.language.to_string(),
111115
}
112116
.write(&prefix, ".pre-commit-config.yaml");
113-
Prettier {}.write(&prefix, ".cpa/prettier.json");
117+
Prettier {}.write(&prefix, ".ci/prettier.json");
114118
VSCodeSettings {}.write(&prefix, ".vscode/settings.json");
115119
VSCodeExtensions {}.write(&prefix, ".vscode/extensions.json");
116120
prefix
@@ -120,8 +124,7 @@ pub fn python(name: &str, prefix: &str, lang: &Language) {
120124
let black_target_ver = format!("py{}", lang.ver.replace('.', ""));
121125

122126
// Render Python-specific files
123-
Flake8 {}.write(prefix, ".cpa/flake8.cfg");
124-
PyMain {}.write(prefix, "main.py");
127+
Flake8 {}.write(prefix, ".ci/flake8.cfg");
125128
PyDockerfile {}.write(prefix, "Dockerfile");
126129

127130
let pyproj: PyProject = PyProject {
@@ -140,3 +143,19 @@ pub fn rust(name: &str, prefix: &str) {
140143
CargoToml { name: name.to_string() }.write(prefix, "Cargo.toml");
141144
RustFmt {}.write(prefix, "rustfmt.toml");
142145
}
146+
147+
pub fn base(name: &str, create: bool, _lang: &Language) -> String {
148+
let prefix: String = if create { format!("./{}", name) } else { "./".to_string() };
149+
150+
// Create needed dirs
151+
let _ = fs::create_dir_all(format!("{}/.ci", prefix));
152+
let _ = fs::create_dir_all(format!("{}/.github/workflows", prefix));
153+
154+
// Render common files
155+
GhCIBase {}.write(&prefix, ".github/workflows/ci.yaml");
156+
GitIgnore {}.write(&prefix, ".gitignore");
157+
Makefile {}.write(&prefix, "Makefile");
158+
PreCommitConfigBase {}.write(&prefix, ".pre-commit-config.yaml");
159+
Prettier {}.write(&prefix, ".ci/prettier.json");
160+
prefix
161+
}

0 commit comments

Comments
 (0)