Skip to content

Commit

Permalink
Ruff (#772)
Browse files Browse the repository at this point in the history
* add .pre-commit-config.yaml

* add pyproject.toml

* ruff . --fix

* expand star import

* fix mutable default kwarg

* white space

* os.environ.get -> os.getenv

* add lint.yml, remove old lint job from testing.yml

* more white space

flagged by new lint action

* restore accidentally removed __init__ imports

use std lib importlib.metadata.version to get pkg version instead of setuptools_scm or pkg_resources
  • Loading branch information
janosh committed Apr 26, 2023
1 parent 53d30d8 commit 6316599
Show file tree
Hide file tree
Showing 82 changed files with 1,022 additions and 1,010 deletions.
3 changes: 1 addition & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[run]
omit =
omit =
*test*
*/resources.py
*/models.py
*/models/*
*/_consumer/client.py

2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ updates:
interval: weekly
time: '08:00'
timezone: US/Pacific
open-pull-requests-limit: 10
open-pull-requests-limit: 10
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Linting

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: pip

- name: Install dependencies
run: |
pip install pre-commit
- name: Run pre-commit
run: |
pre-commit run --all-files --show-diff-on-failure
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
release:
types: [published]


jobs:
deploy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -60,4 +59,4 @@ jobs:
uses: peaceiris/actions-gh-pages@v3.8.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_build
publish_dir: ./docs/_build
46 changes: 4 additions & 42 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,12 @@ name: testing

on:
push:
branches:
- main
branches: [main]

pull_request:
branches:
- main
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-testing.txt
- name: Lint with pycodestyle
run: |
pip install pycodestyle
pycodestyle mp_api
- name: Lint with mypy
run: |
mypy --namespace-packages --explicit-package-bases mp_api
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 --count --show-source --statistics mp_api
# exit-zero treats all errors as warnings.
flake8 --count --exit-zero --max-complexity=20 --statistics mp_api
test:
strategy:
max-parallel: 3
Expand Down Expand Up @@ -74,7 +38,7 @@ jobs:
- name: Set SSL_CERT_FILE (Windows)
if: matrix.os == 'windows-latest'
run: echo "SSL_CERT_FILE=$(python -m certifi)" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append

- name: Format API key name (Linux/MacOS)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: |
Expand All @@ -98,9 +62,7 @@ jobs:
file: ./coverage.xml

auto-gen-release:
needs:
- lint
- test
needs: [test]
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.API_VER_BUMP_TOKEN }}
Expand Down
41 changes: 29 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
default_stages: [commit]

default_install_hook_types: [pre-commit, commit-msg]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.261
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: flake8
- id: ruff
args: [--fix, --ignore, "D,E501"]

- repo: https://github.com/psf/black
rev: 22.8.0
rev: 23.3.0
hooks:
- id: black-jupyter

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
- repo: https://github.com/PyCQA/autoflake
rev: v1.5.3
- id: check-case-conflict
- id: check-symlinks
- id: check-yaml
- id: destroyed-symlinks
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: autoflake
- id: codespell
stages: [commit, commit-msg]
exclude_types: [json, bib, svg]
args: [--ignore-words-list, "mater,fwe,te"]
8 changes: 4 additions & 4 deletions docs/_templates/custom-class-template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
:members:
:show-inheritance:
:inherited-members:
:members:
:show-inheritance:
:inherited-members:

{% block methods %}
.. automethod:: __init__
Expand All @@ -29,4 +29,4 @@
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% endblock %}
16 changes: 8 additions & 8 deletions docs/_templates/custom-module-template.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{{ fullname | escape | underline}}

.. automodule:: {{ fullname }}

{% block attributes %}
{% if attributes %}
.. rubric:: Module Attributes

.. autosummary::
:toctree:
:toctree:
{% for item in attributes %}
{{ item }}
{%- endfor %}
Expand All @@ -19,7 +19,7 @@
.. rubric:: {{ _('Functions') }}

.. autosummary::
:toctree:
:toctree:
{% for item in functions %}
{{ item }}
{%- endfor %}
Expand All @@ -31,8 +31,8 @@
.. rubric:: {{ _('Classes') }}

.. autosummary::
:toctree:
:template: custom-class-template.rst
:toctree:
:template: custom-class-template.rst
{% for item in classes %}
{{ item }}
{%- endfor %}
Expand All @@ -44,7 +44,7 @@
.. rubric:: {{ _('Exceptions') }}

.. autosummary::
:toctree:
:toctree:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
Expand All @@ -57,10 +57,10 @@

.. autosummary::
:toctree:
:template: custom-module-template.rst
:template: custom-module-template.rst
:recursive:
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% endblock %}
Loading

0 comments on commit 6316599

Please sign in to comment.