From a3e8c9c2ff005919925bac7343b2707aa906477b Mon Sep 17 00:00:00 2001 From: Martin Majlis Date: Fri, 23 Feb 2024 09:42:12 +0100 Subject: [PATCH] Add code quality checks for commits (#85) * Add code quality checks for commits * Update travis covig file * Fix branch in Check code quality action * Add types for setuptools * Call the correct make target --- .codeclimate.yml | 4 +-- .github/workflows/code-quality.yml | 38 ++++++++++++++++++++++++ .gitignore | 3 +- .pre-commit-config.yaml | 46 ++++++++++++------------------ .readthedocs.yml | 2 +- .travis.yml | 34 ++++++++++------------ CODE_OF_CONDUCT.md | 20 ++++++------- Makefile | 1 + README.rst | 3 +- requirements-dev.txt | 3 ++ requirements.txt | 1 - wikipediaapi/api.rst | 2 +- 12 files changed, 93 insertions(+), 64 deletions(-) create mode 100644 .github/workflows/code-quality.yml diff --git a/.codeclimate.yml b/.codeclimate.yml index ae030a3..2a3762d 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -17,5 +17,5 @@ engines: ratings: paths: - - "wikipediaapi/**.py" - - "tests/**.py" + - "wikipediaapi/**.py" + - "tests/**.py" diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 0000000..602b6b4 --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,38 @@ +name: Check code quality + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + code-quality-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.11 + - name: Install pre-commit + run: | + python -m pip install -U pip + make requirements-dev + make requirements + - name: Install pre-commit hooks + run: | + pre-commit install + - name: Run pre-commit + run: | + pre-commit run -a + - name: Code coverage + run: | + make run-coverage + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: martin-majlis/Wikipedia-API diff --git a/.gitignore b/.gitignore index f492fac..52987bf 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ htmlcov/ .cache nosetests.xml coverage.xml +coverage.json *.cover .hypothesis/ @@ -218,4 +219,4 @@ modules.xml -# End of https://www.gitignore.io/api/pycharm+all,jetbrains+all \ No newline at end of file +# End of https://www.gitignore.io/api/pycharm+all,jetbrains+all diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5cbd38f..5d8a373 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,37 +26,27 @@ repos: hooks: - id: prettier - # - repo: https://github.com/pre-commit/mirrors-autopep8 - # rev: "v1.5.6" - # hooks: - # - id: autopep8 - - - repo: https://github.com/pycqa/isort - rev: 5.12.0 + - repo: local hooks: - id: isort + name: Run isort + entry: isort + language: python args: ["--profile", "google", "--filter-files"] - - # - repo: https://github.com/asottile/pyupgrade - # rev: v3.2.2 - # hooks: - # - id: pyupgrade - # args: [--py36-plus] - - - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: + types: [file, python] + - id: black + name: Run black + entry: black + language: python + types: [file, python] - id: flake8 + name: Run flake8 + entry: flake8 + language: python additional_dependencies: [flake8-bugbear] - - - repo: https://github.com/psf/black - rev: 23.3.0 - hooks: - - id: black - - - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.1 - hooks: + types: [file, python] - id: mypy - additional_dependencies: - ["types-requests", "types-cachetools", "types-aiofiles"] + name: Run mypy + entry: mypy + language: python + types: [file, python] diff --git a/.readthedocs.yml b/.readthedocs.yml index 50fa46a..3916c1f 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,3 +1,3 @@ python: # version: 3.6 - setup_py_install: true \ No newline at end of file + setup_py_install: true diff --git a/.travis.yml b/.travis.yml index 56e10fd..09719e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,28 +5,24 @@ env: language: python python: -- '3.4' -- '3.5' -- '3.6' -- '3.7' -- '3.8' -- '3.9' -- '3.10' -- '3.11' + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" install: -- pip install -r requirements.txt -- pip install coverage -- pip install coveralls + - pip install -r requirements.txt + - pip install coverage + - pip install coveralls before_script: -- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter -- chmod +x ./cc-test-reporter -- ./cc-test-reporter before-build + - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + - chmod +x ./cc-test-reporter + - ./cc-test-reporter before-build script: -- make run-coverage -- coverage xml + - make run-coverage after_script: -- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT -- coveralls + - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT + - coveralls deploy: provider: pypi skip_existing: true @@ -36,4 +32,4 @@ deploy: on: tags: true after_sucess: -- CODECLIMATE_REPO_TOKEN=d62b9e265b625e28f256147e9636d8fc1abe9f540d4fc82f9f8976171676cec4 codeclimate-test-reporter + - CODECLIMATE_REPO_TOKEN=d62b9e265b625e28f256147e9636d8fc1abe9f540d4fc82f9f8976171676cec4 codeclimate-test-reporter diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index a42366e..ad6fcc3 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -8,19 +8,19 @@ In the interest of fostering an open and welcoming environment, we as contributo Examples of behavior that contributes to creating a positive environment include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting +- The use of sexualized language or imagery and unwelcome sexual attention or advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities diff --git a/Makefile b/Makefile index f5e1c1c..c74b80b 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ run-tox: run-coverage: coverage run --source=wikipediaapi -m unittest discover tests/ '*test.py' coverage report -m + coverage xml requirements: pip3 install -r requirements.txt diff --git a/README.rst b/README.rst index 8f79595..70b1725 100644 --- a/README.rst +++ b/README.rst @@ -292,8 +292,9 @@ This will help you determine if the problem is in the library or somewhere else. .. code-block:: python - import wikipediaapi import sys + + import wikipediaapi wikipediaapi.log.setLevel(level=wikipediaapi.logging.DEBUG) # Set handler if you use Python in interactive mode diff --git a/requirements-dev.txt b/requirements-dev.txt index dc9d0e9..73b6e50 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,6 +3,9 @@ coverage==7.4.2 flake8==7.0.0 isort==5.12.0 mypy==1.4.1 +pre-commit==3.3 pygments==2.17.2 sphinx==7.0.1 tox==4.6.3 +types-requests==2.31.0 +types-setuptools==69.1.0.20240223 diff --git a/requirements.txt b/requirements.txt index 6ac85c6..2c24336 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ requests==2.31.0 -typing diff --git a/wikipediaapi/api.rst b/wikipediaapi/api.rst index c037c51..4aa372a 100644 --- a/wikipediaapi/api.rst +++ b/wikipediaapi/api.rst @@ -20,4 +20,4 @@ :members: :undoc-members: :member-order: bysource - :exclude-members: __module__, __weakref__ \ No newline at end of file + :exclude-members: __module__, __weakref__