Skip to content

Commit

Permalink
Merge branch 'radix-ai-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
awheat committed Jul 25, 2024
2 parents 1368fdc + 1a7556b commit 1b6ef3d
Show file tree
Hide file tree
Showing 37 changed files with 319 additions and 295 deletions.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"customizations": {
"vscode": {
"extensions": [
"DavidAnson.vscode-markdownlint",
"ms-python.python",
"tamasfe.even-better-toml",
"visualstudioexptteam.vscodeintellicode"
Expand Down
28 changes: 15 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
python-version: ["3.9", "3.12"]
project-type: ["app", "package"]

name: Python ${{ matrix.python-version }}
name: Python ${{ matrix.python-version }} ${{ matrix.project-type }}

steps:
- name: Checkout
Expand All @@ -24,22 +25,22 @@ jobs:
path: template

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.9"

- name: Scaffold Python package
- name: Scaffold Python project
run: |
pip install --no-input cruft
cruft create --no-input --extra-context '{"package_name": "My Package", "python_version": "3.8", "docker_image":"radixai/python-gpu:$PYTHON_VERSION-cuda11.8", "with_fastapi_api": "1", "with_typer_cli": "1"}' ./template/
cruft create --no-input --extra-context '{"project_type": "${{ matrix.project-type }}", "project_name": "My Project", "python_version": "3.9", "__docker_image":"radixai/python-gpu:$PYTHON_VERSION-cuda11.8", "with_fastapi_api": "1", "with_typer_cli": "1"}' ./template/
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 21

- name: Install @devcontainers/cli
run: npm install --location=global @devcontainers/cli@0.55.0
run: npm install --location=global @devcontainers/cli@0.58.0

- name: Start Dev Container with Python ${{ matrix.python-version }}
run: |
Expand All @@ -48,19 +49,20 @@ jobs:
git checkout -b test
git add .
PYTHON_VERSION=${{ matrix.python-version }} devcontainer up --workspace-folder .
working-directory: ./my-package/
working-directory: ./my-project/

- name: Lint package
run: devcontainer exec --workspace-folder my-package poe lint
- name: Lint project
run: devcontainer exec --workspace-folder my-project poe lint

- name: Test package
run: devcontainer exec --workspace-folder my-package poe test
- name: Test project
run: devcontainer exec --workspace-folder my-project poe test

- name: Build app Docker image
if: ${{ matrix.project-type == 'app' }}
uses: docker/build-push-action@v5
with:
build-args: |
SOURCE_BRANCH=${{ env.GITHUB_REF }}
SOURCE_COMMIT=${{ env.GITHUB_SHA }}
context: ./my-package/
context: ./my-project/
target: app
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/radix-ai/poetry-cookiecutter) [![Open in GitHub Codespaces](https://img.shields.io/static/v1?label=GitHub%20Codespaces&message=Open&color=blue&logo=github)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=444870763)

# Poetry Cookiecutter
# 🍪 Poetry Cookiecutter

A modern [Cookiecutter](https://github.com/cookiecutter/cookiecutter) template for scaffolding Python packages and apps.

## 🍿 Demo

See [My Package](https://github.com/radix-ai/my-package) for an example of a Python package and app that is scaffolded with this template.

Starting development in My Package can be done with a single click by [opening My Package in GitHub Codespaces](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=450509735), or [opening My Package in a Dev Container](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/radix-ai/my-package).
See 👖 [Conformal Tights](https://github.com/radix-ai/conformal-tights) for an example of a Python package that is scaffolded with this template. Contributing to this package can be done with a single click by [starting a GitHub Codespace](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=765698489&skip_quickstart=true) or [starting a Dev Container](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/radix-ai/conformal-tights).

## 🎁 Features

Expand All @@ -34,25 +32,41 @@ Starting development in My Package can be done with a single click by [opening M
To create a new Python project with this template:

1. Install the latest [Cruft](https://github.com/cruft/cruft) and [Cookiecutter](https://github.com/cookiecutter/cookiecutter) in your [Python environment](https://github.com/pyenv/pyenv-virtualenv) with:

```sh
pip install --upgrade "cruft>=2.12.0" "cookiecutter>=2.1.1"
```
2. Create a new repository for your Python project, then clone it locally.

2. [Create a new repository](https://github.com/new) for your Python project, then clone it locally.
3. Run the following command in the parent directory of the cloned repository to apply the Poetry Cookiecutter template:

```sh
cruft create -f https://github.com/radix-ai/poetry-cookiecutter
```
4. _Optional:_ if your repository name differs from your project's slugified package name (see `package_name` in the [Template parameters](https://github.com/radix-ai/poetry-cookiecutter#-template-parameters) below), you will need to copy the scaffolded project into the repository with:
```sh
cp -r {package-name}/ {repository-name}/
```

<details>

<summary>⚠️ If your repository name ≠ the project's slugified name</summary>

If your repository name differs from your project's slugified name (see `project_name` in the [Template parameters](https://github.com/radix-ai/poetry-cookiecutter#-template-parameters) below), you will need to copy the scaffolded project into the repository with:

```sh
cp -r {project-name}/ {repository-name}/
```

</details>

### Updating your Python project

To update your Python project with the latest template:
To update your Python project to the latest template version:

1. Update the project while verifying the existing template parameters and setting any new parameters, if there are any:

```sh
cruft update --cookiecutter-input
```

1. Run `cruft update` to update your project with the latest template.
2. If any of the updates failed, resolve them by inspecting the generated `.rej` files.
2. If any of the file updates failed, resolve them by inspecting the corresponding `.rej` files.

## 🤓 Template parameters

Expand Down
32 changes: 20 additions & 12 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
{
"package_name": "My Package",
"package_description": "A Python package that ...",
"package_url": "https://github.com/user/my-package",
"project_type": [
"package",
"app"
],
"project_name": "{% if cookiecutter.project_type == 'app' %}My App{% else %}My Package{% endif %}",
"project_description": "A Python {{ cookiecutter.project_type }} that reticulates splines.",
"project_url": "https://github.com/user/my-{{ cookiecutter.project_type }}",
"author_name": "John Smith",
"author_email": "[email protected]",
"python_version": "3.8",
"docker_image": "python:$PYTHON_VERSION-slim",
"with_zscaler_cert": "1",
"development_environment": ["simple", "strict"],
"python_version": "{% if cookiecutter.project_type == 'app' %}3.12{% else %}3.10{% endif %}",
"development_environment": [
"simple",
"strict"
],
"with_conventional_commits": "{% if cookiecutter.development_environment == 'simple' %}0{% else %}1{% endif %}",
"with_fastapi_api": "0",
"with_jupyter_lab": "0",
"with_pydantic_typing": "0",
"with_sentry_logging": "0",
"with_streamlit_app": "0",
"with_typer_cli": "0",
"continuous_integration": ["GitHub", "GitLab"],
"docstring_style": ["NumPy", "Google"],
"continuous_integration": [
"GitHub",
"GitLab"
],
"private_package_repository_name": "",
"private_package_repository_url": "",
"__package_name_kebab_case": "{{ cookiecutter.package_name|slugify }}",
"__package_name_snake_case": "{{ cookiecutter.package_name|slugify(separator='_') }}"
"__docker_image": "python:$PYTHON_VERSION-slim",
"__docstring_style": "NumPy",
"__project_name_kebab_case": "{{ cookiecutter.project_name|slugify }}",
"__project_name_snake_case": "{{ cookiecutter.project_name|slugify(separator='_') }}"
}
28 changes: 8 additions & 20 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,26 @@
import shutil

# Read Cookiecutter configuration.
package_name = "{{ cookiecutter.__package_name_snake_case }}"
project_name = "{{ cookiecutter.__project_name_snake_case }}"
development_environment = "{{ cookiecutter.development_environment }}"
with_fastapi_api = int("{{ cookiecutter.with_fastapi_api }}")
with_sentry_logging = int("{{ cookiecutter.with_sentry_logging }}")
with_streamlit_app = int("{{ cookiecutter.with_streamlit_app }}")
with_typer_cli = int("{{ cookiecutter.with_typer_cli }}")
continuous_integration = "{{ cookiecutter.continuous_integration }}"
is_deployable_app = "{{ not not cookiecutter.with_fastapi_api|int or not not cookiecutter.with_streamlit_app|int }}" == "True"
is_publishable_package = "{{ not cookiecutter.with_fastapi_api|int and not cookiecutter.with_streamlit_app|int }}" == "True"
is_application = "{{ cookiecutter.project_type == 'app' }}" == "True"

# Remove py.typed and Dependabot if not in strict mode.
if development_environment != "strict":
os.remove(f"src/{package_name}/py.typed")
os.remove(f"src/{project_name}/py.typed")
os.remove(".github/dependabot.yml")

# Remove FastAPI if not selected.
if not with_fastapi_api:
os.remove(f"src/{package_name}/api.py")
os.remove(f"src/{project_name}/api.py")
os.remove("tests/test_api.py")

# Remove Sentry if not selected.
if not with_sentry_logging:
os.remove(f"src/{package_name}/sentry.py")
os.remove("tests/test_sentry.py")

# Remove Streamlit if not selected.
if not with_streamlit_app:
os.remove(f"src/{package_name}/app.py")

# Remove Typer if not selected.
if not with_typer_cli:
os.remove(f"src/{package_name}/cli.py")
os.remove(f"src/{project_name}/cli.py")
os.remove("tests/test_cli.py")

# Remove the continuous integration provider that is not selected.
Expand All @@ -44,7 +32,7 @@

# Remove unused GitHub Actions workflows.
if continuous_integration == "GitHub":
if not is_deployable_app:
os.remove(".github/workflows/deploy.yml")
if not is_publishable_package:
if is_application:
os.remove(".github/workflows/publish.yml")
else:
os.remove(".github/workflows/deploy.yml")

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions {{ cookiecutter.__package_name_kebab_case }}/tests/test_cli.py

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions {{ cookiecutter.__package_name_kebab_case }}/tests/test_sentry.py

This file was deleted.

Loading

0 comments on commit 1b6ef3d

Please sign in to comment.