Skip to content

Commit

Permalink
Remove docs tox env if sphinx not selected
Browse files Browse the repository at this point in the history
Also add a test for this
Fixes #57
  • Loading branch information
coretl committed Feb 9, 2024
1 parent 5ef6aca commit 6abb935
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
5 changes: 3 additions & 2 deletions template/README.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ how it does it, and why people should use it.
Source | <{{repo_url}}>
:---: | :---:
PyPI | `pip install {{pypi_name}}`
Documentation | <{{docs_url}}>
{% if sphinx %}Documentation | <{{docs_url}}>{% endif %}
Releases | <{{repo_url}}/releases>

This is where you should put some images or code snippets that illustrate
Expand All @@ -29,7 +29,8 @@ Or if it is a commandline tool then you might put some example commands here:
```
python -m {{package_name}} --version
```

{% if sphinx %}
<!-- README only content. Anything below this line won't be included in index.md -->

See {{docs_url}} for more detailed documentation.
{% endif %}
12 changes: 6 additions & 6 deletions template/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ reportMissingImports = false # Ignore missing stubs in imported modules
[tool.pytest.ini_options]
# Run pytest with all our checkers, and don't spam us with massive tracebacks on error
addopts = """
--tb=native -vv --doctest-modules --doctest-glob="*.rst"
--tb=native -vv{% if sphinx %} --doctest-modules --doctest-glob="*.rst"{% endif %}
"""
# https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings
filterwarnings = "error"
Expand All @@ -82,22 +82,22 @@ legacy_tox_ini = """
[tox]
skipsdist=True

[testenv:{pre-commit,pyright,pytest,docs}]
[testenv:{pre-commit,pyright,pytest{% if sphinx %},docs{% endif %}}]
# Don't create a virtualenv for the command, requires tox-direct plugin
direct = True
passenv = *
allowlist_externals =
pytest
pre-commit
pyright
sphinx-build
{% if sphinx %} sphinx-build
sphinx-autobuild
commands =
{% endif %}commands =
pytest: pytest --cov={{ package_name }} --cov-report term --cov-report xml:cov.xml {posargs}
pyright: pyright src tests {posargs}
pre-commit: pre-commit run --all-files {posargs}
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
"""
{% if sphinx %} docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
{% endif %}"""

[tool.ruff]
src = ["src", "tests"]
Expand Down
31 changes: 21 additions & 10 deletions tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,28 @@ def run_pipe(cmd: str, cwd=None):
return output


def test_template(tmp_path: Path):
project_path = tmp_path / "project"
venv_path = tmp_path / "venv"
copy_project(project_path)
def make_venv(project_path: Path) -> callable:
venv_path = project_path / "venv"
run_pipe(f"python -m venv {venv_path}")
run = functools.partial(run_pipe, cwd=str(project_path))
run(f"python -m venv {venv_path}")
run(f"{venv_path}/bin/python -m pip install -e .[dev]")
run(f"{venv_path}/bin/tox -p")
run(f"{venv_path}/bin/python -m pip install build twine")
run(f"{venv_path}/bin/python -m build")
run(f"{venv_path}/bin/python -m twine check --strict dist/*")
run(f"./venv/bin/pip install -e .[dev]")
return run


def test_template(tmp_path: Path):
copy_project(tmp_path)
run = make_venv(tmp_path)
run(f"./venv/bin/tox -p")
run(f"./venv/bin/pip install build twine")
run(f"./venv/bin/python -m build")
run(f"./venv/bin/twine check --strict dist/*")


def test_template_no_docs(tmp_path: Path):
copy_project(tmp_path, docs_type="README")
run = make_venv(tmp_path)
run(f"./venv/bin/tox -p")



def test_bad_repo_name(tmp_path: Path):
Expand Down

0 comments on commit 6abb935

Please sign in to comment.