Skip to content

Commit

Permalink
fix: remove --require-hashes mode
Browse files Browse the repository at this point in the history
Due to issues with pytype not pinning dependency versions, I'm removing
the explicit version checking semantics.

See also:
* google/pytype#731
* cjolowicz/hypermodern-python#174
  • Loading branch information
ToddG committed Nov 16, 2020
1 parent 934da90 commit 150e493
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# hypermodern-python-seed

Generate python seed apps based on [hypermodern-python][1].
Generate python seed apps based on `cjolowicz's` [hypermodern-python][1]. Note
that `cjolowicz` has also created a [seed][3] repo. I prefer this one b/c I only
pulled in the ideas that are relevant to the projects I build, today.

## Dependencies

* [cookiecutter](https://github.com/cookiecutter/cookiecutter)

See [hypermodern-python][1] for installation instructions for these:
See [hypermodern-python][1] for further installation instructions. You'll need
these:

* poetry
* pyenv
Expand All @@ -20,6 +23,11 @@ See [hypermodern-python][1] for installation instructions for these:

nox

## Notes

* Not using --require-hashes mode due to [pytype issue 731][2]

# Links
[1]: https://cjolowicz.github.io/posts/hypermodern-python-01-setup/
[2]: https://github.com/google/pytype/issues/731
[3]: https://github.com/cjolowicz/cookiecutter-hypermodern-python
44 changes: 13 additions & 31 deletions {{cookiecutter.directory_name}}/noxfile.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
"""project_name Nox sessions."""

import tempfile
from typing import Any
"""{{cookiecutter.project_name}} Nox sessions."""

import nox
from nox.sessions import Session

locations = "src", "tests", "noxfile.py", "docs/conf.py"
nox.options.sessions = "lint", "mypy", "pytype", "tests"
_versions = ["3.7"]


def install_with_constraints(session: Session, *args: str, **kwargs: Any) -> None:
"""Install application dependencies using constraints."""
with tempfile.NamedTemporaryFile() as requirements:
session.run(
"poetry",
"export",
"--dev",
"--format=requirements.txt",
f"--output={requirements.name}",
external=True,
)
session.install(f"--constraint={requirements.name}", *args, **kwargs)
_versions = ["3.7", "3.8"]


@nox.session(python=_versions)
def lint(session: Session) -> None:
"""Run the code linters."""
args = session.posargs or locations
install_with_constraints(
session,
session.install(
"darglint",
"flake8",
"flake8-annotations",
"flake8-black",
"flake8-isort",
"flake8-docstrings",
"darglint",
"flake8-isort",
"flake8-rst-docstrings",
"flake8_sphinx_links",
)
session.run("flake8", *args)

Expand All @@ -46,9 +30,7 @@ def tests(session: Session) -> None:
"""Run tests."""
args = session.posargs or ["--cov", "--xdoctest"]
session.run("poetry", "install", "--no-dev", external=True)
install_with_constraints(
session, "coverage[toml]", "pytest", "pytest-cov", "xdoctest"
)
session.install("coverage[toml]", "pytest", "pytest-cov", "xdoctest")
session.run("pytest", *args)


Expand All @@ -63,37 +45,37 @@ def format(session: Session) -> None:
def isort(session: Session) -> None:
"""Run the import re-orderer (isort)."""
args = session.posargs or locations
install_with_constraints(session, "flake8-isort")
session.install("flake8-isort")
session.run("isort", *args)


@nox.session(python=_versions)
def black(session: Session) -> None:
"""Run the code reformatter (black)."""
args = session.posargs or locations
install_with_constraints(session, "black")
session.install("black")
session.run("black", *args)


@nox.session(python=_versions)
def mypy(session: Session) -> None:
"""Run the static type checker (mypy))."""
args = session.posargs or locations
install_with_constraints(session, "mypy")
session.install("mypy")
session.run("mypy", *args)


@nox.session(python=_versions)
def pytype(session: Session) -> None:
"""Run the static type checker (pytype)."""
args = session.posargs or ["--disable=import-error", *locations]
install_with_constraints(session, "pytype")
session.install("pytype")
session.run("pytype", *args)


@nox.session(python=_versions)
def docs(session: Session) -> None:
"""Build the documentation."""
session.run("poetry", "install", "--no-dev", external=True)
install_with_constraints(session, "sphinx", "sphinx-autodoc-typehints")
session.install("sphinx", "sphinx-autodoc-typehints")
session.run("sphinx-build", "docs", "docs/_build")

0 comments on commit 150e493

Please sign in to comment.