Skip to content

Commit

Permalink
migrate from poetry to hatch
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Nov 7, 2023
1 parent dba0716 commit 9df158c
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 2,423 deletions.
30 changes: 5 additions & 25 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,15 @@
name: Publish package

on:
workflow_dispatch:
workflow_dispatch:
release:
types: [published]

jobs:

test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version: ["3.8", "3.9"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Test with pytest
run: |
poetry run pytest --cov=app --cov-report=term-missing tests
tests:
uses: sunchang0124/dp_cgans/.github/workflows/test.yml@main
secrets: inherit

publish:
needs: test
Expand All @@ -53,8 +34,7 @@ jobs:
run: python -m build

- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

19 changes: 10 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Test package
name: Run tests

on:
workflow_dispatch:
workflow_dispatch:
workflow_call:
push:
paths:
- '**.py'
- '**.cfg'
- '**.lock'
- '**.toml'
- '**.yml'
branches: [ "main" ]
Expand All @@ -23,19 +23,20 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
pip install hatch
- name: Test with pytest
run: |
poetry run pytest --cov=app --cov-report=term-missing tests
hatch run test
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
FROM python:3.9
FROM python:3.10

# This docker image is only used for debugging

WORKDIR /app

RUN apt-get update && apt-get upgrade -y

RUN curl -sSL https://install.python-poetry.org | python -

ENV PATH="${PATH}:/root/.poetry/bin"
RUN apt-get update && \
apt-get upgrade -y && \
pip install --upgrade pip

ADD . .

RUN poetry install
RUN pip install -e .


ENTRYPOINT [ "bash" ]
Expand Down
2 changes: 1 addition & 1 deletion LICENSE → LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Chang Sun
Copyright (c) 2023-present Sun Chang <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
70 changes: 27 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,8 @@ model.sample(100)

## 🧑‍💻 Development setup

<details>
<summary>You will need to <a href="https://python-poetry.org/docs">install Poetry</a></summary><br/>

Be careful as poetry sometime uses a weird python version by default, you can check for the environment used by poetry for the current folder by running:

```bash
poetry env list
```

You can easily tell `poetry` to use your current version of python for this folder by running the following command:

```bash
poetry env use $(which python)
```
</details>

For development, we recommend to install and use [Hatch](https://hatch.pypa.io/latest/), as it will automatically install and sync the dependencies when running development scripts. But you can also directly create a virtual environment and install the library with `pip install -e .`

### Install

Expand All @@ -156,63 +142,61 @@ git clone https://github.com/sunchang0124/dp_cgans
cd dp_cgans
```

Install the dependencies:

```bash
poetry install
```
> When working in development the `hatch` tool will automatically install and sync the dependencies when running a script. But you can also directly
### Run

Run the library with the CLI:

```bash
poetry run dp-cgans gen --help
hatch -v run dp-cgans gen --help
```

Run the tests locally:
You can also enter a new shell with the virtual environments automatically activated:

```bash
poetry run pytest -s
hatch shell
dp-cgans gen --help
```

### Add a new dependency

You can change the `pyproject.toml` file and run:
### Tests

```bash
poetry update
```

Or you can do it directly with the CLI (e.g. for `pandas` here):
Run the tests locally:

```bash
poetry add pandas
hatch run pytest -s
```

### Build and publish

Build:

```bash
poetry build
```
### Reset the virtual environments

Publishing a new release is automatically done by a GitHub Action workflow when a release is created on GitHub:
In case the virtual environments is not updating as expected you can easily reset it with:

```bash
poetry publish
hatch env prune
```

## 📦️ New release process

The deployment of new releases is done automatically by a GitHub Action workflow when a new release is created on GitHub. To release a new version:

1. Make sure the `PYPI_API_TOKEN` secret has been defined in the GitHub repository (in Settings > Secrets > Actions). You can get an API token from PyPI [here](https://pypi.org/manage/account/).
2. Increment the `version` number in the `pyproject.toml` file in the root folder of the repository.

2. Increment the `version` number in `src/dp_cgans/__init__.py` file:

```bash
hatch version fix # Bump from 0.0.1 to 0.0.2
hatch version minor # Bump from 0.0.1 to 0.1.0
hatch version 0.1.1 # Bump to the specified version
```

3. Create a new release on GitHub, which will automatically trigger the publish workflow, and publish the new release to PyPI.

You can also manually trigger the workflow from the Actions tab in your GitHub repository webpage.
You can also manually build and publish from you laptop:

```bash
hatch build
hatch publish
```

## 📚️ References / Further reading

Expand Down
Loading

0 comments on commit 9df158c

Please sign in to comment.