Skip to content

Commit

Permalink
chore: update template
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau committed Feb 5, 2024
1 parent 63ee776 commit ff281c9
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Changes here will be overwritten by Copier
_commit: 0.1.5
_commit: 0.1.11
_src_path: gh:12rambau/pypackage
author_email: [email protected]
author_first_name: Pierrick
author_last_name: Rambaud
author_orcid: 0000-0001-8764-5749
creation_year: "2023"
github_repo_name: pytest-copie
github_user: 12rambau
project_name: pytest-copie
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"ghcr.io/devcontainers-contrib/features/nox:2": {},
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {}
},
"postCreateCommand": "pre-commit install"
"postCreateCommand": "python -m pip install commitizen && pre-commit install"
}
9 changes: 5 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ on:
types: [created]

jobs:
tests:
uses: ./.github/workflows/unit.yaml

deploy:
needs: [tests]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand All @@ -19,6 +22,4 @@ jobs:
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python -m build
twine upload dist/*
run: python -m build && twine upload dist/*
25 changes: 15 additions & 10 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Unit tests

on:
workflow_call:
push:
branches:
- main
Expand Down Expand Up @@ -63,24 +64,28 @@ jobs:
- name: Install nox
run: pip install nox
- name: test with pytest
run: nox -s test
run: nox -s ci-test
- name: assess dead fixtures
if: ${{ matrix.python-version == '3.10' }}
shell: bash
run: nox -s dead-fixtures
- uses: actions/upload-artifact@v4
if: ${{ matrix.python-version == '3.10' }}
with:
name: coverage
path: coverage.xml

coverage:
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/download-artifact@v4
with:
python-version: "3.10"
- name: Install deps
run: pip install nox
- name: test with pytest
run: nox -s test
- name: assess dead fixtures
run: nox -s dead-fixtures
name: coverage
path: coverage.xml
- name: codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,7 @@ dmypy.json
.vscode/

# image tmp file
*Zone.Identifier
*Zone.Identifier

# debugging notebooks
test.ipynb
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ The ``copie`` fixture will allow you to ``copy`` a template and run tests agains
assert result.project_dir.is_dir()
Context and template location can be fully customized, see our `documentation <https://pytest-copie.readthedocs.io>`__ for more details.

Credits
-------

This package was created with `Copier <https://copier.readthedocs.io/en/latest/>`__ and the `@12rambau/pypackage <https://github.com/12rambau/pypackage>`__ 0.1.11 project template.
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# disable the treemap comment and report in PRs
comment: false
8 changes: 2 additions & 6 deletions demo_template/tests/test_custom_template_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def custom_template(tmp_path) -> Path:
(template / "copier.yaml").write_text(yaml.dump(questions))
# Create custom subdirectory
(repo_dir := template / "custom_template").mkdir()
(template / "copier.yaml").write_text(
yaml.dump({"_subdirectory": "custom_template"})
)
(template / "copier.yaml").write_text(yaml.dump({"_subdirectory": "custom_template"}))
# Create custom template text files
(repo_dir / "README.rst.jinja").write_text("{{custom_name}}\n")

Expand All @@ -25,9 +23,7 @@ def custom_template(tmp_path) -> Path:

def test_copie_custom_project(copie, custom_template):
"""Test custom copier template fixture using pytest-copie."""
result = copie.copy(
template_dir=custom_template, extra_answers={"custom_name": "tutu"}
)
result = copie.copy(template_dir=custom_template, extra_answers={"custom_name": "tutu"})

assert result.project_dir.is_dir()
with open(result.project_dir / "README.rst") as f:
Expand Down
4 changes: 1 addition & 3 deletions demo_template/tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def test_template_with_extra_answers(copie):
# can delete the template_dir keyword argument here.
demo_template_dir = Path(__file__).parent.parent

result = copie.copy(
extra_answers={"name": "helloworld"}, template_dir=demo_template_dir
)
result = copie.copy(extra_answers={"name": "helloworld"}, template_dir=demo_template_dir)

assert result.exit_code == 0
assert result.exception is None
Expand Down
6 changes: 3 additions & 3 deletions docs/_template/pypackage-credit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p class="pypackage-credit">
From a
<a href="https://github.com/12rambau/pypackage">12rambau/pypackage</a>
Cookiecutter project.
From
<a href="https://github.com/12rambau/pypackage">@12rambau/pypackage</a>
0.1.11 Copier project.
</p>
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# -- Project information -------------------------------------------------------
project = "pytest-copie"
author = "Pierrick Rambaud"
copyright = f"2020-{datetime.now().year}, {author}"
copyright = f"2023-{datetime.now().year}, {author}"
release = "0.1.6"

# -- General configuration -----------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ def lint(session):

@nox.session(reuse_venv=True)
def test(session):
"""Run all the test using the environment variable of the running machine."""
"""Run the selected tests and report coverage in html."""
session.install(".[test]")
test_files = session.posargs or ["tests", "demo_template"]
session.run("coverage", "run", "-m", "pytest", "--color=yes", *test_files)
session.run("coverage", "html")


@nox.session(reuse_venv=True, name="ci-test")
def ci_test(session):
"""Run all the test and report coverage in xml."""
session.install(".[test]")
session.run("coverage", "run", "-m", "pytest", "--color=yes", "tests", "demo_template")
session.run("coverage", "xml")


Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ version_files = [
[tool.pytest.ini_options]
testpaths = ["tests", "demo_template"]

[tool.black]
line-length = 100

[tool.ruff]
ignore-init-module-imports = true
fix = true
Expand Down
4 changes: 1 addition & 3 deletions pytest_copie/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class Copie:
counter: int = 0
"A counter to keep track of the number of projects created."

def copy(
self, extra_answers: dict = {}, template_dir: Optional[Path] = None
) -> Result:
def copy(self, extra_answers: dict = {}, template_dir: Optional[Path] = None) -> Result:
"""Create a copier Project from the template and return the associated :py:class:`Result <pytest_copie.plugin.Result>` object.
Args:
Expand Down
8 changes: 2 additions & 6 deletions stubs/pytest_copie/plugin.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ class Copie:
test_dir: Path
config_file: Path
counter: int = ...
def copy(
self, extra_answers: dict = ..., template_dir: Optional[Path] = ...
) -> Result: ...
def __init__(
self, default_template_dir, test_dir, config_file, counter
) -> None: ...
def copy(self, extra_answers: dict = ..., template_dir: Optional[Path] = ...) -> Result: ...
def __init__(self, default_template_dir, test_dir, config_file, counter) -> None: ...

def _copier_config_file(tmp_path_factory) -> Path: ...
def copie(request, tmp_path: Path, _copier_config_file: Path) -> Generator: ...
Expand Down
8 changes: 2 additions & 6 deletions tests/test_copie.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def test_copie_project(copie):
assert result.ret == 0


def test_copie_copy_without_subdirectory(
testdir, incomplete_copier_template, test_check
):
def test_copie_copy_without_subdirectory(testdir, incomplete_copier_template, test_check):
"""Programmatically create a **Copier** template and use `copy` to create a project from it."""
testdir.makepyfile(
"""
Expand Down Expand Up @@ -146,9 +144,7 @@ def test_previous_dir_is_kept(copie):
"""
)

result = testdir.runpytest(
"-v", f"--template={copier_template}", "--keep-copied-projects"
)
result = testdir.runpytest("-v", f"--template={copier_template}", "--keep-copied-projects")
test_check(result, "test_create_dir")
test_check(result, "test_previous_dir_is_kept")
assert result.ret == 0
Expand Down

0 comments on commit ff281c9

Please sign in to comment.