-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1ed7f3
commit b1d92b7
Showing
33 changed files
with
1,094 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "pip" | ||
directory: "/{{cookiecutter.repostory_name}}/app/src" | ||
directory: "/{{cookiecutter.package_name}}/" | ||
schedule: | ||
interval: "daily" | ||
open-pull-requests-limit: 0 # Only security updates will be opened as PRs | ||
- package-ecosystem: "docker" | ||
directory: "/{{cookiecutter.repostory_name}}/app/envs/prod" | ||
schedule: | ||
interval: "weekly" | ||
- package-ecosystem: "docker" | ||
directory: "/docker" | ||
directory: "/{{cookiecutter.package_name}}/" # specify the directory to scan for dependency files, e.g., "/" | ||
schedule: | ||
interval: "weekly" | ||
open-pull-requests-limit: 0 # Only security updates will be opened as PRs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Continuous Integration | ||
|
||
on: | ||
push: | ||
branches: [master, main] | ||
pull_request: | ||
branches: [master, main] | ||
|
||
env: | ||
PYTHON_DEFAULT_VERSION: "3.12" | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ env.PYTHON_DEFAULT_VERSION }} | ||
cache: 'pip' | ||
cache-dependency-path: | | ||
**/pyproject.toml | ||
**/pdm.lock | ||
- name: Install dependencies | ||
run: python -m pip install --upgrade nox pdm | ||
- name: Run linters | ||
run: nox -vs lint | ||
check_crufted_project: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
cruft_config: ["default", "django"] | ||
env: | ||
CRUFT_TESTED_CONFIGS: ${{ matrix.cruft_config }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ env.PYTHON_DEFAULT_VERSION }} | ||
cache: 'pip' | ||
- name: Install dependencies | ||
run: python -m pip install --upgrade nox pdm | ||
- name: Run checks on project created from template | ||
run: nox -vt crufted_project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,81 @@ | ||
# cookiecutter-rt-pkg | ||
Cookiecutter for python packages | ||
|
||
Opinionated cookiecutter for Python packages. | ||
|
||
### TODO: | ||
# Features | ||
|
||
Must haves: | ||
* [ ] towncrier for changelog | ||
* [ ] CD (pypi) that runs CI workflow first | ||
* [ ] CI for cookiecutter itself (see https://github.com/reef-technologies/cookiecutter-rt-django/blob/master/.github/workflows/ci.yml) | ||
* [ ] rudimentary template readme | ||
Packages created from this template get following features: | ||
|
||
- CI with GitHub Actions | ||
- Trusted Publishing to PyPI with GitHub Actions | ||
- Signed release files using sigstore | ||
- Pre-configured nox for testing (pytest), autoformatting and auto linting (ruff) | ||
- Testing against multiple Python versions, operating systems, and optionally, Django versions | ||
- Package layout and release process with SemVer & ApiVer in mind | ||
- Towncrier for conflict free changelogs | ||
|
||
## Template features | ||
|
||
- CI for cookiecutter template itself | ||
|
||
## Planned features | ||
|
||
High priority: | ||
|
||
- [ ] testing utils for testing ApiVer modules | ||
|
||
Nice to haves: | ||
* [] Contributing guidelines | ||
* [] PR templates | ||
|
||
- [ ] CD should require CI tests to pass first | ||
- [ ] excluding some django-python combos in nox test matrix (allow to test of Django5+Python3.12 and Django4+Python3.9 but not Django5+Python3.9) | ||
- [ ] Contributing guidelines | ||
- [ ] PR templates | ||
- [ ] ability to build binary & python version-specific wheels | ||
|
||
## Usage | ||
|
||
[cruft](https://github.com/cruft/cruft) is used to manage the template, you can install it with: | ||
|
||
```sh | ||
pip install cruft | ||
``` | ||
|
||
### To generate a new package: | ||
|
||
1. Setup empty repository on GitHub | ||
2. Run: | ||
|
||
```sh | ||
cruft create https://github.com/reef-technologies/cookiecutter-rt-pkg | ||
``` | ||
|
||
3. Configure Trusted Publishers to allow GitHub Actions to publish to PyPI, follow instructions in [{{cookiecutter.package\_name}}/.github/workflows/publish.yml](.github/workflows/publish.yml) | ||
|
||
### When you wish to update your project to the latest version of the template: | ||
|
||
```sh | ||
cruft update | ||
``` | ||
|
||
Before committing make sure to review changes listed in [docs/3rd\_party/cookiecutter-rt-pkg/CHANGELOG.md](docs/3rd_party/cookiecutter-rt-pkg/CHANGELOG.md). | ||
|
||
### Linking an existing repository | ||
|
||
If you have an existing repo, you can link it to the template by running: | ||
|
||
```sh | ||
cruft link https://github.com/reef-technologies/cookiecutter-rt-django | ||
``` | ||
|
||
# Contributing | ||
|
||
When proposing new features or changes, please make sure there are also applicable to the application template [cookiecutter-rt-django](https://github.com/reef-technologies/cookiecutter-rt-django). | ||
This is to ensure we do not try to solve the same problem in two different ways. | ||
|
||
## License | ||
|
||
This project is licensed under the terms of the [BSD-3 License](/LICENSE) | ||
|
||
## Changelog | ||
|
||
Breaking changes are documented in the [CHANGELOG]({{cookiecutter.package_name}}/docs/3rd_party/cookiecutter-rt-django/CHANGELOG.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"package_name": "xxx", | ||
"repository_github_url": "https://github.com/reef-technologies/xxx", | ||
"is_django_package": "n", | ||
"_jinja2_env_vars": { | ||
"block_start_string": "# COOKIECUTTER{%", | ||
"block_end_string": "%}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python | ||
import contextlib | ||
import importlib.util | ||
import os | ||
import pathlib | ||
import re | ||
import subprocess | ||
|
||
PROJECT_ROOT = pathlib.Path().resolve() | ||
NOXFILE_PATH = PROJECT_ROOT / "noxfile.py" | ||
|
||
|
||
def is_django_support_enabled(): | ||
""" | ||
Check if DJANGO SUPPORT is enabled. | ||
""" | ||
# Since .cruft.json is not available at this point, we need to check from noxfile.py. | ||
spec = importlib.util.spec_from_file_location("noxfile", NOXFILE_PATH) | ||
noxfile = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(noxfile) | ||
|
||
return hasattr(noxfile, "DJANGO_VERSIONS") | ||
|
||
|
||
_DJANGO_ONL_FILE_MARKER = re.compile( | ||
r"^# cookiecutter-rt-pkg macro: requires cookiecutter.is_django_package$", | ||
re.MULTILINE, | ||
) | ||
|
||
|
||
def get_django_specific_files(): | ||
""" | ||
Find all files with `# cookiecutter-rt-pkg macro: requires cookiecutter.is_django_package` line. | ||
""" | ||
for file_path in PROJECT_ROOT.rglob("*.py"): | ||
with file_path.open() as f: | ||
try: | ||
content = f.read() | ||
except UnicodeDecodeError: | ||
continue | ||
without_marker_content = _DJANGO_ONL_FILE_MARKER.sub("", content) | ||
if content != without_marker_content: | ||
yield file_path, content | ||
|
||
|
||
@contextlib.contextmanager | ||
def working_directory(path): | ||
"""Changes working directory and returns to previous on exit.""" | ||
prev_cwd = pathlib.Path.cwd() | ||
os.chdir(path) | ||
try: | ||
yield | ||
finally: | ||
os.chdir(prev_cwd) | ||
|
||
|
||
def main(): | ||
django_support = is_django_support_enabled() | ||
print(f"{django_support=!r}") | ||
for filepath, new_content in get_django_specific_files(): | ||
if django_support: | ||
with filepath.open("w") as f: | ||
f.write(new_content) | ||
else: | ||
print(f"Removing django specific {filepath}") | ||
filepath.unlink() | ||
|
||
with working_directory(PROJECT_ROOT): | ||
subprocess.check_call(["pdm", "lock", "--update-reuse"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.