diff --git a/README.md b/README.md index 04c74e4..bbdea23 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ source venv/bin/activate 2. Install necessary files ```sh -python -m pip install cruft packaging ruff black +python -m pip install cruft packaging ruff ``` 3. Generate the project using this template diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 5f677e8..6a1def0 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -120,18 +120,14 @@ def check_for_files() -> None: def error_msg(pkg: str) -> str: return f"`{pkg}` is not installed. Run `pip install {pkg}` to install it." -def run_ruff_fix_and_black() -> None: - """checks if ruff and black are installed and runs them on the project""" +def run_ruff_lint_and_format() -> None: + """checks if ruff are installed and runs it on the project""" if importlib.util.find_spec("ruff"): - subprocess.run(["python3", "-m" "ruff", "--fix", "src"]) + subprocess.run(["python3", "-m" "ruff", "check", "--fix", "src"]) + subprocess.run(["python3", "-m", "ruff", "format", "src"]) else: logging.warning(error_msg("ruff")) - if importlib.util.find_spec("black"): - subprocess.run(["python3", "-m", "black", "src", "-q", "--config", "pyproject.toml"]) - else: - logging.warning(error_msg("black")) - def run_bicep_format() -> None: """formats your bicep files""" subprocess.run(["az", "bicep", "format", "--file", "infra/main.bicep"]) @@ -139,11 +135,11 @@ def run_bicep_format() -> None: def lint() -> None: """Runs all linters""" - run_ruff_fix_and_black() + run_ruff_lint_and_format() run_bicep_format() if __name__ == "__main__": rich.print("Removing unecessary files") check_for_files() - rich.print("Linting files") + rich.print("Linting and formatting files") lint() diff --git a/requirements.in b/requirements.in index 12e7b51..c756856 100644 --- a/requirements.in +++ b/requirements.in @@ -3,8 +3,7 @@ cookiecutter packaging # linting -ruff -black +ruff<=0.1.6 # testing pytest diff --git a/requirements.txt b/requirements.txt index fdcd449..db485a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.12 # by the following command: # # pip-compile requirements.in @@ -8,8 +8,6 @@ arrow==1.2.3 # via cookiecutter binaryornot==0.4.4 # via cookiecutter -black==23.7.0 - # via -r requirements.in certifi==2023.7.22 # via requests chardet==5.2.0 @@ -17,9 +15,7 @@ chardet==5.2.0 charset-normalizer==3.2.0 # via requests click==8.1.6 - # via - # black - # cookiecutter + # via cookiecutter cookiecutter==2.3.0 # via # -r requirements.in @@ -36,17 +32,10 @@ markupsafe==2.1.3 # via jinja2 mdurl==0.1.2 # via markdown-it-py -mypy-extensions==1.0.0 - # via black packaging==23.1 # via # -r requirements.in - # black # pytest -pathspec==0.11.2 - # via black -platformdirs==3.10.0 - # via black pluggy==1.2.0 # via pytest pygments==2.16.1 @@ -67,7 +56,7 @@ requests==2.31.0 # via cookiecutter rich==13.5.2 # via cookiecutter -ruff==0.0.284 +ruff==0.1.6 # via -r requirements.in six==1.16.0 # via python-dateutil diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index fbe1258..f96a282 100644 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -18,7 +18,7 @@ def test_project_generation(bakery): def test_project_post_hook_triggers_warning_if_linters_not_installed( cookies_session, default_context, mocker, caplog ): - """If ruff or black is not installed, the post hook should trigger a warning""" + """If ruff is not installed, the post hook should trigger a warning""" mocker.patch("hooks.post_gen_project.importlib.util.find_spec", return_value=None) diff --git a/{{cookiecutter.__src_folder_name}}/.devcontainer/devcontainer.json b/{{cookiecutter.__src_folder_name}}/.devcontainer/devcontainer.json index c275d58..4d51be2 100644 --- a/{{cookiecutter.__src_folder_name}}/.devcontainer/devcontainer.json +++ b/{{cookiecutter.__src_folder_name}}/.devcontainer/devcontainer.json @@ -24,7 +24,6 @@ "ms-azuretools.vscode-bicep", "charliermarsh.ruff", "ms-python.python", - "ms-python.black-formatter", {% if cookiecutter.project_host == "aca" %} "ms-azuretools.vscode-docker", {% endif %} @@ -55,6 +54,14 @@ ".coverage": true, ".pytest_cache": true, "__pycache__": true + }, + [python]: { + "editor.formatOnSave": true, + "editor.defaultFormatter": "charliermarsh.ruff", + "editor.codeActionsOnSave": { + "source.organizeImports": true, + "source.fixAll": true + } } } } diff --git a/{{cookiecutter.__src_folder_name}}/.github/workflows/format.yml b/{{cookiecutter.__src_folder_name}}/.github/workflows/format.yml index d29fe9d..d455bd9 100644 --- a/{{cookiecutter.__src_folder_name}}/.github/workflows/format.yml +++ b/{{cookiecutter.__src_folder_name}}/.github/workflows/format.yml @@ -25,6 +25,6 @@ jobs: python -m pip install --upgrade pip pip install -r requirements-dev.in - name: Lint with ruff - run: ruff . - - name: Check formatting with black - run: black . --check --verbose + run: | + ruff check . + ruff format. diff --git a/{{cookiecutter.__src_folder_name}}/pyproject.toml b/{{cookiecutter.__src_folder_name}}/pyproject.toml index 21f5de8..4a60ec3 100644 --- a/{{cookiecutter.__src_folder_name}}/pyproject.toml +++ b/{{cookiecutter.__src_folder_name}}/pyproject.toml @@ -2,6 +2,7 @@ line-length = 120 select = ["E", "F", "I", "UP"] ignore = ["D203"] +extend-exclude = ["flaskapp/migrations/"] [tool.ruff.isort] {% if cookiecutter.project_backend == "flask" %} @@ -11,22 +12,6 @@ known-first-party = ["flaskapp"] known-first-party = ["fastapi_app"] {% endif %} -[tool.black] -line-length = 120 -{% if cookiecutter.project_backend == "flask" %} -extend-exclude = ''' -( - flaskapp/migrations/ -) -''' -force-exclude = ''' -# Needed for pre-commit -( - flaskapp/migrations/ -) -''' -{% endif %} - [tool.pytest.ini_options] addopts = "-ra -vv" {% if cookiecutter.project_backend == "django" %} diff --git a/{{cookiecutter.__src_folder_name}}/requirements-dev.in b/{{cookiecutter.__src_folder_name}}/requirements-dev.in index 9ee96a5..8258896 100644 --- a/{{cookiecutter.__src_folder_name}}/requirements-dev.in +++ b/{{cookiecutter.__src_folder_name}}/requirements-dev.in @@ -16,4 +16,3 @@ pytest-playwright # Linters ruff -black