Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 64de5f9

Browse files
author
Joseph M. Burling
authored
Merge pull request #8 from iamamutt/main
Workflow template updates
2 parents a47a354 + a86a867 commit 64de5f9

File tree

93 files changed

+2942
-667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2942
-667
lines changed

.github/workflows/ci.yml

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ jobs:
2323
create_annotated_tag: false
2424
fetch_all_tags: true
2525

26-
generate_datajoint_workflow_content:
26+
generate_datajoint-workflow:
2727
runs-on: ubuntu-latest
2828
needs: [get_tag]
2929
if: |
3030
always() &&
3131
(needs.get_tag.result == 'success') &&
3232
(github.ref_name == 'main') &&
3333
(github.ref_type == 'branch')
34+
outputs:
35+
artifact: ${{ steps.bake-cookies.outputs.artifact }}
36+
3437
steps:
3538
- name: Checkout Repository for Local Action
3639
uses: actions/checkout@v3
@@ -44,28 +47,62 @@ jobs:
4447
folder: science-institute_brain-lab
4548
cookiecutter_pkg: git+https://github.com/cookiecutter/cookiecutter tomli pyyaml
4649
new_tag: ${{ needs.get_tag.outputs.new_tag }}
50+
51+
generate_basic-package:
52+
runs-on: ubuntu-latest
53+
needs: [get_tag]
54+
if: |
55+
always() &&
56+
(needs.get_tag.result == 'success') &&
57+
(github.ref_name == 'main') &&
58+
(github.ref_type == 'branch')
4759
outputs:
4860
artifact: ${{ steps.bake-cookies.outputs.artifact }}
4961

62+
steps:
63+
- name: Checkout Repository for Local Action
64+
uses: actions/checkout@v3
65+
66+
- name: Generate Content from 'basic-package' Template
67+
id: bake-cookies
68+
uses: ./.github/actions/bake-cookies
69+
with:
70+
github_token: ${{ secrets.GITHUB_TOKEN }}
71+
directory: basic-package
72+
folder: datajoint_basic-package
73+
cookiecutter_pkg: git+https://github.com/cookiecutter/cookiecutter tomli pyyaml
74+
new_tag: ${{ needs.get_tag.outputs.new_tag }}
75+
76+
77+
5078
make_release:
5179
runs-on: ubuntu-latest
52-
needs: [get_tag, generate_datajoint_workflow_content]
80+
needs: [get_tag, generate_datajoint-workflow, generate_basic-package]
5381
if: |
5482
always() &&
5583
(needs.get_tag.result == 'success') &&
56-
(needs.generate_datajoint_workflow_content.result == 'success')
84+
(needs.generate_datajoint-workflow.result == 'success') &&
85+
(needs.generate_basic-package.result == 'success')
86+
5787
steps:
5888
- name: Checkout Repository
5989
uses: actions/checkout@v3
6090

6191
- name: Downloading 'datajoint-workflow' Artifact Content
6292
uses: actions/download-artifact@v3
6393
with:
64-
name: ${{ needs.generate_datajoint_workflow_content.outputs.artifact }}
65-
path: ${{ needs.generate_datajoint_workflow_content.outputs.artifact }}
94+
name: ${{ needs.generate_datajoint-workflow.outputs.artifact }}
95+
path: ${{ needs.generate_datajoint-workflow.outputs.artifact }}
96+
97+
- name: Downloading 'basic-package' Artifact Content
98+
uses: actions/download-artifact@v3
99+
with:
100+
name: ${{ needs.generate_basic-package.outputs.artifact }}
101+
path: ${{ needs.generate_basic-package.outputs.artifact }}
66102

67103
- run: |
68-
tar -zcf ${{ needs.generate_datajoint_workflow_content.outputs.artifact }}.tar.gz ${{ needs.generate_datajoint_workflow_content.outputs.artifact }}
104+
tar -zcf ${{ needs.generate_datajoint-workflow.outputs.artifact }}.tar.gz ${{ needs.generate_datajoint-workflow.outputs.artifact }}
105+
tar -zcf ${{ needs.generate_basic-package.outputs.artifact }}.tar.gz ${{ needs.generate_basic-package.outputs.artifact }}
69106
70107
- name: Create a Release
71108
uses: ncipollo/release-action@v1
@@ -77,4 +114,5 @@ jobs:
77114
allowUpdates: true
78115
generateReleaseNotes: true
79116
artifacts: |
80-
${{ needs.generate_datajoint_workflow_content.outputs.artifact }}.tar.gz
117+
${{ needs.generate_datajoint-workflow.outputs.artifact }}.tar.gz
118+
${{ needs.generate_basic-package.artifact }}.tar.gz

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,4 @@ dmypy.json
132132
.build/
133133
.DS_Store
134134
/build
135-
/science-institute_neuro-lab
135+
/science-institute_brain-lab

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ cookiecutter --directory another-template gh:datajoint-company/dj-cookiecutter
7777

7878
- [`datajoint-workflow`](datajoint-workflow/README.md) by @Yambottle, @iamamutt
7979
- [`element-example`](element-example/README.md) created as initial examples for science-team, welcome changes or new templates for your own requirements
80-
81-
> Note: the [`datajoint-workflow`](datajoint-workflow/README.md) template requires _cookiecutter>=2.0.0_
80+
- [`basic-package`](basic-package/README.md) by @iamamutt
81+
-
82+
> Note: the [`datajoint-workflow`](datajoint-workflow/README.md) and [`basic-package`](basic-package/README.md) templates require _cookiecutter>=2.0.0_
8283
8384
---
8485

basic-package/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Basic Python Package Template
2+
3+
_Cookiecutter Template for Basic Python Packages_
4+
5+
This [`cookiecutter`](https://cookiecutter.readthedocs.io/en/2.0.2/) template creates a python package based on the latest `setuptools` build backend. This follows the new [PEP 621](https://www.python.org/dev/peps/pep-0621/) standard of using a single `pyproject.toml` config file for specifying and building python packages.
6+
7+
## Features
8+
9+
- Python package build system: `setuptools>=62.0`
10+
- Virtual environment: `conda`
11+
- Automation:
12+
- `pre-commit`: Before committing:
13+
- Autoformat w/ `black`
14+
- Sort imports with `isort`
15+
- Process notebooks for version control w/ `nbstripout`
16+
- Various file fixes
17+
- `pytest`: Python testing framework
18+
- `nox`: Automate python tasks in an isolated environment like packaging, versioning, testing
19+
- `GitHub Actions`:
20+
- Run tests on pushes and PR's
21+
- GitHub issue templates
22+
- IDE:
23+
- `vscode`
24+
- `code-workspace` Workspace file w/ recommended extensions, settings, and tasks.
25+
26+
## Using the template
27+
28+
### 1. Install `cookiecutter`
29+
30+
You can create a new python environment to install `cookiecutter` or use an existing environment, as long as you get `cookiecutter>=2.0.0`.
31+
32+
> **Note**: The example below uses `conda` to create a new environment called `cookies`, activates that environment, then uses `pip` to get the latest version.
33+
34+
```
35+
conda create -yn cookies "python>=3.10" pip tomli pyyaml
36+
conda activate cookies
37+
pip install "git+https://github.com/cookiecutter/cookiecutter"
38+
```
39+
40+
### 2. Generate the content from the template
41+
42+
You can use `cookiecutter` to use a template without having to manually download or clone the repository itself. The following command will use the template from the directory called `basic-package`, then prompt you to fill out some entries, or press `ENTER` to accept the default values shown.
43+
44+
```
45+
cookiecutter --directory basic-package gh:datajoint-company/dj-cookiecutter
46+
```
47+
48+
> Note: cookiecutter will cache/clone this specified template repo to your user directory's ~/.cookiecutters
49+
50+
## Updating template content
51+
52+
If you have already started working on your project and you want to overwrite existing files,
53+
54+
```
55+
cookiecutter --directory basic-package --overwrite-if-exists gh:datajoint-company/dj-cookiecutter
56+
```
57+
58+
or to skip files that already exist,
59+
60+
```
61+
cookiecutter --directory basic-package --skip-if-file-exists gh:datajoint-company/dj-cookiecutter
62+
```
63+
64+
If you want to regenerate the most recent version of the cookiecutter template without having to re-type the values you already specified during setup, run the script [`replay.sh`](../scripts/replay/README.md).
65+
66+
## Editing the template (optional)
67+
68+
The following steps are only necessary if you want to customize or add to the template's content.
69+
70+
### Get template content
71+
72+
Clone this repository: `git clone https://github.com/datajoint-company/dj-cookiecutter`
73+
74+
Customize the template's content in the folder named [basic-package/{{cookecutter.github_repo}}](./{{cookiecutter.github_repo}}/README.md) only.
75+
76+
Change the values in [basic-package/cookiecutter.json](./cookiecutter.json). Don't edit anything that starts with an underscore `_*` or `__*`, or starting at the line `"_copy_without_render"` and below unless you know what they are for.
77+
78+
### Build the content from the template
79+
80+
Make the cookiecutter package available.
81+
82+
```
83+
cd dj-cookiecutter/basic-package
84+
conda activate cookies
85+
```
86+
87+
Build with prompts,
88+
89+
```
90+
cookiecutter -f .
91+
```
92+
93+
or use the default values you specified,
94+
95+
```
96+
cookiecutter -vf --no-input .
97+
```
98+
99+
### Adding back to a template
100+
101+
See [`retrocookie.sh`](../scripts/retrocookie/README.md) for more information.

basic-package/cookiecutter.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"author_name": "FirstName LastName",
3+
"author_email": "{{cookiecutter.author_name|words(1)|lower}}@datajoint.com",
4+
"organization": "DataJoint",
5+
"package_name": "basic-package",
6+
"__pkg_name": "{{cookiecutter.package_name|slugify}}",
7+
"__pkg_import_name": "{{cookiecutter.package_name|slugify(separator='_')}}",
8+
"github_user": [
9+
"datajoint-company",
10+
"datajoint",
11+
"dj-sciops",
12+
"iamamutt",
13+
"ttngu207",
14+
"yambottle",
15+
"other-gh-username"
16+
],
17+
"github_repo": "{{cookiecutter.organization|slugify}}_{{cookiecutter.__pkg_name}}",
18+
"python_version": [
19+
"3.10",
20+
"3.11",
21+
"3.9"
22+
],
23+
"_vscode_ws_name": "pyproject",
24+
"_pkg_version": "0.0.0",
25+
"_extensions": [
26+
"extensions.words"
27+
],
28+
"_new_lines": "\n"
29+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from cookiecutter.utils import simple_filter
2+
3+
4+
@simple_filter
5+
def words(string: str, n: int = 1) -> str:
6+
split = string.split()
7+
return " ".join(split[: min(len(split), n)])

0 commit comments

Comments
 (0)