Browse Source

[ADD] cruft & cookiecutter

master
Justin Lecher 3 months ago
parent
commit
f60d811ba5
  1. 16
      .cruft.json
  2. 1
      .gitignore
  3. 4
      .pre-commit-config.yaml
  4. 31
      Makefile
  5. 15
      README.md
  6. 12
      hooks/post_gen_project.py
  7. 14
      hooks/pre_gen_project.py
  8. 24
      tests/test_bake_project.py
  9. 1
      {{ cookiecutter.ansible_collection }}/.gitignore
  10. 8
      {{ cookiecutter.ansible_collection }}/galaxy.yml

16
.cruft.json

@ -0,0 +1,16 @@
{
"template": "git@git.ercpe.de:justin/cookiecutter-cookie.git",
"commit": "f0580cea84d52371582980b2bd3a46089009aadb",
"context": {
"cookiecutter": {
"full_name": "Justin Lecher",
"email": "justin@jlec.de",
"project_name": "Ansible Collection Cookiecutter",
"project_slug": "cookiecutter_ansible_collection",
"project_short_description": "Cookiecutter for Ansible collections",
"_template": "git@git.ercpe.de:justin/cookiecutter-cookie.git"
}
},
"directory": null,
"checkout": null
}

1
.gitignore

@ -25,5 +25,6 @@ pip-delete-this-directory.txt
packer_cache/
# CUSTOM
.cache
setup*done
tmp

4
.pre-commit-config.yaml

@ -24,3 +24,7 @@ repos:
hooks:
- id: black
args: ["--line-length", "128"]
- repo: https://github.com/jlec/pre-commit-cruft
rev: v0.1.1
hooks:
- id: cruft

31
Makefile

@ -54,19 +54,35 @@ publish:
git push -v --progress
git push -v --progress --tags
################################################################################
#
# Cookies options
#
################################################################################
.PHONY: cruft-update
cruft-update: setup-dev.done
git stash
$(PIPENV) cruft update --allow-untracked-files
git stash pop
################################################################################
#
# Checking and Linting
#
################################################################################
.PHONY: check lint linting pytest test
.PHONY: check cruft-check lint linting pytest test
check: lint test
check: cruft-check lint test
test: pytest
cruft-check: setup-dev.done
$(PIPENV) cruft check
$(PIPENV) cruft diff
test: cruft-check pytest
pytest: setup-dev.done
$(PIPENV) pytest ${PYTESTARGS} .
$(PIPENV) pytest ${PYTESTARGS} tests
pre-commit: setup-dev.done
$(PIPENV) pre-commit run --all-files
@ -79,12 +95,7 @@ linting: pre-commit
# Custom options
#
################################################################################
.PHONY: clean cruft-update
cruft-update: setup-dev.done
git stash
$(PIPENV) cruft update --allow-untracked-files
git stash pop
.PHONY: clean
clean:
rm -rvf tmp setup*done

15
README.md

@ -1,3 +1,14 @@
# cookiecutter-ansible-collection
# cookiecutter_ansible_collection
=========
Create your collection role from it
Cookiecutter for Ansible collections
License
-------
Apache-2.0
Author Information
------------------
* Justin Lecher <justin@jlec.de>

12
hooks/post_gen_project.py

@ -5,6 +5,11 @@ import shutil
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
PROJECT_FOLDERS = (
"docs",
"plugins",
"roles",
)
def create_folder(filepath):
@ -22,12 +27,7 @@ def remove_file_or_folder(filepath):
def gen_role_folders():
ansible_role_folders = (
"docs",
"plugins",
"roles",
)
for d in ansible_role_folders:
for d in PROJECT_FOLDERS:
create_folder(d)

14
hooks/pre_gen_project.py

@ -0,0 +1,14 @@
#!/usr/bin/env python3
import re
import sys
ROLE_REGEX = r"^[_a-zA-Z][_a-zA-Z0-9]+$"
ANSIBLE_COLLECTION = "{{ cookiecutter.ansible_collection }}"
if not re.match(ROLE_REGEX, ANSIBLE_COLLECTION):
print(f"ERROR: '{ANSIBLE_COLLECTION}' is not a valid Python module name!")
# exits with status 1 to indicate failure
sys.exit(1)

24
tests/test_bake_project.py

@ -10,14 +10,10 @@ from contextlib import contextmanager
from cookiecutter.utils import rmtree
ANSIBLE_COLLECTION_DIRS = (
"docs",
"plugins",
"roles",
)
ANSIBLE_COLLECTION_FILES = (
FILES = (
".bumpversion.cfg",
".gitignore",
".pre-commit-config.yaml",
".yamllint",
"galaxy.yml",
"LICENSE",
@ -26,6 +22,12 @@ ANSIBLE_COLLECTION_FILES = (
"README.md",
)
DIRS = (
"docs",
"plugins",
"roles",
)
@contextmanager
def inside_dir(dirpath):
@ -71,7 +73,7 @@ def check_output_inside_dir(command, dirpath):
return subprocess.check_output(shlex.split(command))
def check_project_content(result, files, dirs):
def check_project_content(result, files=(), dirs=()):
assert result.exit_code == 0
found_toplevel_files = [f.basename for f in result.project.listdir()]
@ -115,7 +117,11 @@ def test_make_help(cookies):
assert b"Make targets" in output
def test_bake_role(cookies):
def test_bake_invalid_name(cookies):
bake_in_temp_dir(cookies, extra_context={"ansible_collection": "foo-bar"})
def test_bake(cookies):
with bake_in_temp_dir(cookies) as result:
assert result.exit_code == 0
check_project_content(result, ANSIBLE_COLLECTION_FILES, ANSIBLE_COLLECTION_DIRS)
check_project_content(result, FILES, DIRS)

1
{{ cookiecutter.ansible_collection }}/.gitignore

@ -25,6 +25,7 @@ pip-delete-this-directory.txt
packer_cache/
# CUSTOM
.cache
pytestdebug.log
setup*done
tmp

8
{{ cookiecutter.ansible_collection }}/galaxy.yml

@ -1,11 +1,11 @@
---
namespace: {{ cookiecutter.ansible_namespace }}
name: {{ cookiecutter.ansible_collection }}
namespace: "{{ cookiecutter.ansible_namespace }}"
name: "{{ cookiecutter.ansible_collection }}"
version: 0.1.0
readme: README.md
authors:
- {{ cookiecutter.full_name }} <{{ cookiecutter.email }}>
description: {{ cookiecutter.collection_short_description }}
- "{{ cookiecutter.full_name }} <{{ cookiecutter.email }}>"
description: "{{ cookiecutter.collection_short_description }}"
license:
- Apache-2.0
tags: []

Loading…
Cancel
Save