Skip to content

Commit fe439d9

Browse files
committed
Restructure and rename some arguments. Add Docker support
1 parent 6a0c7b0 commit fe439d9

File tree

23 files changed

+116
-16
lines changed

23 files changed

+116
-16
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# https://github.com/PyCQA/flake8/issues/234
33
[flake8]
44
exclude = docs
5-
{{cookiecutter.module_name}}
5+
{{cookiecutter.repository_name}}
66
max-line-length = 100

cookiecutter.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
"full_name": "Jørgen S. Dokken",
33
"email": "[email protected]",
44
"github_username": "jorgensd",
5-
"project_name": "Package Name",
6-
"module_name": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
5+
"project_name": "Research Project 1",
6+
"repository_name": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
7+
"module_name": "{{cookiecutter.repository_name}}",
78
"project_short_description": "Tools ensuring reproducible and standarized Python packaging.",
89
"version": "0.1.0",
910
"linting": "y",
1011
"testing": ["pytest", "pytest-cov", "none"],
1112
"use_argparse": "y",
1213
"build_docs": "y",
14+
"docker": "y",
1315
"open_source_license": ["MIT", "GPL-3.0", "Other"],
1416
"_copy_without_render": [".github/*"]
1517
}

docs/options.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ The following options are available when using the cookiecutter:
55
2. __Email__: Will be used in `pyproject.toml` for package information.
66
3. __github\_username__: Will be used to fetch the correct links for the documentation and [license badge](https://scientificcomputing.github.io/reproducibility/part5/badges.html#licence).
77
4. __project\_name__: Used in various headers of the documentation
8-
5. __module\_name__: Name of the python module.
9-
6. __project\_short\_description__: Usin in `pyproject.toml`
10-
7. __version__: The initial version of the software.
11-
8. __linting__: Enable linting, i.e. [mypy](https://scientificcomputing.github.io/reproducibility/part1/typing.html) and [flake8](https://scientificcomputing.github.io/reproducibility/part1/linting.html). This also enables the "Check Formatting" Github action.
12-
9. __testing__: Creates a test folder with an initial test. Also adds [optional installation dependencies](https://scientificcomputing.github.io/reproducibility/part1/packaging.html#optional-dependencies) to `pyproject.toml`. Creates a "Test Package" Githib action.
8+
5. __repository\_name__: Name of the repository
9+
6. __package\_name__: Name of the python package.
10+
7. __project\_short\_description__: Usin in `pyproject.toml`
11+
8. __version__: The initial version of the software.
12+
9. __linting__: Enable linting, i.e. [mypy](https://scientificcomputing.github.io/reproducibility/part1/typing.html) and [flake8](https://scientificcomputing.github.io/reproducibility/part1/linting.html). This also enables the "Check Formatting" Github action.
13+
10. __testing__: Choose testing framework. If not `none` it creates a test folder with an initial test. Also adds [optional installation dependencies](https://scientificcomputing.github.io/reproducibility/part1/packaging.html#optional-dependencies) to `pyproject.toml`. Creates a "Test Package" Github action. If `pytest-cov` is chosen, it adds settings to generate a coverage report and publsuh them as a [Github artifact](https://scientificcomputing.github.io/reproducibility/part1/coverage.html).
1314
10. __use\_argparse__: Makes it possible to run the package as `module_name` or `python -m module_name` with inputs from the command line.
1415
11. __build\_docs__: Build a webpage with documentation (including a package API).
15-
12. __open\_source\_license__: Choose a open source license for your code
16+
12. __docker__: Adds a Dockerfile that includes the module (not including optional dependencies). Adds a [publishing workflow](https://scientificcomputing.github.io/reproducibility/part4/docker.html#github-packages).
17+
13. __open\_source\_license__: Choose a open source license for your code

hooks/post_gen_project.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,21 @@
2020
'docs/api.rst',
2121
'docs/index.md',
2222
'docs/logo.png',
23-
'docs'
23+
'docs',
24+
{% endif %}
25+
{%- if cookiecutter.docker|lower != "y" %}
26+
'Dockerfile',
27+
'.github/workflows/docker-image.yml',
28+
{% endif %}
29+
{%- if cookiecutter.use_argparse|lower != "y" %}
30+
'src/{{ cookiecutter.module_name }}/__main__.py',
31+
'src/{{ cookiecutter.module_name }}/cli.py',
2432
{% endif %}
2533
]
2634

2735
for path in REMOVE_PATHS:
2836
path = path.strip()
37+
print(path)
2938
if path and os.path.exists(path):
3039
if os.path.isdir(path):
3140
os.rmdir(path)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: Create and publish a Docker image
7+
8+
on:
9+
push:
10+
branches:
11+
- "!*"
12+
tags:
13+
- "v*"
14+
15+
env:
16+
REGISTRY: ghcr.io
17+
IMAGE_NAME: ${{ github.repository }}
18+
19+
jobs:
20+
build-and-push-image:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v2
29+
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
43+
- name: Build and push Docker image
44+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
45+
with:
46+
context: .
47+
push: true
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)