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

Commit

Permalink
Merge pull request #8 from iamamutt/main
Browse files Browse the repository at this point in the history
Workflow template updates
  • Loading branch information
Joseph M. Burling authored Jul 20, 2022
2 parents a47a354 + a86a867 commit 64de5f9
Show file tree
Hide file tree
Showing 93 changed files with 2,942 additions and 667 deletions.
52 changes: 45 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ jobs:
create_annotated_tag: false
fetch_all_tags: true

generate_datajoint_workflow_content:
generate_datajoint-workflow:
runs-on: ubuntu-latest
needs: [get_tag]
if: |
always() &&
(needs.get_tag.result == 'success') &&
(github.ref_name == 'main') &&
(github.ref_type == 'branch')
outputs:
artifact: ${{ steps.bake-cookies.outputs.artifact }}

steps:
- name: Checkout Repository for Local Action
uses: actions/checkout@v3
Expand All @@ -44,28 +47,62 @@ jobs:
folder: science-institute_brain-lab
cookiecutter_pkg: git+https://github.com/cookiecutter/cookiecutter tomli pyyaml
new_tag: ${{ needs.get_tag.outputs.new_tag }}

generate_basic-package:
runs-on: ubuntu-latest
needs: [get_tag]
if: |
always() &&
(needs.get_tag.result == 'success') &&
(github.ref_name == 'main') &&
(github.ref_type == 'branch')
outputs:
artifact: ${{ steps.bake-cookies.outputs.artifact }}

steps:
- name: Checkout Repository for Local Action
uses: actions/checkout@v3

- name: Generate Content from 'basic-package' Template
id: bake-cookies
uses: ./.github/actions/bake-cookies
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
directory: basic-package
folder: datajoint_basic-package
cookiecutter_pkg: git+https://github.com/cookiecutter/cookiecutter tomli pyyaml
new_tag: ${{ needs.get_tag.outputs.new_tag }}



make_release:
runs-on: ubuntu-latest
needs: [get_tag, generate_datajoint_workflow_content]
needs: [get_tag, generate_datajoint-workflow, generate_basic-package]
if: |
always() &&
(needs.get_tag.result == 'success') &&
(needs.generate_datajoint_workflow_content.result == 'success')
(needs.generate_datajoint-workflow.result == 'success') &&
(needs.generate_basic-package.result == 'success')
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Downloading 'datajoint-workflow' Artifact Content
uses: actions/download-artifact@v3
with:
name: ${{ needs.generate_datajoint_workflow_content.outputs.artifact }}
path: ${{ needs.generate_datajoint_workflow_content.outputs.artifact }}
name: ${{ needs.generate_datajoint-workflow.outputs.artifact }}
path: ${{ needs.generate_datajoint-workflow.outputs.artifact }}

- name: Downloading 'basic-package' Artifact Content
uses: actions/download-artifact@v3
with:
name: ${{ needs.generate_basic-package.outputs.artifact }}
path: ${{ needs.generate_basic-package.outputs.artifact }}

- run: |
tar -zcf ${{ needs.generate_datajoint_workflow_content.outputs.artifact }}.tar.gz ${{ needs.generate_datajoint_workflow_content.outputs.artifact }}
tar -zcf ${{ needs.generate_datajoint-workflow.outputs.artifact }}.tar.gz ${{ needs.generate_datajoint-workflow.outputs.artifact }}
tar -zcf ${{ needs.generate_basic-package.outputs.artifact }}.tar.gz ${{ needs.generate_basic-package.outputs.artifact }}
- name: Create a Release
uses: ncipollo/release-action@v1
Expand All @@ -77,4 +114,5 @@ jobs:
allowUpdates: true
generateReleaseNotes: true
artifacts: |
${{ needs.generate_datajoint_workflow_content.outputs.artifact }}.tar.gz
${{ needs.generate_datajoint-workflow.outputs.artifact }}.tar.gz
${{ needs.generate_basic-package.artifact }}.tar.gz
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ dmypy.json
.build/
.DS_Store
/build
/science-institute_neuro-lab
/science-institute_brain-lab
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ cookiecutter --directory another-template gh:datajoint-company/dj-cookiecutter

- [`datajoint-workflow`](datajoint-workflow/README.md) by @Yambottle, @iamamutt
- [`element-example`](element-example/README.md) created as initial examples for science-team, welcome changes or new templates for your own requirements

> Note: the [`datajoint-workflow`](datajoint-workflow/README.md) template requires _cookiecutter>=2.0.0_
- [`basic-package`](basic-package/README.md) by @iamamutt
-
> Note: the [`datajoint-workflow`](datajoint-workflow/README.md) and [`basic-package`](basic-package/README.md) templates require _cookiecutter>=2.0.0_
---

Expand Down
101 changes: 101 additions & 0 deletions basic-package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Basic Python Package Template

_Cookiecutter Template for Basic Python Packages_

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.

## Features

- Python package build system: `setuptools>=62.0`
- Virtual environment: `conda`
- Automation:
- `pre-commit`: Before committing:
- Autoformat w/ `black`
- Sort imports with `isort`
- Process notebooks for version control w/ `nbstripout`
- Various file fixes
- `pytest`: Python testing framework
- `nox`: Automate python tasks in an isolated environment like packaging, versioning, testing
- `GitHub Actions`:
- Run tests on pushes and PR's
- GitHub issue templates
- IDE:
- `vscode`
- `code-workspace` Workspace file w/ recommended extensions, settings, and tasks.

## Using the template

### 1. Install `cookiecutter`

You can create a new python environment to install `cookiecutter` or use an existing environment, as long as you get `cookiecutter>=2.0.0`.

> **Note**: The example below uses `conda` to create a new environment called `cookies`, activates that environment, then uses `pip` to get the latest version.
```
conda create -yn cookies "python>=3.10" pip tomli pyyaml
conda activate cookies
pip install "git+https://github.com/cookiecutter/cookiecutter"
```

### 2. Generate the content from the template

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.

```
cookiecutter --directory basic-package gh:datajoint-company/dj-cookiecutter
```

> Note: cookiecutter will cache/clone this specified template repo to your user directory's ~/.cookiecutters
## Updating template content

If you have already started working on your project and you want to overwrite existing files,

```
cookiecutter --directory basic-package --overwrite-if-exists gh:datajoint-company/dj-cookiecutter
```

or to skip files that already exist,

```
cookiecutter --directory basic-package --skip-if-file-exists gh:datajoint-company/dj-cookiecutter
```

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).

## Editing the template (optional)

The following steps are only necessary if you want to customize or add to the template's content.

### Get template content

Clone this repository: `git clone https://github.com/datajoint-company/dj-cookiecutter`

Customize the template's content in the folder named [basic-package/{{cookecutter.github_repo}}](./{{cookiecutter.github_repo}}/README.md) only.

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.

### Build the content from the template

Make the cookiecutter package available.

```
cd dj-cookiecutter/basic-package
conda activate cookies
```

Build with prompts,

```
cookiecutter -f .
```

or use the default values you specified,

```
cookiecutter -vf --no-input .
```

### Adding back to a template

See [`retrocookie.sh`](../scripts/retrocookie/README.md) for more information.
29 changes: 29 additions & 0 deletions basic-package/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"author_name": "FirstName LastName",
"author_email": "{{cookiecutter.author_name|words(1)|lower}}@datajoint.com",
"organization": "DataJoint",
"package_name": "basic-package",
"__pkg_name": "{{cookiecutter.package_name|slugify}}",
"__pkg_import_name": "{{cookiecutter.package_name|slugify(separator='_')}}",
"github_user": [
"datajoint-company",
"datajoint",
"dj-sciops",
"iamamutt",
"ttngu207",
"yambottle",
"other-gh-username"
],
"github_repo": "{{cookiecutter.organization|slugify}}_{{cookiecutter.__pkg_name}}",
"python_version": [
"3.10",
"3.11",
"3.9"
],
"_vscode_ws_name": "pyproject",
"_pkg_version": "0.0.0",
"_extensions": [
"extensions.words"
],
"_new_lines": "\n"
}
7 changes: 7 additions & 0 deletions basic-package/extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from cookiecutter.utils import simple_filter


@simple_filter
def words(string: str, n: int = 1) -> str:
split = string.split()
return " ".join(split[: min(len(split), n)])
Loading

0 comments on commit 64de5f9

Please sign in to comment.