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

ci,build: Add flake8, black, isort (and wire into CI) #42

Merged
merged 12 commits into from
Sep 4, 2022
7 changes: 5 additions & 2 deletions .github/workflows/pypi-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ jobs:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
cache: 'pip'
cache-dependency-path: 'pyproject.toml'

- name: Install latest pip, build, twine
run: |
Expand All @@ -26,4 +29,4 @@ jobs:
env:
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
twine upload --verbose -u '__token__' dist/*
twine upload --verbose -u '__token__' dist/*
14 changes: 13 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,27 @@ jobs:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: 'pyproject.toml'

- name: Install dependencies
run: |
python -m pip install -e .[lint]
python -m pip install --upgrade pip
python -m pip install --upgrade tox

- name: Lint (flake8)
run: flake8

- name: Lint (black)
run: black --check .

- name: Lint (isort)
run: isort --check .

- name: Unit tests
run: |
tox -e ci-py -- -v --color=yes
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,22 @@ dependencies = [
"pytest >=7.0.0",
]

[project.optional-dependencies]
lint = [
"isort >= 5",
"flake8",
"black"
]

[project.urls]
homepage = "https://github.com/thisch/pytest-sphinx"

[project.entry-points."pytest11"]
"sphinx" = "pytest_sphinx"

[tool.isort]
profile = "black"

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
4 changes: 1 addition & 3 deletions pytest_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ def _split_into_body_and_options(section_content):
option[0] not in "+-"
or option[1:] not in doctest.OPTIONFLAGS_BY_NAME
):
raise ValueError(
f"doctest has an invalid option {option}"
)
raise ValueError(f"doctest has an invalid option {option}")
flag = doctest.OPTIONFLAGS_BY_NAME[option[1:]]
flag_settings[flag] = option[0] == "+"
i += 1
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
exclude = .*/,.tox,*.egg
max-line-length = 88
extend-ignore = E203
10 changes: 4 additions & 6 deletions tests/test_text_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ def add_sys(doctest_namespace):

def test_doctest_directive(testdir):
testdir.maketxtfile(
test_something="""
test_something=r"""
This is a paragraph. This is the
next sentence.

.. doctest::

>>> assert False
Expand All @@ -220,12 +220,11 @@ def test_doctest_directive(testdir):
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*=== 1 passed in *"])


testdir.maketxtfile(
test_something="""
test_something=r"""
This is a paragraph. This is the
next sentence.

.. doctest::

>>> assert False
Expand All @@ -234,4 +233,3 @@ def test_doctest_directive(testdir):

result = testdir.runpytest()
result.stdout.fnmatch_lines(["*=== 1 failed in *"])