Run black locally with nox (#776)

* Run black locally with nox

* Update contributor instructions

* Fix workflow
pull/787/head
Pieter Marsman 2022-06-26 18:25:28 +02:00 committed by GitHub
parent 4733eb333a
commit 8f52578e85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 34 deletions

View File

@ -1,25 +1,15 @@
**Pull request**
Please remove this paragraph and replace it with a description of your PR.
Also include links to the issues that it fixes.
Please *remove* this paragraph and replace it with a description of your PR. Also include the issue that it fixes.
**How Has This Been Tested?**
Please repalce this paragraph with a description of how this PR has been
tested. Include the necessary instructions and files such that other can
reproduce it.
Please *remove* this paragraph with a description of how this PR has been tested.
**Checklist**
- [ ] I have formatted my code with [black](https://github.com/psf/black).
- [ ] I have added tests that prove my fix is effective or that my feature
works
- [ ] I have added docstrings to newly created methods and classes
- [ ] I have optimized the code at least one time after creating the initial
version
- [ ] I have updated the [README.md](../README.md) or verified that this
is not necessary
- [ ] I have updated the [readthedocs](../docs/source) documentation or
verified that this is not necessary
- [ ] I have added a concise human-readable description of the change to
[CHANGELOG.md](../CHANGELOG.md)
- [ ] I have read [CONTRIBUTING.md](../CONTRIBUTING.md).
- [ ] I have added a concise human-readable description of the change to [CHANGELOG.md](../CHANGELOG.md).
- [ ] I have tested that this fix is effective or that this feature works.
- [ ] I have added docstrings to newly created methods and classes.
- [ ] I have updated the [README.md](../README.md) and the [readthedocs](../docs/source) documentation. Or verified that this is not necessary.

View File

@ -16,13 +16,22 @@ env:
jobs:
check-code-formatting:
name: Check code formatting
name: Check coding style
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check code formatting
uses: psf/black@stable
- name: Set up Python ${{ env.default-python }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.default-python }}
- name: Upgrade pip, Install nox
run: |
python -m pip install --upgrade pip
python -m pip install nox
- name: Check coding style
run: |
nox --error-on-missing-interpreters --non-interactive --session format
check-coding-style:
name: Check coding style

View File

@ -26,20 +26,25 @@ Any contribution is appreciated! You might want to:
## Guideline for creating pull request
* A pull request should close an existing issue.
* Pull requests should be merged to master. Version tags are used indicate the releases.
* A pull request should close an existing issue. For example, use "Fix #123" to indicate that your PR fixes issue 123.
* Pull requests should be merged to master.
* Include unit tests when possible. In case of bugs, this will help to prevent the same mistake in the future. In case
of features, this will show that your code works correctly.
* Code should work for Python 3.6+.
* Code should be formatted with [black](https://github.com/psf/black).
* Test your code by using nox (see below).
* New features should be well documented using docstrings.
* Check if the [README.md](../README.md) or [readthedocs](../docs/source) documentation needs to be updated.
* Check spelling and grammar.
* Don't forget to update the [CHANGELOG.md](CHANGELOG.md#[Unreleased])
* Don't forget to update the [CHANGELOG.md](CHANGELOG.md#[Unreleased]).
## Guidelines for posting comments
* [Be cordial and positive](https://www.kennethreitz.org/essays/be-cordial-or-be-on-your-way)
## Guidelines for publishing
* Publishing is automated. Add a YYYYMMDD version tag and GitHub workflows will do the rest.
## Getting started
1. Clone the repository
@ -68,9 +73,3 @@ Any contribution is appreciated! You might want to:
```sh
nox -e py36
```
4. After changing the code, run the black formatter.
```sh
black .
```

View File

@ -1,20 +1,37 @@
import os
import nox
PYTHON_ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"]
PYTHON_MODULES = ["pdfminer", "tools", "tests", "noxfile.py", "setup.py"]
@nox.session
def format(session):
session.install("black")
# Format files locally with black, but only check in cicd
if "CI" in os.environ:
session.run("black", "--check", *PYTHON_MODULES)
else:
session.run("black", *PYTHON_MODULES)
@nox.session
def lint(session):
session.install("flake8")
session.run("flake8", "pdfminer/", "tools/", "tests/", "--count", "--statistics")
session.run("flake8", *PYTHON_MODULES, "--count", "--statistics")
@nox.session
def types(session):
session.install("mypy")
session.run(
"mypy", "--install-types", "--non-interactive", "--show-error-codes", "."
"mypy",
"--install-types",
"--non-interactive",
"--show-error-codes",
*PYTHON_MODULES,
)

View File

@ -5,8 +5,7 @@ from setuptools import setup
from os import path
sys.path.append(str(Path(__file__).parent))
import pdfminer as package
import pdfminer as package # noqa: E402
with open(path.join(path.abspath(path.dirname(__file__)), "README.md")) as f:
readme = f.read()