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

Migrate from setup.py to Poetry pyproject.toml for packaging and environment management #57

Merged
merged 10 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
10 changes: 6 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
- name: Setup python env
- name: Setup poetry
run: |
pip install pytest
pip install .
pip install poetry
- name: Install poetry env
run: |
poetry install
- name: Run pytest
env:
# set a placeholder OpenAI key (required by tests)
OPENAI_API_KEY: ABCD1234
run: python -m pytest
run: poetry run pytest
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ repos:
hooks:
- id: black
language_version: python3
- repo: https://github.com/python-poetry/poetry
rev: "1.8.3"
hooks:
- id: poetry-check
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "v2.5.0"
hooks:
- id: pyproject-fmt
- repo: https://github.com/rhysd/actionlint
rev: v1.7.3
hooks:
- id: actionlint
18 changes: 14 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This project is governed by our [code of conduct](CODE_OF_CONDUCT.md). By partic

## Development

This project leverages development environments managed by a Python [`setup.py` file.](https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#setup-py)
This project leverages development environments managed by a Python [Poetry `pyproject.toml` file](https://python-poetry.org/docs/).
We use [pytest](https://docs.pytest.org/) for testing and [GitHub Actions](https://docs.github.com/en/actions) for automated tests.
[`pre-commit`](https://pre-commit.com/) is used to help lint or format code.
A [Conda environment](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) is provided (via the file `environment.yml`) for convenience but is not required for development purposes.
Expand All @@ -22,8 +22,8 @@ A [Conda environment](https://conda.io/projects/conda/en/latest/user-guide/tasks
Perform the following steps to setup a Python development environment.

1. [Install Python](https://www.python.org/downloads/) (we recommend using [`pyenv`](https://github.com/pyenv/pyenv) or similar)
1. Install package, e.g. `pip install .` (from the root directory, referencing the `setup.py`)
1. Install pytest: `pip install pytest`
1. [Install Poetry](https://python-poetry.org/docs/#installation).
1. Install package, e.g. `poetry install`

### Linting

Expand All @@ -45,10 +45,20 @@ Work added to this project is automatically tested using [pytest](https://docs.p
Pytest is installed through the Poetry environment for this project.
We recommend testing your work before opening pull requests with proposed changes.

Some tests require a special environment key to be set: `OPENAI_API_KEY`.
This key is an openai.com API key tied to an account.
See here to [make an OpenAI account](https://openai.com/api/) and [create an API key](https://platform.openai.com/api-keys).
Any key may be used if you want to perform tests without an openai.com account or key (tests which require it will then be skipped).
d33bs marked this conversation as resolved.
Show resolved Hide resolved
You can set this key as follows:

```bash
export OPENAI_API_KEY=ABCD1234
```

You can run pytest on your work using the following example:

```sh
% python -m pytest
% poetry run pytest
```

## Making changes to this repository
Expand Down
Loading