Skip to content

Commit

Permalink
Merge 468025b into bc6a57b
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Nov 7, 2021
2 parents bc6a57b + 468025b commit c3a9f0f
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python.yaml
Expand Up @@ -11,7 +11,7 @@ jobs:
build:
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
# ubuntu-latest is being moved from ubuntu-18.04 to ubuntu-20.04
# See https://github.com/actions/virtual-environments/issues/1816
os: [ubuntu-latest, macos-latest, windows-latest]
Expand Down
12 changes: 12 additions & 0 deletions docs/examples.rst
Expand Up @@ -411,6 +411,18 @@ Contents of `styles/pylint.toml <https://github.com/andreoliwa/nitpick/blob/v0.2
# A regular expression matching the name of dummy variables (i.e. expectedly not used).
dummy-variables-rgx = "_$|dummy"
.. _example-python-3-10:

Python 3.10
-----------

Contents of `styles/python310.toml <https://github.com/andreoliwa/nitpick/blob/v0.28.0/styles/python310.toml>`_:

.. code-block:: toml
["pyproject.toml".tool.poetry.dependencies]
python = "^3.10"
.. _example-python-3-6:

Python 3.6
Expand Down
1 change: 1 addition & 0 deletions docs/generate_rst.py
Expand Up @@ -65,6 +65,7 @@
"python37.toml": "Python 3.7",
"python38.toml": "Python 3.8",
"python39.toml": "Python 3.9",
"python310.toml": "Python 3.10",
"tox.toml": "tox_",
}
)
Expand Down
4 changes: 2 additions & 2 deletions docs/ideas/yaml/contains.toml
Expand Up @@ -3,7 +3,7 @@
[[".github/workflows/python.yaml".contains]]
__jmespath = "jobs.build.strategy.matrix"
os = ["ubuntu-latest", "macos-latest", "windows-latest"]
"python-version" = ["3.6", "3.7", "3.8", "3.9"]
"python-version" = ["3.6", "3.7", "3.8", "3.9", "3.10"]

# 3. Same as item 4 on "jmespath-on-section.toml", but with a different syntax.
[[".github/workflows/python.yaml".contains]]
Expand Down Expand Up @@ -56,7 +56,7 @@ __yaml = "- uses: actions/checkout@v2"
[[".github/workflows/python.yaml".contains_sorted]]
__jmespath = "jobs.build.strategy.matrix"
os = ["ubuntu-latest", "macos-latest", "windows-latest"]
"python-version" = ["3.6", "3.7", "3.8", "3.9"]
"python-version" = ["3.6", "3.7", "3.8", "3.9", "3.10"]

[[".github/workflows/python.yaml".contains_sorted]]
__jmespath = "jobs.build"
Expand Down
2 changes: 1 addition & 1 deletion docs/ideas/yaml/jmespath-on-section.toml
Expand Up @@ -8,7 +8,7 @@
# 3. Both are lists, and they have to be exactly as described here.
[".github/workflows/python.yaml".jobs.build.strategy.matrix]
os = ["ubuntu-latest", "macos-latest", "windows-latest"]
"python-version" = ["3.6", "3.7", "3.8", "3.9"]
"python-version" = ["3.6", "3.7", "3.8", "3.9", "3.10"]

# 4. "jobs.build" should have "runs-on" with value "${{ matrix.os }}"
[".github/workflows/python.yaml".jobs.build]
Expand Down
2 changes: 1 addition & 1 deletion docs/ideas/yaml/merge_lists/merged_style.toml
@@ -1,4 +1,4 @@
# This should be the result of a parent style including all the styles in this directory
[".github/workflows/python.yaml".jobs.build.strategy.matrix]
os = ["ubuntu-latest", "macos-latest", "windows-latest"]
"python-version" = ["3.6", "3.7", "3.8", "3.9"]
"python-version" = ["3.6", "3.7", "3.8", "3.9", "3.10"]
2 changes: 2 additions & 0 deletions docs/ideas/yaml/merge_lists/py310.toml
@@ -0,0 +1,2 @@
[".github/workflows/python.yaml".jobs.build.strategy.matrix]
"python-version" = ["3.10"]
2 changes: 1 addition & 1 deletion src/nitpick/style/fetchers/pypackage.py
Expand Up @@ -58,4 +58,4 @@ class PythonPackageFetcher(StyleFetcher): # pylint: disable=too-few-public-meth

def _do_fetch(self, url):
package_url = PythonPackageURL.parse_url(url)
return package_url.raw_content_url.read_text()
return package_url.raw_content_url.read_text(encoding="UTF-8")
2 changes: 2 additions & 0 deletions styles/python310.toml
@@ -0,0 +1,2 @@
["pyproject.toml".tool.poetry.dependencies]
python = "^3.10"
33 changes: 27 additions & 6 deletions tasks.py
Expand Up @@ -80,6 +80,22 @@ def macos(ctx, enable: bool):
else:
ctx.run("sed -i '' 's/platform = darwin/platform = linux/g' tox.ini")

def _python_versions(self):
"""Lines with Python versions executed in tox."""
return self._parser["gh-actions"]["python"].strip().splitlines()

@property
def minimum_python_version(self):
"""Minimum Python version."""
last = self._python_versions()[-1]
return last.split(":")[0]

@property
def stable_python_version(self):
"""Stable Python version."""
stable = [line for line in self._python_versions() if "lint" in line]
return stable[0].split(":")[1].split(",")[0].strip()


@task(help={"deps": "Poetry dependencies", "hooks": "pre-commit hooks"})
def install(ctx, deps=True, hooks=False):
Expand All @@ -88,12 +104,15 @@ def install(ctx, deps=True, hooks=False):
Poetry install is needed to create the Nitpick plugin entries on setuptools, used by pluggy.
"""
if deps:
print(f"{COLOR_GREEN}Nitpick runs in Python 3.6 and later, but development is done in 3.6{COLOR_NONE}")
ctx.run("poetry env use python3.6")
version = ToxCommands().minimum_python_version
print(
f"{COLOR_GREEN}Nitpick runs in Python {version} and later"
f", but development is done in {version}{COLOR_NONE}"
)
ctx.run(f"poetry env use python{version}")
ctx.run("poetry install -E test -E lint -E doc --remove-untracked")
if hooks:
ctx.run("pre-commit install --install-hooks")
ctx.run("pre-commit install --hook-type commit-msg")
ctx.run("pre-commit install -t pre-commit -t commit-msg --install-hooks")
ctx.run("pre-commit gc")


Expand Down Expand Up @@ -189,7 +208,8 @@ def ci_build(ctx, full=False, recreate=False):
ctx.run(f"rm -rf {DOCS_BUILD_PATH} docs/source")
ctx.run(tox_cmd)
else:
ctx.run(f"{tox_cmd} -e clean,lint,py38,docs,report")
version = ToxCommands().stable_python_version
ctx.run(f"{tox_cmd} -e clean,lint,{version},docs,report")

tox.macos(ctx, False)

Expand Down Expand Up @@ -219,7 +239,8 @@ def clean(ctx, venv=False):
ctx.run(f"rm -rf .cache .mypy_cache {DOCS_BUILD_PATH} src/*.egg-info .pytest_cache .coverage htmlcov .testmondata")
if venv:
ctx.run("rm -rf .tox")
ctx.run("poetry env remove python3.6", warn=True)
version = ToxCommands().minimum_python_version
ctx.run(f"poetry env remove python{version}", warn=True)


@task
Expand Down
20 changes: 11 additions & 9 deletions tox.ini
@@ -1,22 +1,24 @@
[tox]
# https://tox.readthedocs.io/en/latest/config.html
isolated_build = True
envlist = clean,lint,py39,py38,py37,py36,docs,report
envlist = clean,lint,py310,py39,py38,py37,py36,docs,report

[gh-actions]
# https://github.com/ymyzk/tox-gh-actions
# Linting and docs run in the "stable" version of Python, avoiding bleeding edge or very recent versions
python =
3.9: py39
3.8: py38, clean, lint, docs, report
3.10: py310
3.9: py39, clean, lint, docs, report
3.8: py38
3.7: py37
3.6: py36

[testenv]
description = Run tests with pytest and coverage
extras = test
depends =
{py39,py38,py37,py36}: clean
report: py39,py38,py37,py36
{py310,py39,py38,py37,py36}: clean
report: py310,py39,py38,py37,py36
setenv =
PY_IGNORE_IMPORTMISMATCH = 1
commands =
Expand All @@ -35,7 +37,7 @@ commands = coverage erase

[testenv:lint]
description = Lint all files with pre-commit
basepython = python3.8
basepython = python3.9
platform = linux
# pylint needs both these extras:
extras =
Expand Down Expand Up @@ -64,15 +66,15 @@ commands =

[testenv:docs]
description = Build the HTML docs using Sphinx (sphinx-build, API docs, link checks)
basepython = python3.8
basepython = python3.9
platform = linux
extras = doc
# https://tox.readthedocs.io/en/latest/config.html#conf-allowlist_externals
allowlist_externals =
git
printf
commands =
# TODO: Make this step optional; it generates a different output on GitHub Actions (Ubuntu Python3.8)
# TODO: Make this step optional; it generates a different output on GitHub Actions (Ubuntu)
- python3 docs/generate_rst.py
sphinx-apidoc --force --follow-links --module-first --separate --implicit-namespaces --ext-autodoc --ext-doctest --ext-intersphinx --ext-todo --ext-coverage --ext-imgmath --ext-mathjax --ext-ifconfig --ext-viewcode --ext-githubpages --output-dir docs/source src/nitpick/

Expand All @@ -83,7 +85,7 @@ commands =
git add .
git status
printf "\n\033[1;31mIf tox failed at this point, it means that files were created (see above) and documentation is missing.\n\033[1;31mRun \033[32minvoke doc\033[1;31m in your development machine and commit the generated .rst files.\033[0m\n"
# TODO: Make this step optional; it generates a different output on GitHub Actions (Ubuntu Python3.8)
# TODO: Make this step optional; it generates a different output on GitHub Actions (Ubuntu)
- git diff-index --quiet HEAD --

# Run link checks after building the docs
Expand Down

0 comments on commit c3a9f0f

Please sign in to comment.