Use pre-commit to streamline development (#229)

* Use pre-commit to streamline development

* Specify linting stage in travis config
This commit is contained in:
Jim Brännlund 2019-08-12 20:11:52 +02:00 committed by GitHub
parent b69dde56a3
commit 49a36a4de7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 99 additions and 40 deletions

15
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,15 @@
repos:
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
args: [--safe, --quiet]
language_version: python3
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.7
hooks:
- id: flake8
exclude: docs
language_version: python3

View File

@ -8,16 +8,14 @@ jobs:
script: grunt test
-
name: Linting
python: 3.7
dist: xenial
sudo: required
env: TOXENV=flake8
-
python: 3.7
dist: xenial
sudo: required
env: TOXENV=black
env: TOXENV=linting
cache:
directories:
- $HOME/.cache/pre-commit
-
python: 2.7

View File

@ -8,6 +8,7 @@ pytest = "*"
tox = "*"
flake8 = "*"
black = "*"
pre-commit = "*"
[packages]
pytest-html = {editable = true,path = "."}

View File

@ -253,28 +253,9 @@ Screenshots
Contributing
------------
Fork the repository and submit PRs with bug fixes and enhancements, contributions are very welcome.
We welcome contributions.
Tests can be run locally with `tox`_, for example to execute tests for Python 2.7 and 3.6 execute::
tox -e py27,py36
.. _`tox`: https://tox.readthedocs.org/en/latest/
Releasing a new version
-----------------------
Follow these steps to release a new version of the project:
1. Update your local master with the upstream master (``git pull --rebase upstream master``)
2. Create a new branch and update ``CHANGES.rst`` with the new version, today's date, and all changes/new features
3. Commit and push the new branch and then create a new pull request
4. Wait for tests and reviews and then merge the branch
5. Once merged, update your local master again (``git pull --rebase upstream master``)
6. Tag the release with the new release version (``git tag v<new tag>``)
7. Push the tag (``git push upstream --tags``)
8. Done. You can monitor the progress on `Travis <https://travis-ci.org/pytest-dev/pytest-html/>`_
To learn more, see `Development <https://github.com/pytest-dev/pytest-html/blob/master/development.rst>`_
Resources
---------

70
developtment.rst Normal file
View File

@ -0,0 +1,70 @@
Development
===========
To contribute to `pytest-html` you can use `Pipenv`_ to manage
a python virtual environment and `pre-commit <https://pre-commit.com/>`_ to help you with
styling and formatting.
To setup the virtual environment and pre-commit, run:
.. code-block:: bash
$ pipenv install --dev
$ pipenv run pre-commit install
If you're not using `Pipenv`_, to install `pre-commit`, run:
.. code-block:: bash
$ pip install pre-commit
$ pre-commit install
Automated Testing
-----------------
All pull requests and merges are tested in `Travis CI <https://travis-ci.org/>`_
based on the ``.travis.yml`` file.
Usually, a link to your specific travis build appears in pull requests, but if
not, you can find it on the
`pull requests page <https://travis-ci.org/pytest-dev/pytest-html/pull_requests>`_
The only way to trigger Travis CI to run again for a pull request, is to submit
another change to the pull branch.
You can do this with `git commit --allow-empty`
Running Tests
-------------
You will need `Tox <http://tox.testrun.org/>`_ installed to run the tests
against the supported Python versions. If you're using `Pipenv`_ it will be
installed for you.
With `Pipenv`_, run:
.. code-block:: bash
$ pipenv run tox
Otherwise, to install and run, do:
.. code-block:: bash
$ pip install tox
$ tox
Releasing a new version
-----------------------
Follow these steps to release a new version of the project:
1. Update your local master with the upstream master (``git pull --rebase upstream master``)
2. Create a new branch and update ``CHANGES.rst`` with the new version, today's date, and all changes/new features
3. Commit and push the new branch and then create a new pull request
4. Wait for tests and reviews and then merge the branch
5. Once merged, update your local master again (``git pull --rebase upstream master``)
6. Tag the release with the new release version (``git tag v<new tag>``)
7. Push the tag (``git push upstream --tags``)
8. Done. You can monitor the progress on `Travis <https://travis-ci.org/pytest-dev/pytest-html/>`_

18
tox.ini
View File

@ -4,7 +4,7 @@
# and then run "tox" from this directory.
[tox]
envlist = py{27,36,37,py,py3}{,-ansi2html}, flake8, black
envlist = py{27,36,37,py,py3}{,-ansi2html}, linting
[testenv]
setenv = PYTHONDONTWRITEBYTECODE=1
@ -15,17 +15,11 @@ deps =
py{27,36,py,py3}-ansi2html: ansi2html
commands = pytest -v -r a {posargs}
[testenv:flake8]
skip_install = true
basepython = python
deps = flake8
commands = flake8 {posargs:.}
[testenv:black]
skip_install = true
basepython = python
deps = black
commands = black --check {posargs:.}
[testenv:linting]
skip_install = True
basepython = python3
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure
[flake8]
max-line-length = 88