From 7431372c882c1922288ab758505115ff69069dad Mon Sep 17 00:00:00 2001 From: jorricks Date: Tue, 8 Mar 2022 09:31:20 +0100 Subject: [PATCH] Add pre-commit --- .flake8 | 4 +++ .github/workflows/lint.yml | 26 -------------- .github/workflows/pre-commit.yml | 12 +++++++ .pre-commit-config.yaml | 58 ++++++++++++++++++++++++++++++++ README.md | 6 ++++ pyproject.toml | 16 +++++++++ setup.py | 3 ++ 7 files changed, 99 insertions(+), 26 deletions(-) create mode 100644 .flake8 delete mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/pre-commit.yml create mode 100644 pyproject.toml diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..eb719aae --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +# Default ignores that we can extend +ignore=D100 +max-line-length=120 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 085af01d..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Lint code -on: - push: - pull_request: - -jobs: - PythonBlack: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Check code lints with Black - uses: psf/black@stable - - Prettier: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - uses: actions/setup-node@v2 - - - name: Install Prettier - run: npm install -g prettier - - - name: Run Prettier --check - run: prettier --check ${GITHUB_WORKSPACE} diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..92de037e --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,12 @@ +name: Lint code +on: + push: + pull_request: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - uses: pre-commit/action@v2.0.3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e69de29b..3b16b94a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -0,0 +1,58 @@ +minimum_pre_commit_version: "2.9.2" +repos: + - repo: meta + hooks: + - id: identity + - id: check-hooks-apply + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "" # Can not be removed, so leave this empty. + hooks: + - id: prettier + - repo: local + hooks: + - id: no-relative-imports + name: No relative imports. + description: Use absolute imports only. + entry: "^\\s*from\\s+\\." + language: pygrep + - id: isort + name: iSort - Sorts imports. + description: Sorts your import for you. + entry: isort + args: ["--settings-path=pyproject.toml"] + language: python + types: [python] + require_serial: true + additional_dependencies: + - isort + - id: black + name: Black - Auto-formatter. + description: Black is the uncompromising Python code formatter. Writing to files. + entry: black + args: ["--config=pyproject.toml"] + language: python + types: [python] + require_serial: true + additional_dependencies: + - black + - id: flake8 + name: Flake8 - Enforce code style and doc. + description: A command-line utility for enforcing style consistency across Python projects. + entry: flake8 + args: ["--config=.flake8"] + language: python + types: [python] + require_serial: true + additional_dependencies: + - flake8 + - flake8-docstrings + - id: mypy + name: mypy - Static type checking + description: Mypy helps ensure that we use our functions and variables correctly by checking the types. + entry: mypy + args: ["--ignore-missing-imports", "--scripts-are-modules"] + language: python + types: [python] + require_serial: true + additional_dependencies: + - mypy diff --git a/README.md b/README.md index c9f1654c..3b881427 100644 --- a/README.md +++ b/README.md @@ -339,6 +339,12 @@ Contributions and suggestions for new features are welcome, as are bug reports! Please create a new [issue](https://github.com/ewels/rich-click/issues) or better still, dive right in with a pull-request. +### Local setup +1. Create a new venv with a python3.6+ interpreter using `python3 -m venv venv` +2. Activate the venv with `source venv/bin/activate` +3. Install our the package as an editable including all dev dependencies with `pip3 install -e ."[dev]"` +4. Install pre-commit with `pre-commit install` + ## Credits This package was written by Phil Ewels ([@ewels](http://github.com/ewels/)), diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..45f3b8f8 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[tool.black] +line-length=120 +target-version=['py36'] + +[tool.isort] +line_length = 120 +multi_line_output = 3 +force_alphabetical_sort_within_sections = "True" +force_sort_within_sections = "False" +known_richclick = ["rich_click"] +sections=["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER", "RICHCLICK"] +profile = "black" + +[tool.mypy] +python_version = "3.6" +ignore_missing_imports = "True" diff --git a/setup.py b/setup.py index 2bc86a7c..ecb96c93 100644 --- a/setup.py +++ b/setup.py @@ -7,4 +7,7 @@ "rich>=10", "importlib-metadata; python_version < '3.8'", ], + extras_require={ + "dev": ["pre-commit"], + }, )