Skip to content

Commit

Permalink
Migrate from setup.py to Poetry pyproject.toml for packaging and …
Browse files Browse the repository at this point in the history
…environment management (#57)

* add poetry pyproject.toml and lock

* remove setup.py

* update pre-commit to include poetry check

* updates for pyproject file; docs; pre-commit updt

* add dave bunten to maintainers

* update license

* Update pyproject.toml

Co-authored-by: Faisal Alquaddoomi <[email protected]>

* Update CONTRIBUTING.md

Co-authored-by: Faisal Alquaddoomi <[email protected]>

* Update poetry.lock

---------

Co-authored-by: Faisal Alquaddoomi <[email protected]>
  • Loading branch information
d33bs and falquaddoomi authored Dec 11, 2024
1 parent 46ffbc6 commit ac0a6c1
Show file tree
Hide file tree
Showing 6 changed files with 1,129 additions and 45 deletions.
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
20 changes: 16 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,22 @@ 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).
While the `OPENAI_API_KEY` environment variable must be set to a value for the testing suite to complete, any non-whitespace value will do. It doesn't have to be a valid API key, since all tests that actually query the API with the key are skipped by default.

If you want to run tests that query the actual OpenAI API, you must specify a valid API key for `OPENAI_API_KEY` . You can then execute pytest with the `--runcost` option, e.g. `poetry run pytest --runcost`, which will then use the specified key to run tests that query the API. Note that this will cost you money, typically around a cent or two per execution, depending on your choice of model. You can find detailed information about cost for each model per 1M tokens on the [OpenAI API Pricing Page](https://openai.com/api/pricing/) -- our test suite uses `gpt-3.5-turbo`. The tests also take significantly longer than the non-live test suite to complete, so it's recommended to leave them disabled them unless you know you need to test the live API.
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

0 comments on commit ac0a6c1

Please sign in to comment.