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

Moved template to subdirectory #91

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ repos:
rev: "22.8.0"
hooks:
- id: black
exclude: ^{{cookiecutter.project_name}}
exclude: ^templates/cookiecutter-poetry/{{cookiecutter.project_name}}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Github repository to the `cookiecutter` command:

``` bash
pip install cookiecutter
cookiecutter https://github.com/fpgmaas/cookiecutter-poetry.git
cookiecutter https://github.com/fpgmaas/cookiecutter-poetry.git \
--directory templates/cookiecutter-poetry
```

Create a repository on GitHub, and then run the following commands, replacing `<project-name>`, with the name that you gave the Github repository and
Expand Down
4 changes: 3 additions & 1 deletion cookiecutter_poetry/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
from pathlib import Path


def main() -> None:
cwd = os.path.dirname(__file__)
package_dir = os.path.abspath(os.path.join(cwd, ".."))
os.system(f"cookiecutter {package_dir}")
template_dir = Path(package_dir) / "templates" / "cookiecutter-poetry"
os.system(f"cookiecutter {str(template_dir)}")
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ packages = [
{include = "cookiecutter_poetry"}
]
include = [
'{{cookiecutter.project_name}}/**/*',
'cookiecutter.json',
'hooks/*'
'templates/cookiecutter-poetry/**/*',
'templates/cookiecutter-poetry/cookiecutter.json',
'templates/cookiecutter-poetry/hooks/*'
]

[tool.poetry.dependencies]
Expand Down Expand Up @@ -65,7 +65,7 @@ show_error_codes = "True"

[tool.deptry]
extend_exclude = [
"{{cookiecutter.project_name}}"
"templates/cookiecutter-poetry/{{cookiecutter.project_name}}"
]

[tool.deptry.per_rule_ignores]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 16 additions & 14 deletions tests/test_cookiecutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import subprocess
from contextlib import contextmanager

TEMPLATE_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "templates", "cookiecutter-poetry"))


@contextmanager
def run_within_dir(path: str):
Expand All @@ -20,7 +22,7 @@ def file_contains_text(file: str, text: str) -> bool:


def test_bake_project(cookies):
result = cookies.bake(extra_context={"project_name": "my-project"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"project_name": "my-project"})

assert result.exit_code == 0
assert result.exception is None
Expand All @@ -30,7 +32,7 @@ def test_bake_project(cookies):

def test_using_pytest(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake()
result = cookies.bake(template=TEMPLATE_PATH)

# Assert that project was created.
assert result.exit_code == 0
Expand All @@ -46,7 +48,7 @@ def test_using_pytest(cookies, tmp_path):

def test_cicd_contains_artifactory_secrets(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake(extra_context={"publish_to": "artifactory"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"publish_to": "artifactory"})
assert result.exit_code == 0
for text in ["ARTIFACTORY_URL", "ARTIFACTORY_USERNAME", "ARTIFACTORY_PASSWORD"]:
assert file_contains_text(f"{result.project_path}/.github/workflows/on-release-main.yml", text)
Expand All @@ -55,15 +57,15 @@ def test_cicd_contains_artifactory_secrets(cookies, tmp_path):

def test_cicd_contains_pypi_secrets(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake(extra_context={"publish_to": "pypi"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"publish_to": "pypi"})
assert result.exit_code == 0
assert file_contains_text(f"{result.project_path}/.github/workflows/on-release-main.yml", "PYPI_TOKEN")
assert file_contains_text(f"{result.project_path}/Makefile", "build-and-publish")


def test_dont_publish(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake(extra_context={"publish_to": "none"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"publish_to": "none"})
assert result.exit_code == 0
assert not file_contains_text(
f"{result.project_path}/.github/workflows/on-release-main.yml", "make build-and-publish"
Expand All @@ -72,7 +74,7 @@ def test_dont_publish(cookies, tmp_path):

def test_mkdocs(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake(extra_context={"mkdocs": "y"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"mkdocs": "y"})
assert result.exit_code == 0
assert file_contains_text(f"{result.project_path}/.github/workflows/on-release-main.yml", "mkdocs gh-deploy")
assert file_contains_text(f"{result.project_path}/Makefile", "docs:")
Expand All @@ -81,7 +83,7 @@ def test_mkdocs(cookies, tmp_path):

def test_not_mkdocs(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake(extra_context={"mkdocs": "n"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"mkdocs": "n"})
assert result.exit_code == 0
assert not file_contains_text(
f"{result.project_path}/.github/workflows/on-release-main.yml", "mkdocs gh-deploy"
Expand All @@ -92,7 +94,7 @@ def test_not_mkdocs(cookies, tmp_path):

def test_tox(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake()
result = cookies.bake(template=TEMPLATE_PATH)
assert result.exit_code == 0
assert file_contains_text(f"{result.project_path}/.github/workflows/main.yml", "pip install tox tox-gh-actions")
assert os.path.isfile(f"{result.project_path}/tox.ini")
Expand All @@ -101,40 +103,40 @@ def test_tox(cookies, tmp_path):

def test_dockerfile(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake(extra_context={"dockerfile": "y"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"dockerfile": "y"})
assert result.exit_code == 0
assert os.path.isfile(f"{result.project_path}/Dockerfile")


def test_not_dockerfile(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake(extra_context={"dockerfile": "n"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"dockerfile": "n"})
assert result.exit_code == 0
assert not os.path.isfile(f"{result.project_path}/Dockerfile")


def test_codecov(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake()
result = cookies.bake(template=TEMPLATE_PATH)
assert result.exit_code == 0
assert os.path.isfile(f"{result.project_path}/codecov.yaml")
assert os.path.isfile(f"{result.project_path}/.github/workflows/validate-codecov-config.yml")


def test_not_codecov(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake(extra_context={"codecov": "n"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"codecov": "n"})
assert result.exit_code == 0
assert not os.path.isfile(f"{result.project_path}/codecov.yaml")
assert not os.path.isfile(f"{result.project_path}/.github/workflows/validate-codecov-config.yml")


def test_remove_release_workflow(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake(extra_context={"publish_to": "none", "mkdocs": "y"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"publish_to": "none", "mkdocs": "y"})
assert result.exit_code == 0
assert os.path.isfile(f"{result.project_path}/.github/workflows/on-release-main.yml")

result = cookies.bake(extra_context={"publish_to": "none", "mkdocs": "n"})
result = cookies.bake(template=TEMPLATE_PATH, extra_context={"publish_to": "none", "mkdocs": "n"})
assert result.exit_code == 0
assert not os.path.isfile(f"{result.project_path}/.github/workflows/on-release-main.yml")