Skip to content

Commit aae651d

Browse files
authored
add vscode conf generation, fix Dockerfile ordering (#8)
* add vscode conf generation * add vscode conf generation * fix bad ordering in Dockerfile * bump cargo ver * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean
1 parent 00c1020 commit aae651d

14 files changed

Lines changed: 111 additions & 45 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
with:
2121
python-version: "3.10"
2222

23+
- name: Install Rust Toolchain
24+
uses: dtolnay/rust-toolchain@nightly
25+
2326
- name: Set shfmt version environment variable
2427
run: echo "SHFMT_VERSION=v3.7.0" >> $GITHUB_ENV
2528

@@ -64,6 +67,8 @@ jobs:
6467
sudo mv shfmt /usr/local/bin/
6568
fi
6669
sudo apt-get install shellcheck
70+
rustup component add clippy
71+
rustup component add rustfmt
6772
6873
- name: Run pre-commits
6974
env:

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cpa"
3-
version = "0.0.4"
3+
version = "0.0.7"
44
edition = "2018"
55

66
[dependencies]

example/.vscode/extensions.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"recommendations": [
3+
"ms-python.python",
4+
"ms-python.vscode-pylance",
5+
"ms-python.isort",
6+
"ms-python.black-formatter",
7+
"ms-python.flake8"
8+
]
9+
}

example/.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"[python]": {
3+
"editor.formatOnType": true,
4+
"editor.formatOnSave": true,
5+
"editor.defaultFormatter": "ms-python.black-formatter"
6+
},
7+
"flake8.args": ["--config=.cpa/flake8.cfg"],
8+
"files.insertFinalNewline": true
9+
}

example/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
FROM python:3.10-slim
22

3-
# Set the working directory in the container to /app
3+
# Create and set the working directory
44
WORKDIR /app
55

6-
# Copy the current directory contents into the container at /app
7-
COPY . .
8-
9-
# Install any needed packages specified in requirements.txt
6+
COPY requirements.txt ./
107
RUN pip install --no-cache-dir -r requirements.txt
118

9+
COPY . .
10+
1211
CMD ["python", "./main.py"]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.poetry]
2-
name = "example"
2+
name = "create-python-app"
33
version = "0.0.1"
44
description = ""
55
authors = [

rustfmt.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
max_width = 120
1+
max_width = 140
2+
# Below require nightly channel, run: rustup default nightly
23
imports_granularity = "Crate"
34
group_imports = "StdExternalCrate"
45
imports_layout = "Horizontal"

src/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ use python::setup_preset;
1111
long_about = "CPA is a cli tool designed to expedite the setup of new projects by automating the creation of various configuration files."
1212
)]
1313
enum Cli {
14-
#[clap(
15-
about = "Create a new project",
16-
long_about = "Create a new project using specified preset."
17-
)]
14+
#[clap(about = "Create a new project", long_about = "Create a new project using specified preset.")]
1815
Create(CreateArgs),
1916
#[clap(
2017
about = "Update existing project",

src/python.rs

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
extern crate regex;
22

3+
use std::{
4+
fs::{self, File}, io::Write, process
5+
};
6+
37
use askama::Template;
48
use regex::Regex;
5-
use std::fs::{self, File};
6-
use std::io::Write;
7-
use std::process;
89

910
#[derive(Template)]
1011
#[template(path = ".gitignore", escape = "none")]
1112
struct GitIgnore {}
1213

14+
#[derive(Template)]
15+
#[template(path = ".vscode/settings.json", escape = "none")]
16+
struct VSCodeSettings {}
17+
18+
#[derive(Template)]
19+
#[template(path = ".vscode/extensions.json", escape = "none")]
20+
struct VSCodeExtensions {}
21+
1322
#[derive(Template)]
1423
#[template(path = "Makefile", escape = "none")]
1524
struct Makefile {}
@@ -57,55 +66,74 @@ pub fn setup_preset(mut preset: String, name: String, create: bool) {
5766
prefix = format!("./{}", name)
5867
}
5968

69+
// Create needed dirs
6070
let _ = fs::create_dir_all(format!("{}/.cpa", prefix));
71+
let _ = fs::create_dir_all(format!("{}/.vscode", prefix));
72+
let _ = fs::create_dir_all(format!("{}/.github/workflows", prefix));
6173

6274
// Render Github Actions CI
63-
let _ = fs::create_dir_all(format!("{}/.github/workflows", prefix));
6475
File::create(format!("{}/.github/workflows/ci.yaml", prefix))
65-
.and_then(|mut file| file.write_all(GHWorkflowCI {}.render().expect("Failed to render ci.yaml").as_bytes()))
66-
.expect("Failed to create or write to ci.yaml");
76+
.and_then(|mut file| file.write_all(GHWorkflowCI {}.render().expect("Render fail: ci.yaml").as_bytes()))
77+
.expect("Write fail: ci.yaml");
78+
79+
// Render .vscode/settings.json
80+
File::create(format!("{}/.vscode/settings.json", prefix))
81+
.and_then(|mut file| file.write_all(VSCodeSettings {}.render().expect("Render fail: .vscode/settings.json").as_bytes()))
82+
.expect("Write fail: .vscode/settings.json");
83+
84+
// Render .vscode/extensions.json
85+
File::create(format!("{}/.vscode/extensions.json", prefix))
86+
.and_then(|mut file| {
87+
file.write_all(
88+
VSCodeExtensions {}
89+
.render()
90+
.expect("Render fail: .vscode/extensions.json")
91+
.as_bytes(),
92+
)
93+
})
94+
.expect("Write fail: .vscode/extensions.json");
6795

6896
// Render .gitignore
6997
File::create(format!("{}/.gitignore", prefix))
70-
.and_then(|mut file| file.write_all(GitIgnore {}.render().expect("Failed to render .gitignore").as_bytes()))
71-
.expect("Failed to create or write to .gitignore");
98+
.and_then(|mut file| file.write_all(GitIgnore {}.render().expect("Render fail: .gitignore").as_bytes()))
99+
.expect("Write fail: .gitignore");
72100

73101
// Render Makefile
74102
File::create(format!("{}/Makefile", prefix))
75-
.and_then(|mut file| file.write_all(Makefile {}.render().expect("Failed to render Makefile").as_bytes()))
76-
.expect("Failed to create or write to Makefile");
103+
.and_then(|mut file| file.write_all(Makefile {}.render().expect("Render fail: Makefile").as_bytes()))
104+
.expect("Write fail: Makefile");
77105

78106
// Render Dockerfile
79107
File::create(format!("{}/Dockerfile", prefix))
80-
.and_then(|mut file| file.write_all(Dockerfile {}.render().expect("Failed to render Dockerfile").as_bytes()))
81-
.expect("Failed to create or write to Dockerfile");
108+
.and_then(|mut file| file.write_all(Dockerfile {}.render().expect("Render fail: Dockerfile").as_bytes()))
109+
.expect("Write fail: Dockerfile");
82110

83111
// Render main.py
84112
File::create(format!("{}/main.py", prefix))
85113
.and_then(|mut file| file.write_all(MainPy {}.render().expect("Render fail").as_bytes()))
86-
.expect("Failed to render or write to main.py");
114+
.expect("Render fail: main.py");
87115

88116
// Render pre-commit conf
89117
File::create(format!("{}/.pre-commit-config.yaml", prefix))
90118
.and_then(|mut file| {
91119
file.write_all(
92120
PreCommitConfig { python: true }
93121
.render()
94-
.expect("Failed to render .pre-commit-config.yaml")
122+
.expect("Render fail: .pre-commit-config.yaml")
95123
.as_bytes(),
96124
)
97125
})
98-
.expect("Failed to create or write to .pre-commit-config.yaml");
126+
.expect("Write fail: .pre-commit-config.yaml");
99127

100128
// Render Flake8 conf
101129
File::create(format!("{}/.cpa/flake8.cfg", prefix))
102-
.and_then(|mut file| file.write_all(Flake8 {}.render().expect("Failed to render flake8.cfg").as_bytes()))
103-
.expect("Failed to create or write to flake8.cfg");
130+
.and_then(|mut file| file.write_all(Flake8 {}.render().expect("Render fail: flake8.cfg").as_bytes()))
131+
.expect("Write fail: flake8.cfg");
104132

105133
// Render Prettier conf
106134
File::create(format!("{}/.cpa/prettier.json", prefix))
107-
.and_then(|mut file| file.write_all(Prettier {}.render().expect("Failed to render prettier.json").as_bytes()))
108-
.expect("Failed to create or write to prettier.json");
135+
.and_then(|mut file| file.write_all(Prettier {}.render().expect("Render fail: prettier.json").as_bytes()))
136+
.expect("Write fail: prettier.json");
109137

110138
// Render Poetry conf
111139
let re = Regex::new(r"python(3\.\d+|4\.\d+)").unwrap();
@@ -124,8 +152,6 @@ pub fn setup_preset(mut preset: String, name: String, create: bool) {
124152
};
125153
let out_pyproj: String = pyproj.render().expect("Failed to render");
126154
let mut f_pyproj = File::create(format!("{}/pyproject.toml", prefix)).expect("Could not create file");
127-
f_pyproj
128-
.write_all(out_pyproj.as_bytes())
129-
.expect("Could not write to file");
155+
f_pyproj.write_all(out_pyproj.as_bytes()).expect("Could not write to file");
130156
println!("Project created at: {}", prefix)
131157
}

0 commit comments

Comments
 (0)