Skip to content

Commit

Permalink
fix: add missing conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
lsorber authored Apr 3, 2024
1 parent 489e00f commit fa74f82
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 49 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
with:
python-version: "3.8"

- name: Scaffold Python package
- name: Scaffold Python project
run: |
pip install --no-input cruft
cruft create --no-input --extra-context '{"project_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": "app", "project_name": "My App", "python_version": "3.8", "__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
Expand All @@ -48,19 +48,19 @@ jobs:
git checkout -b test
git add .
PYTHON_VERSION=${{ matrix.python-version }} devcontainer up --workspace-folder .
working-directory: ./my-package/
working-directory: ./my-app/

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

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

- name: Build app Docker image
uses: docker/build-push-action@v5
with:
build-args: |
SOURCE_BRANCH=${{ env.GITHUB_REF }}
SOURCE_COMMIT=${{ env.GITHUB_SHA }}
context: ./my-package/
context: ./my-app/
target: app
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ A modern [Cookiecutter](https://github.com/cookiecutter/cookiecutter) template f

## 🍿 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.
See [Conformal Tights](https://github.com/radix-ai/conformal-tights) for an example of a Python package 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).
Starting development can be done with a single click by [opening the package in GitHub Codespaces](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=765698489&skip_quickstart=true), or [opening the package in 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 Down Expand Up @@ -42,9 +42,9 @@ To create a new Python project with this 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 `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:
4. _Optional:_ 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 {package-name}/ {repository-name}/
cp -r {project-name}/ {repository-name}/
```

### Updating your Python project
Expand All @@ -56,18 +56,19 @@ To update your Python project with the latest template:

## 🤓 Template parameters

| Parameter | Description |
| ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `project_name` <br> "Spline Reticulator" | The name of the package. Will be slugified to `snake_case` for importing and `kebab-case` for installing. For example, `My Package` will be `my_package` for importing and `my-package` for installing. |
| `project_description` <br> "A Python package that reticulates splines." | A single-line description of the package. |
| `project_url` <br> "https://github.com/user/spline-reticulator" | The URL to the package's repository. |
| `author_name` <br> "John Smith" | The full name of the primary author of the package. |
| `author_email` <br> "[email protected]" | The email address of the primary author of the package. |
| `python_version` <br> "3.8" | The minimum Python version that the package requires. |
| `development_environment` <br> ["simple", "strict"] | Whether to configure the development environment with a focus on simplicity or with a focus on strictness. In strict mode, additional [Ruff rules](https://beta.ruff.rs/docs/rules/) are added, and tools such as [Mypy](https://github.com/python/mypy) and [Pytest](https://github.com/pytest-dev/pytest) are set to strict mode. |
| `with_conventional_commits` <br> ["0", "1"] | If "1", [Commitizen](https://github.com/commitizen-tools/commitizen) will verify that your commits follow the [Conventional Commits](https://www.conventionalcommits.org/) standard. In return, `cz bump` may be used to automate [Semantic Versioning](https://semver.org/) and [Keep A Changelog](https://keepachangelog.com/). |
| `with_fastapi_api` <br> ["0", "1"] | If "1", [FastAPI](https://github.com/tiangolo/fastapi) is added as a run time dependency, FastAPI API stubs and tests are added, a `poe api` command for serving the API is added, and an `app` stage that packages the API is added to the Dockerfile. Additionally, the CI workflow will push the application as a Docker image instead of publishing the Python package. |
| `with_typer_cli` <br> ["0", "1"] | If "1", [Typer](https://github.com/tiangolo/typer) is added as a run time dependency, Typer CLI stubs and tests are added, the package itself is registered as a CLI, and an `app` stage is added to the Dockerfile that packages the CLI. |
| `continuous_integration` <br> ["GitHub", "GitLab"] | Whether to include a [GitHub Actions](https://docs.github.com/en/actions) or a [GitLab CI/CD](https://docs.gitlab.com/ee/ci/) continuous integration workflow for testing and publishing the package or app. |
| `private_package_repository_name` <br> "Private Package Repository" | Optional name of a private package repository to install packages from and publish this package to. |
| `private_package_repository_url` <br> "https://pypi.example.com/simple" | Optional URL of a private package repository to install packages from and publish this package to. Make sure to include the `/simple` suffix. For instance, when using a GitLab Package Registry this value should be of the form `https://gitlab.com/api/v4/projects/` `{project_id}` `/packages/pypi/simple`. |
| Parameter | Description |
| ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `project_type` <br> ["package", "app"] | Whether the project is a publishable Python package or a deployable Python app. |
| `project_name` <br> "Spline Reticulator" | The name of the project. Will be slugified to `snake_case` for importing and `kebab-case` for installing. For example, `My Package` will be `my_package` for importing and `my-package` for installing. |
| `project_description` <br> "A Python package that reticulates splines." | A single-line description of the project. |
| `project_url` <br> "https://github.com/user/spline-reticulator" | The URL to the project's repository. |
| `author_name` <br> "John Smith" | The full name of the primary author of the project. |
| `author_email` <br> "[email protected]" | The email address of the primary author of the project. |
| `python_version` <br> "3.8" | The minimum Python version that the project requires. |
| `development_environment` <br> ["simple", "strict"] | Whether to configure the development environment with a focus on simplicity or with a focus on strictness. In strict mode, additional [Ruff rules](https://beta.ruff.rs/docs/rules/) are added, and tools such as [Mypy](https://github.com/python/mypy) and [Pytest](https://github.com/pytest-dev/pytest) are set to strict mode. |
| `with_conventional_commits` <br> ["0", "1"] | If "1", [Commitizen](https://github.com/commitizen-tools/commitizen) will verify that your commits follow the [Conventional Commits](https://www.conventionalcommits.org/) standard. In return, `cz bump` may be used to automate [Semantic Versioning](https://semver.org/) and [Keep A Changelog](https://keepachangelog.com/). |
| `with_fastapi_api` <br> ["0", "1"] | If "1", [FastAPI](https://github.com/tiangolo/fastapi) is added as a run time dependency, FastAPI API stubs and tests are added, a `poe api` command for serving the API is added. |
| `with_typer_cli` <br> ["0", "1"] | If "1", [Typer](https://github.com/tiangolo/typer) is added as a run time dependency, Typer CLI stubs and tests are added, the package itself is registered as a CLI. |
| `continuous_integration` <br> ["GitHub", "GitLab"] | Whether to include a [GitHub Actions](https://docs.github.com/en/actions) or a [GitLab CI/CD](https://docs.gitlab.com/ee/ci/) continuous integration workflow for testing the project, and publishing the package or deploying the app. |
| `private_package_repository_name` <br> "Private Package Repository" | Optional name of a private package repository to install packages from and publish this package to. |
| `private_package_repository_url` <br> "https://pypi.example.com/simple" | Optional URL of a private package repository to install packages from and publish this package to. Make sure to include the `/simple` suffix. For instance, when using a GitLab Package Registry this value should be of the form `https://gitlab.com/api/v4/projects/` `{project_id}` `/packages/pypi/simple`. |
6 changes: 3 additions & 3 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"project_type": [
"package",
"application"
"app"
],
"project_name": "{% if cookiecutter.project_type == 'application' %}My App{% else %}My Package{% endif %}",
"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": "{% if cookiecutter.project_type == 'application' %}3.12{% else %}3.10{% endif %}",
"python_version": "{% if cookiecutter.project_type == 'app' %}3.12{% else %}3.10{% endif %}",
"development_environment": [
"simple",
"strict"
Expand Down
2 changes: 1 addition & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with_fastapi_api = int("{{ cookiecutter.with_fastapi_api }}")
with_typer_cli = int("{{ cookiecutter.with_typer_cli }}")
continuous_integration = "{{ cookiecutter.continuous_integration }}"
is_application = "{{ cookiecutter.project_type == 'application' }}" == "True"
is_application = "{{ cookiecutter.project_type == 'app' }}" == "True"

# Remove py.typed and Dependabot if not in strict mode.
if development_environment != "strict":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
git config --global init.defaultBranch main
PYTHON_VERSION={% raw %}${{{% endraw %} matrix.python-version }} devcontainer up --workspace-folder .
- name: Lint package
- name: Lint {{ cookiecutter.project_type }}
run: devcontainer exec --workspace-folder . poe lint

- name: Test package
- name: Test {{ cookiecutter.project_type }}
run: devcontainer exec --workspace-folder . poe test

- name: Upload coverage
Expand Down
4 changes: 2 additions & 2 deletions {{ cookiecutter.__package_name_kebab_case }}/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Build:
reports:
dotenv: .env

# Lint and test the package.
# Lint and test the {{ cookiecutter.project_type }}.
Test:
extends:
- .python_matrix
Expand Down Expand Up @@ -101,7 +101,7 @@ Publish:
only:
- tags
{%- else -%}
# Deploy the application to the Docker registry.
# Deploy the app to the Docker registry.
Deploy:
stage: deploy
image: docker:latest
Expand Down
6 changes: 3 additions & 3 deletions {{ cookiecutter.__package_name_kebab_case }}/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ RUN git clone --branch v$ANTIDOTE_VERSION --depth=1 https://github.com/mattmc3/a
# Enable Poetry to read the private package repository credentials.
RUN ln -s /run/secrets/poetry-auth /home/user/.config/pypoetry/auth.toml
{%- endif %}
{%- if cookiecutter.project_type == "application" %}
{%- if cookiecutter.project_type == "app" %}



Expand All @@ -120,10 +120,10 @@ FROM base AS app
# Copy the virtual environment from the poetry stage.
COPY --from=poetry $VIRTUAL_ENV $VIRTUAL_ENV

# Copy the package source code to the working directory.
# Copy the {{ cookiecutter.project_type }} source code to the working directory.
COPY --chown=user:user . .

# Expose the application.
# Expose the app.
{%- if cookiecutter.with_typer_cli|int %}
ENTRYPOINT ["/opt/{{ cookiecutter.__project_name_kebab_case }}-env/bin/{{ cookiecutter.__project_name_kebab_case }}"]
CMD []
Expand Down
Loading

0 comments on commit fa74f82

Please sign in to comment.