Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run black locally with nox #776

Merged
merged 3 commits into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 12 additions & 3 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 .
```
21 changes: 19 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
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()
Expand Down