MOTOR-896 Set up pre-commit (#145)
This commit is contained in:
parent
1e62b868ea
commit
59a3e3229b
@ -23,7 +23,7 @@ export GSSAPI_PORT=${SASL_PORT}
|
||||
export GSSAPI_PRINCIPAL=${PRINCIPAL}
|
||||
|
||||
# Pass needed env variables to the test environment.
|
||||
export TOX_TESTENV_PASSENV=*
|
||||
export TOX_TESTENV_PASSENV="*"
|
||||
|
||||
# --sitepackages allows use of pykerberos without a test dep.
|
||||
/opt/python/3.6/bin/python3 -m tox -e "$TOX_ENV" --sitepackages -- -x test.test_auth
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -o xtrace # Write all commands first to stderr
|
||||
set -o errexit # Exit the script with error if any of the commands fail
|
||||
|
||||
|
||||
2
.git-blame-ignore-revs
Normal file
2
.git-blame-ignore-revs
Normal file
@ -0,0 +1,2 @@
|
||||
# Initial pre-commit reformat
|
||||
1e62b868ea58afeb42b3d0346e33776561c16ab6
|
||||
45
.github/workflows/test-python.yml
vendored
Normal file
45
.github/workflows/test-python.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Python Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
|
||||
pre-commit:
|
||||
name: pre-commit
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-python@v2
|
||||
- uses: pre-commit/action@v2.0.0
|
||||
with:
|
||||
extra_args: --all-files --hook-stage=manual
|
||||
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
python-version: ["3.6", "3.10"]
|
||||
fail-fast: false
|
||||
name: CPython ${{ matrix.python-version }}-${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: 'pip'
|
||||
cache-dependency-path: 'setup.py'
|
||||
- name: Start MongoDB with Custom Options
|
||||
run: |
|
||||
mkdir data
|
||||
mongod --fork --dbpath=$(pwd)/data --logpath=$PWD/mongo.log --setParameter enableTestCommands=1
|
||||
- name: Install Python dependencies
|
||||
run: |
|
||||
python -m pip install -U pip tox tox-gh-actions
|
||||
- name: Run tests
|
||||
run: |
|
||||
tox
|
||||
49
.pre-commit-config.yaml
Normal file
49
.pre-commit-config.yaml
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v3.4.0
|
||||
hooks:
|
||||
- id: check-added-large-files
|
||||
- id: check-case-conflict
|
||||
- id: check-toml
|
||||
- id: check-yaml
|
||||
- id: debug-statements
|
||||
- id: end-of-file-fixer
|
||||
exclude: WHEEL
|
||||
exclude_types: [json]
|
||||
- id: forbid-new-submodules
|
||||
- id: trailing-whitespace
|
||||
exclude: .patch
|
||||
exclude_types: [json]
|
||||
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 22.1.0
|
||||
hooks:
|
||||
- id: black
|
||||
files: \.py$
|
||||
args: [--line-length=100]
|
||||
|
||||
- repo: https://github.com/PyCQA/isort
|
||||
rev: 5.7.0
|
||||
hooks:
|
||||
- id: isort
|
||||
files: \.py$
|
||||
args: [--profile=black]
|
||||
|
||||
# We use the Python version instead of the original version which seems to require Docker
|
||||
# https://github.com/koalaman/shellcheck-precommit
|
||||
- repo: https://github.com/shellcheck-py/shellcheck-py
|
||||
rev: v0.8.0.1
|
||||
hooks:
|
||||
- id: shellcheck
|
||||
name: shellcheck
|
||||
args: ["--severity=warning"]
|
||||
|
||||
- repo: https://github.com/sirosen/check-jsonschema
|
||||
rev: 0.10.2
|
||||
hooks:
|
||||
- id: check-jsonschema
|
||||
name: "Check GitHub Workflows"
|
||||
files: ^\.github/workflows/
|
||||
types: [yaml]
|
||||
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
|
||||
@ -40,6 +40,23 @@ port 27017:
|
||||
|
||||
.. _tox: https://testrun.org/tox/
|
||||
|
||||
Running Linters
|
||||
---------------
|
||||
|
||||
Motor uses `pre-commit <https://pypi.org/project/pre-commit/>`_
|
||||
for managing linting of the codebase.
|
||||
``pre-commit`` performs various checks on all files in Motor and uses tools
|
||||
that help follow a consistent code style within the codebase.
|
||||
|
||||
To set up ``pre-commit`` locally, run::
|
||||
|
||||
pip install pre-commit
|
||||
pre-commit install
|
||||
|
||||
To run ``pre-commit`` manually, run::
|
||||
|
||||
> tox -e lint
|
||||
|
||||
General Guidelines
|
||||
------------------
|
||||
|
||||
|
||||
1
LICENSE
1
LICENSE
@ -199,4 +199,3 @@
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
17
MANIFEST.in
17
MANIFEST.in
@ -1,8 +1,25 @@
|
||||
include README.rst
|
||||
include LICENSE
|
||||
include tox.ini
|
||||
include doc/Makefile
|
||||
include doc/examples/tornado_change_stream_templates/index.html
|
||||
recursive-include doc *.rst
|
||||
recursive-include doc *.py
|
||||
recursive-include doc *.png
|
||||
recursive-include test *.py
|
||||
recursive-include test *.pem
|
||||
recursive-include doc *.conf
|
||||
recursive-include doc *.css
|
||||
recursive-include doc *.js
|
||||
recursive-include doc *.txt
|
||||
recursive-include doc *.bat
|
||||
recursive-include synchro *.py
|
||||
|
||||
exclude .readthedocs.yaml
|
||||
exclude .git-blame-ignore-revs
|
||||
exclude .pre-commit-config.yaml
|
||||
exclude release.sh
|
||||
exclude ez_setup.py
|
||||
exclude RELEASE.rst
|
||||
exclude CONTRIBUTING.rst
|
||||
exclude .evergreen/*
|
||||
|
||||
@ -1 +0,0 @@
|
||||
|
||||
@ -17,4 +17,3 @@ Motor asyncio API
|
||||
|
||||
This page describes using Motor with asyncio. For Tornado integration, see
|
||||
:doc:`../api-tornado/index`.
|
||||
|
||||
|
||||
@ -457,4 +457,3 @@ Learning to use the MongoDB driver is just the beginning, of course. For
|
||||
in-depth instruction in MongoDB itself, see `The MongoDB Manual`_.
|
||||
|
||||
.. _The MongoDB Manual: http://docs.mongodb.org/manual/
|
||||
|
||||
|
||||
@ -19,9 +19,9 @@ import socket
|
||||
import sys
|
||||
import warnings
|
||||
from functools import wraps
|
||||
from unittest import SkipTest
|
||||
from test.utils import create_user
|
||||
from test.version import Version
|
||||
from unittest import SkipTest
|
||||
|
||||
import pymongo.errors
|
||||
|
||||
|
||||
28
tox.ini
28
tox.ini
@ -12,7 +12,7 @@ envlist =
|
||||
tornado6-{pypy35,pypy36,py35,py36,py37,py38,py39,py310},
|
||||
|
||||
# Test Tornado's dev version in a few configurations.
|
||||
tornado_git-{py36,py37},
|
||||
tornado_git-{py37,py38},
|
||||
|
||||
# Ensure the sphinx build has no errors or warnings.
|
||||
py3-sphinx-docs,
|
||||
@ -29,6 +29,12 @@ envlist =
|
||||
# Apply PyMongo's test suite to Motor via Synchro.
|
||||
synchro37
|
||||
|
||||
# Run pre-commit on all files.
|
||||
lint
|
||||
|
||||
# Check the sdist integrity.
|
||||
manifest
|
||||
|
||||
[testenv]
|
||||
passenv =
|
||||
DB_IP
|
||||
@ -49,7 +55,7 @@ basepython =
|
||||
pypy36: {env:PYTHON_BINARY:pypy3}
|
||||
|
||||
# Default Python 3 when we don't care about minor version.
|
||||
py3: {env:PYTHON_BINARY:python3.7}
|
||||
py3,lint,manifest: {env:PYTHON_BINARY:python3}
|
||||
|
||||
deps =
|
||||
tornado5: tornado>=5,<6
|
||||
@ -100,3 +106,21 @@ setenv =
|
||||
commands =
|
||||
git clone --depth 1 --branch master https://github.com/mongodb/mongo-python-driver.git {envtmpdir}/mongo-python-driver
|
||||
python3 -m synchro.synchrotest --with-xunit --xunit-file=xunit-synchro-results -v -w {envtmpdir}/mongo-python-driver {posargs}
|
||||
|
||||
[testenv:lint]
|
||||
deps =
|
||||
pre-commit
|
||||
commands =
|
||||
pre-commit run --all-files
|
||||
|
||||
[testenv:manifest]
|
||||
deps =
|
||||
check-manifest
|
||||
commands =
|
||||
check-manifest -v
|
||||
|
||||
[gh-actions]
|
||||
# Map GitHub Actions python-version to environment using tox-github-actions.
|
||||
python =
|
||||
3.6: py36
|
||||
3.10: py310,manifest
|
||||
|
||||
Loading…
Reference in New Issue
Block a user