Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for poetry and hatchling backends #43

Merged
merged 14 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Test Template Instance

on:
pull_request:
branches:
- main

jobs:
test-project-creation:
name: Test project creation with ${{ matrix.typing }} typing
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
typing: [no_typing, loose, strict]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install Dependencies
run: |
pip install copier pre-commit
- name: Create new project
run: |
mkdir my-project
copier copy \
-d project_name=test \
-d project_short_description="A great package." \
-d python_name=test \
-d url=https://github.com/gh_actions/test \
-d min_python_version=3.10 \
-d org=gh_actions \
-d full_name=gh_actions \
-d [email protected] \
-d license=BSD \
-d backend=setuptools \
-d typing=${{ matrix.typing }} \
-d coc=our_coc \
--vcs-ref HEAD \
. my-project
- name: Check generated project installs with pip
run: |
cd my-project
git config --global user.email "[email protected]"
git config --global user.name "gh_actions"
git init
git add .
git commit -m "Initial commit"
pip install -e .

format-created-project:
name: Try formatting the created project with ${{ matrix.typing }} typing
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
typing: [no_typing, loose, strict]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install Dependencies
run: |
pip install copier pre-commit
- name: Create new project
run: |
mkdir my-project
copier copy \
-d project_name=test \
-d project_short_description="A great package." \
-d python_name=test \
-d url=https://github.com/gh_actions/test \
-d min_python_version=3.10 \
-d org=gh_actions \
-d full_name=gh_actions \
-d [email protected] \
-d license=BSD \
-d backend=setuptools \
-d typing=${{ matrix.typing }} \
-d coc=our_coc \
--vcs-ref HEAD \
. my-project
- name: Run formatting checks
run: |
cd my-project
git init
git config --global user.email "[email protected]"
git config --global user.name "gh_actions"
git add --all
git commit -m "Initial commit"
pre-commit run --all-files
55 changes: 0 additions & 55 deletions .github/workflows/main.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/pre-commit-autoupdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
schedule:
- cron: '*/5 3 * * *'


jobs:
update-template:
if: github.repository == 'alan-turing-institute/python-project-template'
Expand All @@ -27,7 +27,7 @@ jobs:
cd project_template
pre-commit autoupdate

- name: Push changes
- name: Push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
add_options: '-u'
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Template for Python projects

This simple template is designed to help you get started with a new Python project. It includes:
This setuptools-based template is designed to help you get started with a new Python project, or migrate an existing codebase. It includes:

- The recommended `src/` layout for a Python package
- A pre-configured `pyproject.toml` that controls your project metadata
Expand Down Expand Up @@ -45,10 +45,6 @@ You will be prompted for the following information:
- `project_name`: The name of your project. This will be used to name the
project directory, the Python package, and the GitHub repository.
- `project_short_description`: A short description of your project.
- `backend`: The backend to use for dependency management. Here, I've supported the main choices in our Research Engineering Group (`setuptools`/`poetry`), as well as `hatch`, which I've been using more recently.
- [`setuptools`](https://setuptools.readthedocs.io/en/latest/): The default Python packaging tool, configured with `pyproject.toml`.
- [`hatch`](https://hatch.pypa.io/latest/): Almost identical to `setuptools` in terms of config, but with a few extra features.
- [`poetry`](https://python-poetry.org/): An all-in-one tool for dependency management, packaging, and publishing, with a high learning curve. Use if you know what you're doing -- otherwise, I'd stick with `setuptools` or `hatch`.
- `license`: The license to use for your project — PRs for other choices are welcome! The current supported options include:
- `MIT`
- `BSD-3-Clause`
Expand Down Expand Up @@ -104,8 +100,7 @@ If you're taking code you've already written and want to use this template, you'
- By library code, I mean the code that you want to be importable by other Python code. If you have things like experiments, scripts, or notebooks, you should keep them in the root directory under a different name (e.g. `examples`, `notebooks` etc.)
- Copy over any tests you have into the `tests` directory.
- Go through the `pyproject.toml` file and make sure that the metadata is correct. This includes the `name`, `description`, `version`, `authors`, `license`, and `classifiers` fields.
- Add your dependencies to the relevant section of the `pyproject.toml` file.
- If you're using `setuptools` or `hatch`, you'll need to add them to the `install_requires` field. Dependencies are formatted like this:
- Add your dependencies to the relevant section of the `pyproject.toml` file under the `install_requires` field. Dependencies are formatted like this:
```
[project]
install_requires = [
Expand All @@ -115,7 +110,6 @@ If you're taking code you've already written and want to use this template, you'
]
```
where the first part is the package name, and the second part is the version specifier. You can find more information on version specifiers [here](https://www.python.org/dev/peps/pep-0440/#version-specifiers) to help you write these.
- If you're using `poetry`, you'll need to add them to the `dependencies` field under the `tool.poetry` section.

Once you've set up your new project, you can start developing your package. There are some guidelines for development included in the [`CONTRIBUTING.md`](project_template/CONTRIBUTING.md) file generated in your project, but the main things are repeated below.

Expand All @@ -124,7 +118,7 @@ Once you've set up your new project, you can start developing your package. Ther

_Note: I will not be covering Conda environments in this section. Conda is great when your project has dependencies outside of Python packages that you want to manage! If you're using Conda, you can still use this template – these are just recommendations for managing Python environments that don't affect the package itself._

Every project should have a Python environment set up to manage dependencies. `poetry` has its own virtual environment management (if you're not familiar with it, maybe don't use poetry!), but if you're using `setuptools` or `hatch`, you can use `venv` to create a new environment in the root of your project. To create an environment called `.venv`, run the following command in your terminal:
Every project should have a Python environment set up to manage dependencies. You can use the built-in Python tool `venv` to create a new environment in the root of your project. To create an environment called `.venv`, run the following command in your terminal:

```
python -m venv .venv
Expand Down
9 changes: 0 additions & 9 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ url:
help: Provide/modify the url to your GitHub repository if needed.
default: "https://github.com/{{org}}/{{project_name}}"


python_name:
type: str
help: The Python package import name (for `import NAME` in Python code)
Expand Down Expand Up @@ -62,14 +61,6 @@ license:
- MIT
- GPL

backend:
type: str
help: Choose a build backend for your project
choices:
"Setuptools - Standard tooling based around pyproject.toml. (recommended)": setuptools
"Hatchling - As above, but can also interface with hatch. (recommended)": hatch
"Poetry - All-in-one solution to development.": poetry

min_python_version:
type: str
help: What is the minimum version of Python your project will support? (Defaults to minimum supported by NumPy)
Expand Down
8 changes: 4 additions & 4 deletions project_template/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
rev: "v4.6.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -20,7 +20,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.2.0"
rev: "v0.4.9"
hooks:
# first, lint + autofix
- id: ruff
Expand All @@ -30,10 +30,10 @@ repos:
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.8.0"
rev: "v1.10.0"
hooks:
- id: mypy
files: src
args: []
additional_dependencies:
- pytest
- pytest
14 changes: 7 additions & 7 deletions project_template/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ File was automatically generated, please fill me in (or raise an issue on this r
{%- elif coc == "our_coc" -%}
# Code of Conduct

We value the participation of every member of our community and want to ensure
that every contributor has an enjoyable and fulfilling experience. Accordingly,
We value the participation of every member of our community and want to ensure
that every contributor has an enjoyable and fulfilling experience. Accordingly,
everyone who participates in the {{ project_name }} project is expected to show respect and courtesy to other community members at all time.

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers are dedicated to making participation in our project
contributors and maintainers are dedicated to making participation in our project
a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Expand All @@ -36,7 +36,7 @@ Examples of unacceptable behaviour by participants include:
- Other conduct which could reasonably be considered inappropriate in a
professional setting

<!--
<!--
Modify the following sections to the needs of your project.

## Our Responsibilities
Expand All @@ -46,6 +46,6 @@ Modify the following sections to the needs of your project.

## Attribution

This Code of Conduct is adapted from the [Turing Data Stories Code of Conduct](https://github.com/alan-turing-institute/TuringDataStories/blob/main/CODE_OF_CONDUCT.md) which is based on the [scona project Code of Conduct](https://github.com/WhitakerLab/scona/blob/master/CODE_OF_CONDUCT.md)
This Code of Conduct is adapted from the [Turing Data Stories Code of Conduct](https://github.com/alan-turing-institute/TuringDataStories/blob/main/CODE_OF_CONDUCT.md) which is based on the [scona project Code of Conduct](https://github.com/WhitakerLab/scona/blob/master/CODE_OF_CONDUCT.md)
and the [Contributor Covenant](https://www.contributor-covenant.org), version [1.4](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html)
{%- endif -%}
{%- endif %}
7 changes: 0 additions & 7 deletions project_template/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@ description of best practices for developing scientific packages.

You can set up a development environment by running:

{%- if backend == "poetry" %}
```zsh
poetry install
```
{%- else %}

```zsh
python3 -m venv venv # create a virtualenv called venv
source ./venv/bin/activate # now `python` points to the virtualenv python
pip install -v -e ".[dev]" # -v for verbose, -e for editable, [dev] for dev dependencies
```
{%- endif %}

# Post setup

Expand Down
2 changes: 1 addition & 1 deletion project_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ python -m pip install {{ python_name }}

From source:
{% if backend == "poetry" -%}
```bash
```bash
git clone {{ url }}
cd {{ project_name }}
poetry install
Expand Down
Loading