Skip to content

Commit

Permalink
Integrate with copier template. (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
huxuan authored Dec 13, 2022
1 parent bcbc8b7 commit 070dbef
Show file tree
Hide file tree
Showing 32 changed files with 684 additions and 32 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [{{ repo_namespace }}]
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
cache: "pip"
- run: make dev-lint
- run: make lint
test:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -32,8 +32,8 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- run: make dev-test
- run: make test
- run: make dev-tests
- run: make tests
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
if: matrix.python-version == '3.8'
17 changes: 17 additions & 0 deletions .github/workflows/readthedocs-preview.yml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Read the Docs Pull Request Preview

on:
pull_request_target:
types:
- opened

permissions:
pull-requests: write

jobs:
documentation-links:
runs-on: ubuntu-latest
steps:
- uses: readthedocs/actions/preview@v1
with:
project-slug: "{{ repo_name }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Custom
*.swp
.DS_Store
.copier-answers.yml
Pipfile

# Byte-compiled / optimized / DLL files
Expand Down
137 changes: 137 additions & 0 deletions .gitignore.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Custom
*.swp
.DS_Store
{%- if project_name == "Serious Scaffold Python" %}
.copier-answers.yml
{%- endif %}
Pipfile

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
9 changes: 7 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
requirements/docs.txt,
requirements/lint.txt,
requirements/package.txt,
requirements/test.txt,
requirements/tests.txt,
]
- id: sort-simple-yaml
files: .pre-commit-config.yaml
Expand All @@ -43,7 +43,7 @@ repos:
entry: pipenv run python -m isort
require_serial: true
types_or: [cython, pyi, python]
args: ['--filter-files']
args: ["--filter-files"]
- id: mypy
name: mypy
language: system
Expand All @@ -61,3 +61,8 @@ repos:
language: system
entry: pipenv run toml-sort -a -i
types: [toml]
- id: forbidden-files
name: forbidden files
entry: found Copier update rejection files; review them and remove them
language: fail
files: "\\.rej$"
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"autofix",
"automodule",
"codecov",
"huxuan",
"isort",
"mypy",
"pipenv",
Expand Down
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean deepclean install dev version pre-commit lint black mypy ruff toml-sort test freeze build upload docs docs-autobuild
.PHONY: clean deepclean install dev version pre-commit lint black mypy ruff toml-sort tests freeze build upload docs docs-autobuild

# Construct pipenv run command with or without site-packages flag when not in CI environment and pipenv command exists.
SITE_PACKAGES_FLAG = $(shell [ "${SS_SITE_PACKAGES}" = "true" ] && echo --site-packages)
Expand All @@ -7,18 +7,19 @@ PIPRUN := $(shell [ "${CI}" != "true" ] && command -v pipenv > /dev/null 2>&1 &&
# Remove common intermediate files.
clean:
-rm -rf \
*.egg-info \
.copier-answers.yml \
.coverage \
.mypy_cache \
.pytest_cache \
.ruff_cache \
Pipfile* \
coverage.xml \
dist \
docs\_build
docs/_build
find . -name '*.egg-info' -print0 | xargs -0 rm -rf
find . -name '*.pyc' -print0 | xargs -0 rm -f
find . -name '*.swp' -print0 | xargs -0 rm -f
find . -name '.DS_Store' -print0 | xargs -0 rm -rf
find . -name '.DS_Store' -print0 | xargs -0 rm -r
find . -name '__pycache__' -print0 | xargs -0 rm -rf

deepclean: clean
Expand All @@ -32,7 +33,7 @@ dev-%:
${PIPRUN} pip install -e .[$*] -c constraints/$(or $(SS_CONSTRAINTS_VERSION),default).txt

dev:
${PIPRUN} pip install -e .[docs,lint,package,test] -c constraints/$(or $(SS_CONSTRAINTS_VERSION),default).txt
${PIPRUN} pip install -e .[docs,lint,package,tests] -c constraints/$(or $(SS_CONSTRAINTS_VERSION),default).txt
-[ "${CI}" != "true" ] && pre-commit install --hook-type pre-push

version:
Expand All @@ -58,8 +59,8 @@ ruff:
toml-sort:
${PIPRUN} toml-sort -a -i pyproject.toml

test:
${PIPRUN} python -m pytest --cov=src --cov-fail-under=$(or $(SS_TEST_COVERAGE_THRESHOLD),0) .
tests:
${PIPRUN} python -m pytest .

freeze:
@${PIPRUN} pip freeze --exclude-editable
Expand Down
80 changes: 80 additions & 0 deletions Makefile.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.PHONY: clean deepclean install dev version pre-commit lint black mypy ruff toml-sort tests freeze build upload docs docs-autobuild

# Construct pipenv run command with or without site-packages flag when not in CI environment and pipenv command exists.
SITE_PACKAGES_FLAG = $(shell [ "${SS_SITE_PACKAGES}" = "true" ] && echo --site-packages)
PIPRUN := $(shell [ "${CI}" != "true" ] && command -v pipenv > /dev/null 2>&1 && echo pipenv ${SITE_PACKAGES_FLAG} run)

# Remove common intermediate files.
clean:
-rm -rf \
{%- if project_name == "Serious Scaffold Python" %}
.copier-answers.yml \
{%- endif %}
.coverage \
.mypy_cache \
.pytest_cache \
.ruff_cache \
Pipfile* \
coverage.xml \
dist \
docs/_build
find . -name '*.egg-info' -print0 | xargs -0 rm -rf
find . -name '*.pyc' -print0 | xargs -0 rm -f
find . -name '*.swp' -print0 | xargs -0 rm -f
find . -name '.DS_Store' -print0 | xargs -0 rm -r
find . -name '__pycache__' -print0 | xargs -0 rm -rf

deepclean: clean
-pre-commit uninstall --hook-type pre-push
-pipenv --venv >/dev/null 2>&1 && pipenv --rm

install:
${PIPRUN} pip install -e . -c constraints/$(or $(SS_CONSTRAINTS_VERSION),default).txt

dev-%:
${PIPRUN} pip install -e .[$*] -c constraints/$(or $(SS_CONSTRAINTS_VERSION),default).txt

dev:
${PIPRUN} pip install -e .[docs,lint,package,tests] -c constraints/$(or $(SS_CONSTRAINTS_VERSION),default).txt
-[ "${CI}" != "true" ] && pre-commit install --hook-type pre-push

version:
${PIPRUN} python -m setuptools_scm

pre-commit:
pre-commit run --all-files

black:
${PIPRUN} python -m black docs tests src

lint: isort mypy ruff toml-sort

isort:
${PIPRUN} python -m isort .

mypy:
${PIPRUN} python -m mypy docs tests src

ruff:
${PIPRUN} python -m ruff docs tests src

toml-sort:
${PIPRUN} toml-sort -a -i pyproject.toml

tests:
${PIPRUN} python -m pytest .

freeze:
@${PIPRUN} pip freeze --exclude-editable

build:
${PIPRUN} python -m build

upload:
${PIPRUN} python -m twine upload dist/*

docs:
${PIPRUN} python -m sphinx.cmd.build docs docs/_build

docs-autobuild:
${PIPRUN} python -m sphinx_autobuild docs docs/_build
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
A serious Python project template for out-of-box and production usage.

[![GitHub](https://img.shields.io/github/license/huxuan/serious-scaffold-python)](https://github.com/huxuan/serious-scaffold-python/blob/main/LICENSE)
[![Lint & Test Status](https://github.com/huxuan/serious-scaffold-python/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/huxuan/serious-scaffold-python/actions/workflows/ci.yml)
[![CI Status](https://github.com/huxuan/serious-scaffold-python/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/huxuan/serious-scaffold-python/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/huxuan/serious-scaffold-python/branch/main/graph/badge.svg?token=4JPKXI122N)](https://codecov.io/gh/huxuan/serious-scaffold-python)
[![Documentation Status](https://readthedocs.org/projects/serious-scaffold-python/badge/?version=latest)](https://serious-scaffold-python.readthedocs.io/en/latest/?badge=latest)
[![Documentation Status](https://readthedocs.org/projects/serious-scaffold-python/badge/)](https://serious-scaffold-python.readthedocs.io/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
Expand Down Expand Up @@ -34,12 +34,28 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons
- [`pre-commit`](https://github.com/pre-commit/pre-commit) with [general hooks](https://github.com/pre-commit/pre-commit-hooks) and local linters.
- `Makefile` as the entry point for common actions.
- VSCode settings with recommended extensions.
- GitHub workflows for lint, test, package and documentation preview.
- GitHub workflows for lint, tests, package and documentation preview.

## Usage

1. [Install Copier](https://copier.readthedocs.io/en/stable/#installation).
1. Generate the project with the following command.

```
copier gh:huxuan/serious-scaffold-python /path/to/project
```

1. Initialize the project with git.

```
cd /path/to/project && git init
```

1. Happy hacking.

## Roadmap

- More detailed documentation for all aspects.
- [Copier](https://copier.readthedocs.io/) integration.
- [GitHub Dependabot](https://github.com/dependabot) integration.
- [GitHub issue and pull request templates](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests).
- [Gitlab CI/CD](https://docs.gitlab.com/ee/ci/) integration.
Expand Down
Loading

0 comments on commit 070dbef

Please sign in to comment.