From d9ea18ca136683516caa556082a3ce6affd80269 Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 18:30:54 -0700 Subject: [PATCH 01/16] clean --- README.md | 2 ++ install.sh | 10 +++++----- templates/pyproject.toml | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3a9eeee..04f6aff 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ Download latest binary and install via provided `install.sh` script or get it fr ``` sh install.sh +# cpa will be installed to ~/bin/cpa +# add ~/bin to your PATH ``` ### Windows diff --git a/install.sh b/install.sh index 8b5dd49..765dfc6 100644 --- a/install.sh +++ b/install.sh @@ -57,10 +57,10 @@ chmod +x "$BINARY_PATH" || { # Remove the downloaded zip rm "$ZIP_PATH" -# Optionally, append the target directory to PATH if it's not already there -if [[ ":$PATH:" != *":$TARGET_DIR:"* ]]; then - echo "export PATH=\$PATH:$TARGET_DIR" >>~/.bashrc - echo "$TARGET_DIR added to PATH" -fi +# # Optionally, append the target directory to PATH if it's not already there +# if [[ ":$PATH:" != *":$TARGET_DIR:"* ]]; then +# echo "export PATH=\$PATH:$TARGET_DIR" >>~/.bashrc +# echo "$TARGET_DIR added to PATH" +# fi echo "cpa installed to $BINARY_PATH" diff --git a/templates/pyproject.toml b/templates/pyproject.toml index 6a044d5..25f3b68 100644 --- a/templates/pyproject.toml +++ b/templates/pyproject.toml @@ -8,7 +8,7 @@ authors = [ license = "" [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["poetry-core>=1.7.0"] build-backend = "poetry.core.masonry.api" [tool.black] @@ -57,6 +57,6 @@ line_length = 120 python = "^{{ python_ver }}" [tool.poetry.group.dev.dependencies] -pre-commit = "^3.5.0" +pre-commit = ">=3.5.0" pytest = "^7.3.1" pytest-cov = "^4.1.0" From 9d1df75e001760a3157d0e98d52c8227f5b65dea Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 20:23:03 -0700 Subject: [PATCH 02/16] add version --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 4639547..dcb8a97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use clap::Parser; use python::derive_preset; #[derive(Parser)] -#[command(name = "cpa")] +#[command(name = "cpa", version)] enum Cli { Create(CreateArgs), Update(UpdateArgs), From adb72dcfd5a1dcfc3514a41d2f769ebbd522bb0b Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 20:27:42 -0700 Subject: [PATCH 03/16] clean --- Cargo.toml | 2 +- src/main.rs | 8 ++++---- src/python.rs | 2 +- templates/.pre-commit-config.yaml | 11 +++++------ 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a94d3aa..7cb3818 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cpa" -version = "0.0.1" +version = "0.0.2" edition = "2018" [dependencies] diff --git a/src/main.rs b/src/main.rs index dcb8a97..1a59d7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ mod python; use clap::Parser; -use python::derive_preset; +use python::setup_preset; #[derive(Parser)] #[command(name = "cpa", version)] @@ -30,14 +30,14 @@ fn main() { println!("Creating project with name: {}", args.name); println!("Using preset: {:?} ", args.preset); if args.preset.starts_with("python") { - derive_preset(args.preset, args.name); + setup_preset(args.preset, args.name); } else { - eprintln!("Preset: {:?} not supported currently", args.preset); + eprintln!("Preset: {:?} not supported yet", args.preset); } } Cli::Update(args) => { println!("Updating project cwith preset: {:?}", args.preset); - eprintln!("Update currently not supported"); + eprintln!("Update not yet implemented"); } } } diff --git a/src/python.rs b/src/python.rs index 4edd092..e772b6d 100644 --- a/src/python.rs +++ b/src/python.rs @@ -44,7 +44,7 @@ struct Flake8 {} #[template(path = ".cpa/prettier.json", escape = "none")] struct Prettier {} -pub fn derive_preset(mut preset: String, name: String) { +pub fn setup_preset(mut preset: String, name: String) { if preset == "python" { preset = "python3.10".to_string(); } diff --git a/templates/.pre-commit-config.yaml b/templates/.pre-commit-config.yaml index 90fe6a5..53d7220 100644 --- a/templates/.pre-commit-config.yaml +++ b/templates/.pre-commit-config.yaml @@ -83,12 +83,12 @@ repos: - python # - repo: https://github.com/astral-sh/ruff-pre-commit - # rev: v0.0.270 + # rev: v0.1.4 # hooks: # - id: ruff # - repo: https://github.com/python-poetry/poetry - # rev: '1.4.0' + # rev: '1.7.0' # hooks: # - id: poetry-check # Makes sure the poetry configuration does not get committed in a broken state. # - id: poetry-lock # Ensures the poetry.lock file is up-to-date with the pyproject.toml changes. @@ -102,13 +102,12 @@ repos: hooks: - id: prettier # An opinionated code formatter supporting multiple languages. name: prettier - entry: prettier args: [--config, .cpa/prettier.json, --write] types_or: - - javascript + - css + - scss - ts - tsx - - scss - - css + - javascript - yaml - markdown From 32fa87643c265d0c78db3aac67e92f4a9e57080a Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 20:33:18 -0700 Subject: [PATCH 04/16] clean --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1937ccd..792a770 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,8 +38,8 @@ jobs: - name: Run pre-commits run: | - pre-commit run --all-files + # pre-commit run --all-files + pre-commit run --from-ref ${{ env.BASE_COMMIT_ID }} --to-ref $(git log --pretty=tformat:"%H" -n1 .) # pre-commit run --from-ref origin/main --to-ref HEAD # run: | # BASE_COMMIT_ID=$(git rev-parse origin/main) - # pre-commit run --from-ref ${{ env.BASE_COMMIT_ID }} --to-ref HEAD From 15dcc31a14acb3845edea9183c083c2eca5606e5 Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 20:38:37 -0700 Subject: [PATCH 05/16] clean --- .github/workflows/ci.yaml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 792a770..8095484 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,11 +23,27 @@ jobs: with: python-version: "3.10" + - name: Cache pip dependencies + uses: actions/cache@v3 + with: + path: ~/.cache/pip + # key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + key: ${{ runner.os }}-pip- + restore-keys: | + ${{ runner.os }}-pip- + - name: Install dependencies run: | python -m pip install pre-commit pre-commit install + - name: Cache shfmt binary + uses: actions/cache@v3 + with: + path: /usr/local/bin/shfmt + # key: ${{ runner.os }}-shfmt-${{ env.SHFMT_VERSION }} + key: ${{ runner.os }}-shfmt- + - name: Install shfmt run: | SHFMT_VERSION="v3.7.0" @@ -39,7 +55,10 @@ jobs: - name: Run pre-commits run: | # pre-commit run --all-files - pre-commit run --from-ref ${{ env.BASE_COMMIT_ID }} --to-ref $(git log --pretty=tformat:"%H" -n1 .) + CUR_SHA=$(git log --pretty=tformat:"%H" -n1 .) + echo $CUR_SHA + echo ${{ env.BASE_COMMIT_ID }} + pre-commit run --from-ref ${{ env.BASE_COMMIT_ID }} --to-ref $CUR_SHA # pre-commit run --from-ref origin/main --to-ref HEAD # run: | # BASE_COMMIT_ID=$(git rev-parse origin/main) From 9d9be82ff6aba746f29f0a0c76508c2deda1b2f5 Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 20:39:45 -0700 Subject: [PATCH 06/16] clean --- .github/workflows/ci.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8095484..498f91f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -58,7 +58,8 @@ jobs: CUR_SHA=$(git log --pretty=tformat:"%H" -n1 .) echo $CUR_SHA echo ${{ env.BASE_COMMIT_ID }} - pre-commit run --from-ref ${{ env.BASE_COMMIT_ID }} --to-ref $CUR_SHA + # pre-commit run --from-ref ${{ env.BASE_COMMIT_ID }} --to-ref $CUR_SHA + pre-commit run --from-ref origin/main --to-ref $CUR_SHA # pre-commit run --from-ref origin/main --to-ref HEAD # run: | # BASE_COMMIT_ID=$(git rev-parse origin/main) From c22b4d206440f5b3fe898b893ce372e7637082fe Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 20:41:42 -0700 Subject: [PATCH 07/16] clean --- .github/workflows/ci.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 498f91f..dae39d8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -54,12 +54,14 @@ jobs: - name: Run pre-commits run: | - # pre-commit run --all-files CUR_SHA=$(git log --pretty=tformat:"%H" -n1 .) echo $CUR_SHA echo ${{ env.BASE_COMMIT_ID }} - # pre-commit run --from-ref ${{ env.BASE_COMMIT_ID }} --to-ref $CUR_SHA + git fetch pre-commit run --from-ref origin/main --to-ref $CUR_SHA + + # pre-commit run --from-ref ${{ env.BASE_COMMIT_ID }} --to-ref $CUR_SHA + # pre-commit run --all-files # pre-commit run --from-ref origin/main --to-ref HEAD # run: | # BASE_COMMIT_ID=$(git rev-parse origin/main) From fad889b7f3fe5c60dab90ee80cf35f351fab3d8b Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 21:04:49 -0700 Subject: [PATCH 08/16] save --- .cpa/flake8.cfg | 82 ++++++++++++++++++++++-------------- .github/workflows/ci.yaml | 6 --- .gitignore | 4 ++ .pre-commit-config.yaml | 48 +++++++-------------- Dockerfile | 12 ++++++ Makefile | 25 +++++++++++ main.py | 1 + pyproject.toml | 8 ++-- src/main.rs | 7 +-- src/python.rs | 26 +++++++----- templates/.cpa/flake8.cfg | 89 ++++++++++++++++++++++++--------------- 11 files changed, 189 insertions(+), 119 deletions(-) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 main.py diff --git a/.cpa/flake8.cfg b/.cpa/flake8.cfg index 426aebc..6408689 100644 --- a/.cpa/flake8.cfg +++ b/.cpa/flake8.cfg @@ -1,46 +1,66 @@ [flake8] -ignore = E203,E231,E501,I100,I201,I202,D102,D100,C901,D104,D101,D105,D107,D400,D103,D205,W503,E402,E266,F841 -# E203 whitespace before ':'. Conflicts with how Black formats slicing. -# E231 missing whitespace after ',', ';', or ':'. Conflicts with Black. -# E501 line too long (82 > 79 characters). Ignored because max-line-length is set. -# I100 Import statements are in the wrong order. -# I201 Missing newline between import groups. -# I202 Additional newline in a group of imports. -# D102 Missing docstring in public method. -# D100 Missing docstring in public module. -# C901 function is too complex. Ignored because max-complexity is set. -# D104 Missing docstring in public package. -# D101 Missing docstring in public class. -# D105 Missing docstring in magic method. -# D107 Missing docstring in __init__. -# D400 First line should end with a period. -# D103 Missing docstring in public function. -# D205 1 blank line required between summary line and description. -# W503 line break before binary operator. This is no longer PEP 8 compliant. -# E402 module level import not at top of file. -# E266 too many leading '#' for block comment. -# F841 local variable is assigned to but never used. +ignore = +# C901, # function is too complex. Ignored because max-complexity is set. + D100, + # Missing docstring in public module. + D101, + # Missing docstring in public class. + D102, + # Missing docstring in public method. + D103, + # Missing docstring in public function. + D104, + # Missing docstring in public package. + D105, + # Missing docstring in magic method. + D107, + # Missing docstring in __init__. + D205, + # 1 blank line required between summary line and description. + D400, + # First line should end with a period. + E203, + # whitespace before ':'. Conflicts with how Black formats slicing. + E231, + # missing whitespace after ',', ';', or ':'. Conflicts with Black. + E266, + # too many leading '#' for block comment. + E402, + # module level import not at top of file. + E501, + # line too long (82 > 79 characters). Ignored because max-line-length is set. + F841, + # local variable is assigned to but never used. + I100, + # Import statements are in the wrong order. + I201, + # Missing newline between import groups. + I202, + # Additional newline in a group of imports. + W503 + # line break before binary operator. This is no longer PEP 8 compliant. exclude = .cache, .coverage.*, - .env, # Environment directory used by some tools - .git, # Version control directory - .github, # GitHub metadata directory + .env, + .git, + .github, .gradle, - .hg, # Mercurial directory - .mypy_cache, # MyPy cache directory - .pytest_cache, # PyTest cache directory - .svn, # Subversion directory + .hg, + .mypy_cache, + .pytest_cache, + .svn, .tox, - .venv, # Common virtual environment directory - .vscode, # VS Code configuration directory - *__pycache__, # Python cache directory + .venv, + .vscode, + *__pycache__, *.egg-info, *.pyc, build, dist, htmlcov.*, + # List of application-specific import names. application-import-names = flake8 # Import statement format style. diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dae39d8..09eeedf 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -59,9 +59,3 @@ jobs: echo ${{ env.BASE_COMMIT_ID }} git fetch pre-commit run --from-ref origin/main --to-ref $CUR_SHA - - # pre-commit run --from-ref ${{ env.BASE_COMMIT_ID }} --to-ref $CUR_SHA - # pre-commit run --all-files - # pre-commit run --from-ref origin/main --to-ref HEAD - # run: | - # BASE_COMMIT_ID=$(git rev-parse origin/main) diff --git a/.gitignore b/.gitignore index 26b2a67..ea1aea1 100644 --- a/.gitignore +++ b/.gitignore @@ -182,4 +182,8 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + +########################################################################################## +# Misc +########################################################################################## tmp* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1002cf1..09b29e5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,17 +8,16 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: - - id: check-ast # Validates the syntax of Python files. - - id: check-case-conflict # Identifies potential case-insensitive file name conflicts. - id: check-merge-conflict # Searches for merge conflict markers within files. - - id: check-symlinks # Detects broken symlinks. - id: check-added-large-files # Blocks commits that add large files. Default limit is 500kB. - args: ["--maxkb=1300"] # Can be configured with args, e.g., '--maxkb=1000' to change the limit. - # Files in 'your_dir/' can be excluded. # exclude: 'your_dir/.*' - - id: end-of-file-fixer # Ensures files end with a single newline or are empty. + # args: ['--maxkb=5000'] + - id: check-case-conflict # Identifies potential case-insensitive file name conflicts. + - id: check-ast # Validates the syntax of Python files. + - id: check-symlinks # Detects broken symlinks. - id: trailing-whitespace # Removes any trailing whitespace at the end of lines. + - id: end-of-file-fixer # Ensures files end with a single newline or are empty. ############################################################################# # JSON, TOML @@ -48,7 +47,7 @@ repos: - repo: https://github.com/PyCQA/autoflake rev: v2.2.1 hooks: - - id: autoflake # Removes unused imports and unused variables from Python code + - id: autoflake # Removes unused imports and unused variables from Python code. args: - --in-place - --remove-all-unused-imports @@ -56,7 +55,7 @@ repos: - repo: https://github.com/pycqa/isort rev: 5.12.0 hooks: - - id: isort # Sorts Python imports into sections and by alphabetical order + - id: isort # Sorts Python imports into sections and by alphabetical order. args: - --settings-path - pyproject.toml @@ -66,7 +65,7 @@ repos: - repo: https://github.com/psf/black rev: 23.10.1 hooks: - - id: black # Formats Python code to conform to the Black code style + - id: black # Formats Python code to conform to the Black code style. args: - --config - pyproject.toml @@ -76,25 +75,22 @@ repos: - repo: https://github.com/pycqa/flake8 rev: 6.1.0 hooks: - - id: flake8 # Lints Python code for errors and code style issues based on PEP8 + - id: flake8 # Lints Python code for errors and code style issues based on PEP8. args: - --config=.cpa/flake8.cfg types: - python # - repo: https://github.com/astral-sh/ruff-pre-commit - # # Ruff version. - # rev: v0.0.270 + # rev: v0.1.4 # hooks: # - id: ruff # - repo: https://github.com/python-poetry/poetry - # rev: '1.4.0' + # rev: '1.7.0' # hooks: - # # https://python-poetry.org/docs/master/pre-commit-hooks/ - # # These hooks ensure that our dependencies are being updated only thru poetry. # - id: poetry-check # Makes sure the poetry configuration does not get committed in a broken state. - # # - id: poetry-lock # Makes sure the lock file is up-to-date when committing changes. + # - id: poetry-lock # Ensures the poetry.lock file is up-to-date with the pyproject.toml changes. ############################################################################# # CSS, Markdown, JavaScript, TypeScript, YAML style formatter @@ -102,26 +98,14 @@ repos: - repo: https://github.com/pre-commit/mirrors-prettier rev: v3.0.3 hooks: - - id: prettier + - id: prettier # An opinionated code formatter supporting multiple languages. name: prettier - entry: prettier args: [--config, .cpa/prettier.json, --write] types_or: - - javascript + - css + - scss - ts - tsx - - scss - - css + - javascript - yaml - markdown - exclude: templates/.pre-commit-config.yaml - - ############################################################################# - # Rust - ############################################################################# - - repo: https://github.com/doublify/pre-commit-rust - rev: v1.0 - hooks: - - id: fmt # Formats Rust code using rustfmt - - id: cargo-check # Checks Rust code for compilation errors and warnings - - id: clippy # Lints Rust code with clippy for common mistakes and style issues diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1b4b414 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.10-slim + +# Set the working directory in the container to /app +WORKDIR /app + +# Copy the current directory contents into the container at /app +COPY . . + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +CMD ["python", "./main.py"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5c2a614 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +.PHONY: setuppc +setuppc: + @echo "Setting up pre-commit and hooks..." + python3 -m pip install pre-commit + pre-commit install + +ifeq ($(shell uname),Darwin) + @echo "Setting up shfmt (macOS)..." + brew install shfmt + + @echo "Setting up shellcheck (macOS)..." + brew install shellcheck +else + @echo "Setting up shfmt (Linux)..." + wget -qO shfmt "https://github.com/mvdan/sh/releases/download/v3.7.0/shfmt_v3.7.0_$(shell uname -m)" + chmod +x shfmt + sudo mv shfmt /usr/local/bin/shfmt + + @echo "Setting up shellcheck (Linux)..." + sudo apt-get install shellcheck || sudo yum install shellcheck || sudo dnf install shellcheck +endif + +.PHONY: reqtxt +reqtxt: + poetry export -f requirements.txt --output requirements.txt --without-hashes diff --git a/main.py b/main.py new file mode 100644 index 0000000..ad35e5a --- /dev/null +++ b/main.py @@ -0,0 +1 @@ +print("Hello World") diff --git a/pyproject.toml b/pyproject.toml index f9300cc..e3077be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "cpa" +name = "tmp_test" version = "0.0.1" description = "" authors = [ @@ -8,7 +8,7 @@ authors = [ license = "" [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["poetry-core>=1.7.0"] build-backend = "poetry.core.masonry.api" [tool.black] @@ -35,7 +35,7 @@ color = true [tool.isort] balanced_wrapping = true include_trailing_comma = true -known_first_party = "cpa" +known_first_party = "tmp_test" known_third_party = [ "boto3", # Common for AWS "django", # Common web framework, if used @@ -57,6 +57,6 @@ line_length = 120 python = "^3.10" [tool.poetry.group.dev.dependencies] -pre-commit = "^3.5.0" +pre-commit = ">=3.5.0" pytest = "^7.3.1" pytest-cov = "^4.1.0" diff --git a/src/main.rs b/src/main.rs index 1a59d7e..04f3262 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,14 +30,15 @@ fn main() { println!("Creating project with name: {}", args.name); println!("Using preset: {:?} ", args.preset); if args.preset.starts_with("python") { - setup_preset(args.preset, args.name); + setup_preset(args.preset, args.name, true); } else { eprintln!("Preset: {:?} not supported yet", args.preset); } } Cli::Update(args) => { - println!("Updating project cwith preset: {:?}", args.preset); - eprintln!("Update not yet implemented"); + println!("Updating project with preset: {:?}", args.preset); + setup_preset(args.preset, "".to_string(), false); + // eprintln!("Update not yet implemented"); } } } diff --git a/src/python.rs b/src/python.rs index e772b6d..9650e15 100644 --- a/src/python.rs +++ b/src/python.rs @@ -44,14 +44,20 @@ struct Flake8 {} #[template(path = ".cpa/prettier.json", escape = "none")] struct Prettier {} -pub fn setup_preset(mut preset: String, name: String) { +pub fn setup_preset(mut preset: String, name: String, create: bool) { if preset == "python" { preset = "python3.10".to_string(); } + // write to ./pyproject.toml OR ./myproj/pyproject.toml + // write to ./.cpa/flake8 OR ./myproj/.cpa/flake8 + let mut prefix: String = "./".to_string(); + if !create { + prefix = format!("./{}", name) + } - let _ = fs::create_dir_all(format!("./{}/.cpa", name)); + let _ = fs::create_dir_all(format!("{}/.cpa", prefix)); // Render .gitignore - File::create(format!("./{}/.gitignore", name)) + File::create(format!("{}/.gitignore", prefix)) .and_then(|mut file| { file.write_all( GitIgnore {} @@ -63,7 +69,7 @@ pub fn setup_preset(mut preset: String, name: String) { .expect("Failed to create or write to .gitignore"); // Render Makefile - File::create(format!("./{}/Makefile", name)) + File::create(format!("{}/Makefile", prefix)) .and_then(|mut file| { file.write_all( Makefile {} @@ -75,7 +81,7 @@ pub fn setup_preset(mut preset: String, name: String) { .expect("Failed to create or write to Makefile"); // Render Dockerfile - File::create(format!("./{}/Dockerfile", name)) + File::create(format!("{}/Dockerfile", prefix)) .and_then(|mut file| { file.write_all( Dockerfile {} @@ -87,12 +93,12 @@ pub fn setup_preset(mut preset: String, name: String) { .expect("Failed to create or write to Dockerfile"); // Render main.py - File::create(format!("./{}/main.py", name)) + File::create(format!("{}/main.py", prefix)) .and_then(|mut file| file.write_all(MainPy {}.render().expect("Render fail").as_bytes())) .expect("Failed to render or write to main.py"); // Render pre-commit conf - File::create(format!("./{}/.pre-commit-config.yaml", name)) + File::create(format!("{}/.pre-commit-config.yaml", prefix)) .and_then(|mut file| { file.write_all( PreCommitConfig { python: true } @@ -104,7 +110,7 @@ pub fn setup_preset(mut preset: String, name: String) { .expect("Failed to create or write to .pre-commit-config.yaml"); // Render Flake8 conf - File::create(format!("./{}/.cpa/flake8.cfg", name)) + File::create(format!("{}/.cpa/flake8.cfg", prefix)) .and_then(|mut file| { file.write_all( Flake8 {} @@ -116,7 +122,7 @@ pub fn setup_preset(mut preset: String, name: String) { .expect("Failed to create or write to flake8.cfg"); // Render Prettier conf - File::create(format!("./{}/.cpa/prettier.json", name)) + File::create(format!("{}/.cpa/prettier.json", prefix)) .and_then(|mut file| { file.write_all( Prettier {} @@ -144,7 +150,7 @@ pub fn setup_preset(mut preset: String, name: String) { }; let out_pyproj: String = pyproj.render().expect("Failed to render"); let mut f_pyproj = - File::create(format!("./{}/pyproject.toml", name)).expect("Could not create file"); + File::create(format!("{}/pyproject.toml", prefix)).expect("Could not create file"); f_pyproj .write_all(out_pyproj.as_bytes()) .expect("Could not write to file"); diff --git a/templates/.cpa/flake8.cfg b/templates/.cpa/flake8.cfg index eb83fbf..6408689 100644 --- a/templates/.cpa/flake8.cfg +++ b/templates/.cpa/flake8.cfg @@ -1,49 +1,72 @@ [flake8] ignore = # C901, # function is too complex. Ignored because max-complexity is set. - D100, # Missing docstring in public module. - D101, # Missing docstring in public class. - D102, # Missing docstring in public method. - D103, # Missing docstring in public function. - D104, # Missing docstring in public package. - D105, # Missing docstring in magic method. - D107, # Missing docstring in __init__. - D205, # 1 blank line required between summary line and description. - D400, # First line should end with a period. - E203, # whitespace before ':'. Conflicts with how Black formats slicing. - E231, # missing whitespace after ',', ';', or ':'. Conflicts with Black. - E266, # too many leading '#' for block comment. - E402, # module level import not at top of file. - E501, # line too long (82 > 79 characters). Ignored because max-line-length is set. - F841, # local variable is assigned to but never used. - I100, # Import statements are in the wrong order. - I201, # Missing newline between import groups. - I202, # Additional newline in a group of imports. - W503 # line break before binary operator. This is no longer PEP 8 compliant. + D100, + # Missing docstring in public module. + D101, + # Missing docstring in public class. + D102, + # Missing docstring in public method. + D103, + # Missing docstring in public function. + D104, + # Missing docstring in public package. + D105, + # Missing docstring in magic method. + D107, + # Missing docstring in __init__. + D205, + # 1 blank line required between summary line and description. + D400, + # First line should end with a period. + E203, + # whitespace before ':'. Conflicts with how Black formats slicing. + E231, + # missing whitespace after ',', ';', or ':'. Conflicts with Black. + E266, + # too many leading '#' for block comment. + E402, + # module level import not at top of file. + E501, + # line too long (82 > 79 characters). Ignored because max-line-length is set. + F841, + # local variable is assigned to but never used. + I100, + # Import statements are in the wrong order. + I201, + # Missing newline between import groups. + I202, + # Additional newline in a group of imports. + W503 + # line break before binary operator. This is no longer PEP 8 compliant. exclude = .cache, .coverage.*, - .env, # Environment directory used by some tools - .git, # Version control directory - .github, # GitHub metadata directory + .env, + .git, + .github, .gradle, - .hg, # Mercurial directory - .mypy_cache, # MyPy cache directory - .pytest_cache, # PyTest cache directory - .svn, # Subversion directory + .hg, + .mypy_cache, + .pytest_cache, + .svn, .tox, - .venv, # Common virtual environment directory - .vscode, # VS Code configuration directory - *__pycache__, # Python cache directory + .venv, + .vscode, + *__pycache__, *.egg-info, *.pyc, build, dist, htmlcov.*, -application-import-names = flake8 # List of application-specific import names. -import-order-style = google # Import statement format style. -max-complexity = 18 # The maximum McCabe complexity allowed. -max-line-length = 120 # The maximum allowed line length. +# List of application-specific import names. +application-import-names = flake8 +# Import statement format style. +import-order-style = google +# The maximum McCabe complexity allowed. +max-complexity = 18 +# The maximum allowed line length. +max-line-length = 120 # per-file-ignores = # Per-file-ignores setting can be used to ignore specific errors in specific files. From 84e1b5c438011345a7e347ea76cc9b21ed29ac0b Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 21:05:24 -0700 Subject: [PATCH 09/16] clean --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e3077be..b0d3a44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "tmp_test" +name = "" version = "0.0.1" description = "" authors = [ @@ -35,7 +35,7 @@ color = true [tool.isort] balanced_wrapping = true include_trailing_comma = true -known_first_party = "tmp_test" +known_first_party = "" known_third_party = [ "boto3", # Common for AWS "django", # Common web framework, if used From 0893fbc5585b04ba7fe87aa66805c3bd72d623ea Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 21:08:14 -0700 Subject: [PATCH 10/16] clean --- .pre-commit-config.yaml | 10 ++++++++++ src/main.rs | 1 - src/python.rs | 2 -- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 09b29e5..5548643 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -109,3 +109,13 @@ repos: - javascript - yaml - markdown + + ############################################################################# + # Rust + ############################################################################# + - repo: https://github.com/doublify/pre-commit-rust + rev: v1.0 + hooks: + - id: fmt # Formats Rust code using rustfmt + - id: cargo-check # Checks Rust code for compilation errors and warnings + - id: clippy # Lints Rust code with clippy for common mistakes and style issues diff --git a/src/main.rs b/src/main.rs index 04f3262..06d52a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,6 @@ fn main() { Cli::Update(args) => { println!("Updating project with preset: {:?}", args.preset); setup_preset(args.preset, "".to_string(), false); - // eprintln!("Update not yet implemented"); } } } diff --git a/src/python.rs b/src/python.rs index 9650e15..564a8db 100644 --- a/src/python.rs +++ b/src/python.rs @@ -48,8 +48,6 @@ pub fn setup_preset(mut preset: String, name: String, create: bool) { if preset == "python" { preset = "python3.10".to_string(); } - // write to ./pyproject.toml OR ./myproj/pyproject.toml - // write to ./.cpa/flake8 OR ./myproj/.cpa/flake8 let mut prefix: String = "./".to_string(); if !create { prefix = format!("./{}", name) From f84aedafdf4a1673c787e0fa51e0c2b4e1e187b8 Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 21:10:52 -0700 Subject: [PATCH 11/16] cache target dir --- .github/workflows/release.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e658db9..b48ac3f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -39,6 +39,13 @@ jobs: - name: Print Runner OS run: echo "Runner OS is ${{ runner.os }}" + - name: Cache target dir + uses: actions/cache@v3 + with: + path: | + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Build Release run: cargo build --release From ca86f418675b061299b8aaffc69f930fb54ad494 Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 21:13:28 -0700 Subject: [PATCH 12/16] clean --- .gitignore | 2 +- Cargo.lock | 425 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 426 insertions(+), 1 deletion(-) create mode 100644 Cargo.lock diff --git a/.gitignore b/.gitignore index ea1aea1..80d301e 100644 --- a/.gitignore +++ b/.gitignore @@ -174,7 +174,7 @@ target/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock +# Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..cb766de --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,425 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "askama" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" +dependencies = [ + "askama_derive", + "askama_escape", + "humansize", + "num-traits", + "percent-encoding", +] + +[[package]] +name = "askama_derive" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a0fc7dcf8bd4ead96b1d36b41df47c14beedf7b0301fc543d8f2384e66a2ec0" +dependencies = [ + "askama_parser", + "basic-toml", + "mime", + "mime_guess", + "proc-macro2", + "quote", + "serde", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_parser" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c268a96e01a4c47c8c5c2472aaa570707e006a875ea63e819f75474ceedaf7b4" +dependencies = [ + "nom", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "basic-toml" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bfc506e7a2370ec239e1d072507b2a80c833083699d3c6fa176fbb4de8448c6" +dependencies = [ + "serde", +] + +[[package]] +name = "clap" +version = "4.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "cpa" +version = "0.0.2" +dependencies = [ + "askama", + "clap", + "regex", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "humansize" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" +dependencies = [ + "libm", +] + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "percent-encoding" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" + +[[package]] +name = "proc-macro2" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "serde" +version = "1.0.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "2.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" From 27a770a1f10fdd5819fb790754414929f700d3ee Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 21:14:35 -0700 Subject: [PATCH 13/16] clean --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb766de..17f9ed3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -166,7 +166,7 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "cpa" -version = "0.0.2" +version = "0.0.3" dependencies = [ "askama", "clap", diff --git a/Cargo.toml b/Cargo.toml index 7cb3818..a2fb515 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cpa" -version = "0.0.2" +version = "0.0.3" edition = "2018" [dependencies] From 3113f28ceab2721a08b906c749b832dbdeab610e Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 21:16:14 -0700 Subject: [PATCH 14/16] clean --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5548643..8bfe459 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -109,6 +109,7 @@ repos: - javascript - yaml - markdown + exclude: templates/.pre-commit-config.yaml ############################################################################# # Rust From e1feb72cf0020e44de1ff92fd1ba758efdd9020d Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 21:18:27 -0700 Subject: [PATCH 15/16] clean --- example/.cpa/flake8.cfg | 89 +++++++++++++++++++++------------ example/.pre-commit-config.yaml | 11 ++-- example/pyproject.toml | 4 +- src/python.rs | 2 +- 4 files changed, 64 insertions(+), 42 deletions(-) diff --git a/example/.cpa/flake8.cfg b/example/.cpa/flake8.cfg index eb83fbf..6408689 100644 --- a/example/.cpa/flake8.cfg +++ b/example/.cpa/flake8.cfg @@ -1,49 +1,72 @@ [flake8] ignore = # C901, # function is too complex. Ignored because max-complexity is set. - D100, # Missing docstring in public module. - D101, # Missing docstring in public class. - D102, # Missing docstring in public method. - D103, # Missing docstring in public function. - D104, # Missing docstring in public package. - D105, # Missing docstring in magic method. - D107, # Missing docstring in __init__. - D205, # 1 blank line required between summary line and description. - D400, # First line should end with a period. - E203, # whitespace before ':'. Conflicts with how Black formats slicing. - E231, # missing whitespace after ',', ';', or ':'. Conflicts with Black. - E266, # too many leading '#' for block comment. - E402, # module level import not at top of file. - E501, # line too long (82 > 79 characters). Ignored because max-line-length is set. - F841, # local variable is assigned to but never used. - I100, # Import statements are in the wrong order. - I201, # Missing newline between import groups. - I202, # Additional newline in a group of imports. - W503 # line break before binary operator. This is no longer PEP 8 compliant. + D100, + # Missing docstring in public module. + D101, + # Missing docstring in public class. + D102, + # Missing docstring in public method. + D103, + # Missing docstring in public function. + D104, + # Missing docstring in public package. + D105, + # Missing docstring in magic method. + D107, + # Missing docstring in __init__. + D205, + # 1 blank line required between summary line and description. + D400, + # First line should end with a period. + E203, + # whitespace before ':'. Conflicts with how Black formats slicing. + E231, + # missing whitespace after ',', ';', or ':'. Conflicts with Black. + E266, + # too many leading '#' for block comment. + E402, + # module level import not at top of file. + E501, + # line too long (82 > 79 characters). Ignored because max-line-length is set. + F841, + # local variable is assigned to but never used. + I100, + # Import statements are in the wrong order. + I201, + # Missing newline between import groups. + I202, + # Additional newline in a group of imports. + W503 + # line break before binary operator. This is no longer PEP 8 compliant. exclude = .cache, .coverage.*, - .env, # Environment directory used by some tools - .git, # Version control directory - .github, # GitHub metadata directory + .env, + .git, + .github, .gradle, - .hg, # Mercurial directory - .mypy_cache, # MyPy cache directory - .pytest_cache, # PyTest cache directory - .svn, # Subversion directory + .hg, + .mypy_cache, + .pytest_cache, + .svn, .tox, - .venv, # Common virtual environment directory - .vscode, # VS Code configuration directory - *__pycache__, # Python cache directory + .venv, + .vscode, + *__pycache__, *.egg-info, *.pyc, build, dist, htmlcov.*, -application-import-names = flake8 # List of application-specific import names. -import-order-style = google # Import statement format style. -max-complexity = 18 # The maximum McCabe complexity allowed. -max-line-length = 120 # The maximum allowed line length. +# List of application-specific import names. +application-import-names = flake8 +# Import statement format style. +import-order-style = google +# The maximum McCabe complexity allowed. +max-complexity = 18 +# The maximum allowed line length. +max-line-length = 120 # per-file-ignores = # Per-file-ignores setting can be used to ignore specific errors in specific files. diff --git a/example/.pre-commit-config.yaml b/example/.pre-commit-config.yaml index 2984965..09b29e5 100644 --- a/example/.pre-commit-config.yaml +++ b/example/.pre-commit-config.yaml @@ -82,12 +82,12 @@ repos: - python # - repo: https://github.com/astral-sh/ruff-pre-commit - # rev: v0.0.270 + # rev: v0.1.4 # hooks: # - id: ruff # - repo: https://github.com/python-poetry/poetry - # rev: '1.4.0' + # rev: '1.7.0' # hooks: # - id: poetry-check # Makes sure the poetry configuration does not get committed in a broken state. # - id: poetry-lock # Ensures the poetry.lock file is up-to-date with the pyproject.toml changes. @@ -100,13 +100,12 @@ repos: hooks: - id: prettier # An opinionated code formatter supporting multiple languages. name: prettier - entry: prettier args: [--config, .cpa/prettier.json, --write] types_or: - - javascript + - css + - scss - ts - tsx - - scss - - css + - javascript - yaml - markdown diff --git a/example/pyproject.toml b/example/pyproject.toml index 65d53b1..797ef53 100644 --- a/example/pyproject.toml +++ b/example/pyproject.toml @@ -8,7 +8,7 @@ authors = [ license = "" [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["poetry-core>=1.7.0"] build-backend = "poetry.core.masonry.api" [tool.black] @@ -57,6 +57,6 @@ line_length = 120 python = "^3.10" [tool.poetry.group.dev.dependencies] -pre-commit = "^3.5.0" +pre-commit = ">=3.5.0" pytest = "^7.3.1" pytest-cov = "^4.1.0" diff --git a/src/python.rs b/src/python.rs index 564a8db..af44600 100644 --- a/src/python.rs +++ b/src/python.rs @@ -49,7 +49,7 @@ pub fn setup_preset(mut preset: String, name: String, create: bool) { preset = "python3.10".to_string(); } let mut prefix: String = "./".to_string(); - if !create { + if create { prefix = format!("./{}", name) } From df9abe2433f3e845d823240c80fd815df1400b05 Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sat, 4 Nov 2023 22:06:34 -0700 Subject: [PATCH 16/16] clean --- Dockerfile | 12 ---------- README.md | 6 ++--- main.py | 1 - pyproject.toml | 62 -------------------------------------------------- 4 files changed, 3 insertions(+), 78 deletions(-) delete mode 100644 Dockerfile delete mode 100644 main.py delete mode 100644 pyproject.toml diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 1b4b414..0000000 --- a/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM python:3.10-slim - -# Set the working directory in the container to /app -WORKDIR /app - -# Copy the current directory contents into the container at /app -COPY . . - -# Install any needed packages specified in requirements.txt -RUN pip install --no-cache-dir -r requirements.txt - -CMD ["python", "./main.py"] diff --git a/README.md b/README.md index 04f6aff..6c9a84b 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,15 @@ ## Overview -`cpa` is a cli tool for ultra fast setup of new Python projects. It automates the creation of config files for style & lint checks, gitignore, a basic Dockerfile and dependency management configuration. An opinionated set of pre-commit hooks are included for enforcing best practices and reducing setup time. +`cpa` is a cli tool for ultra fast setup of new Python projects. It automates the creation of config files for style & lint checks, gitignore, a basic Dockerfile and Poetry for dependency management. An opinionated set of pre-commit hooks are included for enforcing best practices and reducing dev time. ## Installation ### MacOS, Linux -Download latest binary and install via provided `install.sh` script or get it from [Releases](https://github.com/ysawa0/create-python-app/releases) +Download latest binary and install via provided `install.sh` or get it from [Releases](https://github.com/ysawa0/create-python-app/releases) -``` +```bash sh install.sh # cpa will be installed to ~/bin/cpa # add ~/bin to your PATH diff --git a/main.py b/main.py deleted file mode 100644 index ad35e5a..0000000 --- a/main.py +++ /dev/null @@ -1 +0,0 @@ -print("Hello World") diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index b0d3a44..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,62 +0,0 @@ -[tool.poetry] -name = "" -version = "0.0.1" -description = "" -authors = [ - "My Name " -] -license = "" - -[build-system] -requires = ["poetry-core>=1.7.0"] -build-backend = "poetry.core.masonry.api" - -[tool.black] -line-length = 120 -skip-string-normalization = false -target-version = ['py310'] -include = '\.pyi?$' -exclude = ''' -/( - \.eggs - | \.git - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist -)/ -''' -color = true - -[tool.isort] -balanced_wrapping = true -include_trailing_comma = true -known_first_party = "" -known_third_party = [ - "boto3", # Common for AWS - "django", # Common web framework, if used - "flask", # Common web framework, if used - "jinja2", # Common templating engine - "matplotlib", # Common for plotting - "numpy", # Common for numerical operations - "pandas", # Common for data manipulation - "pendulum", # Common for date time - "pytest", # Common for testing - "requests", # Common for HTTP requests - "sqlalchemy", # Common ORM for databases -] -multi_line_output = 3 -profile = "black" -line_length = 120 - -[tool.poetry.dependencies] -python = "^3.10" - -[tool.poetry.group.dev.dependencies] -pre-commit = ">=3.5.0" -pytest = "^7.3.1" -pytest-cov = "^4.1.0"