Skip to content

Commit

Permalink
feat: Add prettier configuration to the root project and template (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anavelyz authored Mar 8, 2024
1 parent 5a6f0b4 commit e57579c
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 73 deletions.
8 changes: 6 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ root = true

[*]
indent_style = space
indent_size = 4
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
end_of_line = lf

[*.py]
indent_style = space
indent_size = 4

[*.bat]
indent_style = tab
end_of_line = crlf

[LICENSE]
insert_final_newline = false
insert_final_newline = true

[Makefile]
indent_style = tab
Expand Down
89 changes: 47 additions & 42 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,54 @@ repos:
hooks:
- id: end-of-file-fixer

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.2"
hooks:
- id: prettier

- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy
files: "src/scicookie/"
language: system
pass_filenames: true
# pre-commit + mypy doesn't honor the exclusion defined in the config
exclude: |
(?x)(
src/scicookie/{{cookiecutter.project_slug}}/
| src/scicookie/hooks
)
types:
- python
- id: mypy
name: mypy
entry: mypy
files: "src/scicookie/"
language: system
pass_filenames: true
# pre-commit + mypy doesn't honor the exclusion defined in the config
exclude: |
(?x)(
src/scicookie/{{cookiecutter.project_slug}}/
| src/scicookie/hooks
)
types:
- python

- id: ruff format
name: ruff format
entry: ruff format
language: system
pass_filenames: true
files: "./"
# pre-commit + ruff doesn't honor the exclusion defined in the config
exclude: |
(?x)(
src/scicookie/{{cookiecutter.project_slug}}
| src/scicookie/hooks
)
types:
- python
- id: ruff format
name: ruff format
entry: ruff format
language: system
pass_filenames: true
files: "./"
# pre-commit + ruff doesn't honor the exclusion defined in the config
exclude: |
(?x)(
src/scicookie/{{cookiecutter.project_slug}}
| src/scicookie/hooks
)
types:
- python

- id: ruff check
name: ruff check
entry: ruff check
language: system
pass_filenames: true
files: "./"
# pre-commit + ruff doesn't honor the exclusion defined in the config
exclude: |
(?x)(
src/scicookie/{{cookiecutter.project_slug}}
| src/scicookie/hooks
)
types:
- python
- id: ruff check
name: ruff check
entry: ruff check
language: system
pass_filenames: true
files: "./"
# pre-commit + ruff doesn't honor the exclusion defined in the config
exclude: |
(?x)(
src/scicookie/{{cookiecutter.project_slug}}
| src/scicookie/hooks
)
types:
- python
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.makim.yaml
docs/changelog.md
CHANGELOG.md
src/scicookie/{{cookiecutter.project_slug}}
35 changes: 7 additions & 28 deletions src/scicookie/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,9 @@
"GNU General Public License v3",
"Other"
],
"project_layout": [
"src",
"flat"
],
"command_line_interface": [
"None",
"Click",
"Argparse"
],
"documentation_engine":[
"mkdocs",
"sphinx",
"jupyter-book"
],
"project_layout": ["src", "flat"],
"command_line_interface": ["None", "Click", "Argparse"],
"documentation_engine": ["mkdocs", "sphinx", "jupyter-book"],
"documentation_url": "{{ cookiecutter.project_url }}",
"code_of_conduct": [
"None",
Expand All @@ -37,15 +26,8 @@
"numfocus-adapted-coc",
"python-adapted-coc"
],
"governance_document": [
"None",
"numpy-governance",
"sciml-governance"
],
"roadmap_document": [
"None",
"pytorch-ignite-roadmap"
],
"governance_document": ["None", "numpy-governance", "sciml-governance"],
"roadmap_document": ["None", "pytorch-ignite-roadmap"],
"build_system": [
"poetry",
"flit",
Expand All @@ -62,18 +44,15 @@
"use_conda": "yes",
"use_makim": "yes",
"use_make": "no",
"use_containers": [
"None",
"Docker",
"Podman"
],
"use_containers": ["None", "Docker", "Podman"],
"use_coverage": "no",
"use_flake8": "no",
"use_hypothesis": "no",
"use_isort": "no",
"use_mccabe": "no",
"use_mypy": "no",
"use_pre_commit": "yes",
"use_prettier": "no",
"use_pydocstyle": "no",
"use_pytest": "yes",
"use_ruff": "yes",
Expand Down
6 changes: 6 additions & 0 deletions src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
USE_MAKE = {{ cookiecutter.use_make == "yes" }}
USE_MAKIM = {{ cookiecutter.use_makim == "yes" }}
USE_MYPY = {{ cookiecutter.use_mypy == "yes" }}
USE_PRETTIER = {{ cookiecutter.use_prettier == "yes" }}
{% if cookiecutter.code_of_conduct == "contributor-covenant" -%}
COC_PATH = PROJECT_DIRECTORY / 'coc' / 'CONTRIBUTOR_COVENANT.md'
{%- elif cookiecutter.code_of_conduct == "citizen-code-of-conduct" -%}
Expand Down Expand Up @@ -175,6 +176,10 @@ def clean_up_cli():
if not USE_CLI:
remove_package_file("__main__.py")

def clean_up_prettier():
if not USE_PRETTIER:
remove_project_file(".prettierrc.yaml")
remove_project_file(".prettierignore")

def clean_up_build_system():
build_system_dir = PROJECT_DIRECTORY / "build-system"
Expand Down Expand Up @@ -368,6 +373,7 @@ def post_gen():
clean_up_governance()
clean_up_roadmap()
clean_up_build_system()
clean_up_prettier()

# keep it at the end, because it will create a new git commit
prepare_git()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ repos:
rev: v4.1.0
hooks:
- id: end-of-file-fixer

{# keep this comment #}
{%- if cookiecutter.use_prettier == "yes" %}
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.2"
hooks:
- id: prettier
{% endif %}
- repo: local
hooks:
# NOTE: This is a total unnecessary check, just used as part of the
Expand Down
4 changes: 4 additions & 0 deletions src/scicookie/{{cookiecutter.project_slug}}/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{%- if cookiecutter.use_makim == "yes" %}
.makim.yaml
{%- endif %}
docs/changelog.md
6 changes: 6 additions & 0 deletions src/scicookie/{{cookiecutter.project_slug}}/.prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
overrides:
- files: "*.md"
options:
parser: remark
proseWrap: always
printWidth: 80
1 change: 1 addition & 0 deletions tests/smoke/linters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SMOKE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
${SMOKE_DIR}/base.sh "use_mccabe=yes"
${SMOKE_DIR}/base.sh "use_mypy=yes"
${SMOKE_DIR}/base.sh "use_pre_commit=yes"
${SMOKE_DIR}/base.sh "use_prettier=yes"
${SMOKE_DIR}/base.sh "use_pydocstyle=yes"
${SMOKE_DIR}/base.sh "use_ruff=yes"
${SMOKE_DIR}/base.sh "use_shellcheck=yes"
Expand Down

0 comments on commit e57579c

Please sign in to comment.