Skip to content

Commit

Permalink
ci: move to PDM (#2357)
Browse files Browse the repository at this point in the history
* infra: move to ``PDM``

* fix(ci): resolve bad version arg

* ci: run pre-commit

* ci: fix version var

* fix: update lockfile

* fix(ci): lock latest, update ci, simplify install command

* fix(ci): apply version arg to fix regression

* fix(ci): apply version arg to fix regression

* fix(ci): apply pre-commit

* Update Makefile

Co-authored-by: Cody Fincher <[email protected]>

* Update pyproject.toml

Co-authored-by: Cody Fincher <[email protected]>

* Update pyproject.toml

Co-authored-by: Cody Fincher <[email protected]>

* chore: test cli and remove comments

* ci: do not use prereleases

* fix: typo

---------

Co-authored-by: Cody Fincher <[email protected]>
  • Loading branch information
JacobCoffee and cofin authored Oct 7, 2023
1 parent 13e6977 commit a35d392
Show file tree
Hide file tree
Showing 12 changed files with 1,761 additions and 2,683 deletions.
26 changes: 10 additions & 16 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,25 @@ jobs:
with:
python-version: "3.11"

- name: Install Poetry
uses: snok/install-poetry@v1
- uses: pdm-project/setup-pdm@v3
name: Set up PDM
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
python-version: "3.11"
allow-python-prereleases: false
cache: true
cache-dependency-path: |
./pdm.lock
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: v1-venv-docs-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install --no-interaction --with docs --extras full
run: pdm install -G:docs

- name: Build docs
env:
LITESTAR_DOCS_IGNORE_MISSING_EXAMPLE_OUTPUT: 1
run: poetry run make docs
run: pdm run make docs

- name: Check docs links
env:
LITESTAR_DOCS_IGNORE_MISSING_EXAMPLE_OUTPUT: 1
run: poetry run make docs-linkcheck
run: pdm run make docs-linkcheck

- name: Save PR number
env:
Expand Down
35 changes: 20 additions & 15 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
name: Documentation Building

on:
release:
types: [published]
push:
branches:
- main

jobs:
docs:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Poetry
uses: snok/install-poetry@v1

- uses: pdm-project/setup-pdm@v3
name: Set up PDM
with:
virtualenvs-create: false
installer-parallel: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ hashFiles('**/poetry.lock') }}
- name: Install App Dependencies
run: poetry install --no-interaction --with docs --extras full
python-version: "3.11"
allowpython-prereleases: false
cache: true
cache-dependency-path: |
./pdm.lock
- name: Install dependencies
run: pdm install -G:docs

- name: Fetch gh pages
run: git fetch origin gh-pages --depth=1

- name: Build release docs
run: poetry run python tools/build_docs.py docs-build
run: pdm run python tools/build_docs.py docs-build
if: github.event_name == 'release'

- name: Build dev docs
run: poetry run python tools/build_docs.py docs-build --version dev
run: pdm run python tools/build_docs.py docs-build --version dev
if: github.event_name == 'push'

- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
Expand Down
43 changes: 21 additions & 22 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,47 @@ jobs:
with:
python-version: "3.11"

- name: Install Poetry
uses: snok/install-poetry@v1
- uses: pdm-project/setup-pdm@v3
name: Set up PDM
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
python-version: ${{ matrix.python-version }}
allow-python-prereleases: false
cache: true
cache-dependency-path: |
./pdm.lock
- name: Install App Dependencies
run: poetry install --no-interaction --only main

- name: Install Test Dependencies
run: poetry run python -m pip install pytest pytest-asyncio httpx trio time-machine
- name: Install dependencies
run: pdm install

- name: Set pythonpath
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV

- name: Test
run: mv tests/examples/test_hello_world.py test_hello_world.py && poetry run pytest test_hello_world.py
run: mv tests/examples/test_hello_world.py test_hello_world.py && pdm run pytest test_hello_world.py

publish-release:
name: upload release to PyPI
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
environment: release
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up python 3.11
uses: actions/setup-python@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Install dependencies
run: poetry install --no-interaction --no-root --no-dev
- uses: pdm-project/setup-pdm@v3
name: Set up PDM
with:
python-version: "3.11"
allow-python-prereleases: false
cache: true

- name: build
shell: bash
run: poetry build
- name: Build package
run: pdm build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
54 changes: 27 additions & 27 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,46 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
if: runner.os != 'Windows'
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: v1-venv-${{ runner.os }}-${{ inputs.python-version }}-${{ inputs.pydantic-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Load cached pip wheels
if: runner.os == 'Windows'
id: cached-pip-wheels
uses: actions/cache@v3

- uses: pdm-project/setup-pdm@v3
name: Set up PDM
with:
path: ~/.cache
key: cache-${{ runner.os }}-${{ inputs.python-version }}-${{ inputs.pydantic-version }}-${{ hashFiles('**/poetry.lock') }}
python-version: ${{ inputs.python-version }}
allow-python-prereleases: false
cache: true
cache-dependency-path: |
./pdm.lock
- name: Install dependencies
run: poetry install --no-interaction --extras full
run: pdm install

- if: ${{ inputs.pydantic-version == '1' }}
name: Install pydantic v1
run: poetry remove pydantic-extra-types && poetry add "pydantic>=1.10.11,<2" piccolo
name: Prepare for pydantic v1
run: pdm add --no-sync "pydantic>=1.10.11,<2" "piccolo"

- if: ${{ inputs.pydantic-version == '2' }}
name: Install pydantic v2
run: poetry add "pydantic>=2.3.0" "pydantic-extra-types>=2.0.0"
- name: Set pythonpath
name: Prepare for pydantic v2
run: pdm add --no-sync "pydantic>=2.3.0" "pydantic-extra-types>=2.0.0"

- name: Sync dependencies
run: pdm sync

- name: Set PYTHONPATH
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV

- name: Test
if: ${{ !inputs.coverage }}
run: poetry run pytest docs/examples tests -n auto
run: pdm run pytest docs/examples tests -n auto

- name: Test with coverage
if: inputs.coverage
run: poetry run pytest docs/examples tests --cov=litestar --cov-report=xml -n auto
run: pdm run pytest docs/examples tests --cov=litestar --cov-report=xml -n auto

- uses: actions/upload-artifact@v3
if: inputs.coverage
with:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ target/
/docs/_build/
coverage.*
setup.py

# pdm
.pdm.toml
.pdm-python
.pdm-build/
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/python-poetry/poetry
rev: "1.6.0"
- repo: https://github.com/pdm-project/pdm
rev: 2.9.2
hooks:
- id: poetry-check
- id: pdm-lock-check
- repo: https://github.com/provinzkraut/unasyncd
rev: "v0.6.1"
hooks:
Expand Down
35 changes: 20 additions & 15 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ Contribution guide
Setting up the environment
--------------------------

1. Install `poetry <https://python-poetry.org/>`_.
2. Run ``poetry install --extras full`` to create a `virtual environment <https://docs.python.org/3/tutorial/venv.html>`_
and install the dependencies.
3. If you're working on the documentation and need to build it locally, install the extra dependencies with
``poetry install --with docs --extras full``.
4. Install `pre-commit <https://pre-commit.com/>`_.
5. Run ``pre-commit install && pre-commit install --hook-type commit-msg`` to install pre-commit hooks.
.. tip:: We maintain a Makefile with several commands to help with common tasks.
You can run ``make help`` to see a list of available commands.

.. tip::
Many modern IDEs like PyCharm or VS Code will enable the poetry-managed virtualenv that is created in step 2 for you automatically.
If your IDE / editor does not offer this functionality, then you will need to manually activate the virtualenv yourself. Otherwise you may encounter errors or unexpected behaviour when trying to run the commands referenced within this document.
1. Install `Personal Doomsday Machine <https://pdm.fming.dev/latest/>`_
2. Run ``pdm install`` or ``make install`` to create a
`virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ and install the required development dependencies
3. If you're working on the documentation and need to build it locally, install the extra dependencies
with ``pdm install -G:docs`` or ``make docs-install``
4. Install `pre-commit <https://pre-commit.com/>`_
5. Run ``pre-commit install --install-hooks`` or ``make install`` to install pre-commit hooks

The easiest way to activate this virtualenv manually is by running ``poetry shell``, as described at `Using your virtual environment <https://python-poetry.org/docs/basic-usage/#using-your-virtual-environment>`_ in poetry's documentation.
.. tip:: Many modern IDEs like PyCharm or VS Code will enable the PDM-managed virtualenv that is created in step 2 for you automatically.
If your IDE / editor does not offer this functionality, then you will need to manually activate the virtualenv yourself. Otherwise you may encounter errors or unexpected behaviour when trying to run the commands referenced within this document.

The rest of this document will assume this environment is active wherever commands are referenced.
The easiest way to activate this virtualenv manually is by running ``pdm shell``, as described at
`Working with virtual environments <https://pdm.fming.dev/latest/usage/venv/#working-with-virtual-environments>`_
in PDM's documentation.

The rest of this document will assume this environment is active wherever commands are referenced.

Code contributions
------------------
Expand Down Expand Up @@ -109,7 +113,7 @@ Running the docs locally

To run or build the docs locally, you need to first install the required dependencies:

``poetry install --with docs --extras full``
``pdm install -G:docs``

Then you can serve the documentation with ``make docs-serve``, or build them with ``make docs``

Expand Down Expand Up @@ -215,8 +219,9 @@ This is equivalent to:
Creating a new release
----------------------

1. Increment the version in ``pyproject.toml`` according to the
`versioning scheme <https://litestar.dev/about/litestar-releases#version-numbering>`_
1. Increment the version in ``pyproject.toml`` according to the `versioning scheme <https://litestar.dev/about/litestar-releases#version-numbering>`_
.. note:: The version should follow `semantic versioning <https://semver.org/>`_ and `PEP 440 <https://www.python.org/dev/peps/pep-0440/>`_.
2. Commit and push.
2. `Draft a new release <https://github.com/litestar-org/litestar/releases/new>`_ on GitHub

* Use ``vMAJOR.MINOR.PATCH`` (e.g. ``v1.2.3``) as both the tag and release title
Expand Down
Loading

0 comments on commit a35d392

Please sign in to comment.