Skip to content

Commit ddd3836

Browse files
Copilotjason810496
andauthored
Replace Poetry with uv for build and dependency management (#14)
* fix: check vt is None instead of vt or self.vt * release: v0.1.2 * fix: install dev deps in GitHub Action, remove version in docker-compose * Fix vt naming for set_vt * Initial plan * Replace poetry with uv across the project Co-authored-by: jason810496 <[email protected]> * Update documentation badges from poetry to uv Co-authored-by: jason810496 <[email protected]> * Address code review feedback: use uv sync in Dockerfile and relax pytest version Co-authored-by: jason810496 <[email protected]> * Add upper bound to pytest version constraint for better compatibility Co-authored-by: jason810496 <[email protected]> * Fix publish workflow to use correct uv sync command Co-authored-by: jason810496 <[email protected]> --------- Co-authored-by: LIU ZHE YOU <[email protected]> Co-authored-by: jason810496 <[email protected]> Co-authored-by: LIU ZHE YOU <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent 01dbe32 commit ddd3836

12 files changed

Lines changed: 2087 additions & 1701 deletions

File tree

.github/workflows/codecov.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,20 @@ jobs:
2323
uses: actions/setup-python@v5
2424
with:
2525
python-version: ${{ matrix.python-version }}
26-
# Install dependencies
27-
- name: Install dependencies
28-
run: |
29-
pip install poetry
30-
- name: Set poetry python version
26+
# Install uv
27+
- name: Install uv
3128
run: |
32-
poetry env use python${{ matrix.python-version }}
29+
curl -LsSf https://astral.sh/uv/install.sh | sh
30+
echo "$HOME/.local/bin" >> $GITHUB_PATH
3331
- name: Install dependencies
34-
run: poetry install --without=dev
32+
run: uv sync --extra dev
3533
- name: Start PostgreSQL
3634
run: |
3735
cp pgmq_postgres.template.env pgmq_postgres.env
3836
cp pgmq_tests.template.env pgmq_tests.env
3937
make start-db
4038
- name: Run tests and collect coverage
41-
run: poetry run pytest tests --cov=pgmq_sqlalchemy.queue --cov-report=xml -n auto tests
39+
run: uv run pytest tests --cov=pgmq_sqlalchemy.queue --cov-report=xml -n auto tests
4240
continue-on-error: true
4341
- name: Upload coverage reports to Codecov with GitHub Action
4442
uses: codecov/[email protected]

.github/workflows/publish.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,16 @@ jobs:
2626
with:
2727
python-version: "3.10"
2828

29-
- name: Install Poetry
29+
- name: Install uv
3030
run: |
31-
curl -sSL https://install.python-poetry.org | python - -y
32-
33-
- name: Update PATH
34-
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
35-
36-
- name: Update Poetry configuration
37-
run: poetry config virtualenvs.create false
31+
curl -LsSf https://astral.sh/uv/install.sh | sh
32+
echo "$HOME/.local/bin" >> $GITHUB_PATH
3833
3934
- name: Install dependencies
40-
run: poetry install --sync --no-interaction --without=dev
35+
run: uv sync
4136

4237
- name: Package project
43-
run: poetry build
38+
run: uv build
4439

4540
- name: Publish package distributions to PyPI
4641
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,8 @@ ipython_config.py
9494
# install all needed dependencies.
9595
#Pipfile.lock
9696

97-
# poetry
98-
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99-
# This is especially recommended for binary packages to ensure reproducibility, and is more
100-
# commonly ignored for libraries.
101-
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102-
#poetry.lock
97+
# poetry - replaced by uv
98+
poetry.lock
10399

104100
# pdm
105101
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.

Dockerfile

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,41 @@ ENV PYTHONUNBUFFERED=1 \
88
PIP_DISABLE_PIP_VERSION_CHECK=on \
99
PIP_DEFAULT_TIMEOUT=100 \
1010
\
11-
# poetry
12-
# https://python-poetry.org/docs/configuration/#using-environment-variables
13-
POETRY_VERSION=1.3.2 \
14-
# make poetry install to this location
15-
POETRY_HOME="/opt/poetry" \
16-
# make poetry create the virtual environment in the project's root
17-
# it gets named `.venv`
18-
POETRY_VIRTUALENVS_IN_PROJECT=true \
19-
# do not ask any interactive question
20-
POETRY_NO_INTERACTION=1 \
21-
\
2211
# paths
2312
# this is where our requirements + virtual environment will live
2413
PYSETUP_PATH="/opt/pysetup" \
2514
VENV_PATH="/opt/pysetup/.venv"
2615

2716

28-
# prepend poetry and venv to path
29-
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
17+
# prepend venv to path
18+
ENV PATH="$VENV_PATH/bin:$PATH"
3019

3120
FROM python-base as builder-base
3221
RUN apt-get update \
3322
&& apt-get install --no-install-recommends -y \
34-
# deps for installing poetry
23+
# deps for installing uv
3524
curl \
3625
# deps for building python deps
3726
build-essential
3827

39-
# install poetry - respects $POETRY_VERSION & $POETRY_HOME
40-
# The --mount will mount the buildx cache directory to where
41-
# Poetry and Pip store their cache so that they can re-use it
28+
# install uv
4229
RUN --mount=type=cache,target=/root/.cache \
43-
curl -sSL https://install.python-poetry.org | python3 -
30+
curl -LsSf https://astral.sh/uv/install.sh | sh
31+
32+
ENV PATH="/root/.local/bin:$PATH"
4433

4534
# copy project requirement files here to ensure they will be cached.
4635
WORKDIR $PYSETUP_PATH
47-
COPY poetry.lock pyproject.toml ./
36+
COPY pyproject.toml uv.lock ./
4837

49-
# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
38+
# install runtime deps
5039
RUN --mount=type=cache,target=/root/.cache \
51-
poetry install --with=dev
40+
uv sync --extra dev
5241

5342
FROM python:3.12-slim-bookworm as runtime
5443

55-
ENV POETRY_HOME="/opt/poetry" \
56-
VENV_PATH="/opt/pysetup/.venv"
57-
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
44+
ENV VENV_PATH="/opt/pysetup/.venv"
45+
ENV PATH="$VENV_PATH/bin:$PATH"
5846

5947
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
6048
COPY ./pgmq_sqlalchemy /pgmq_sqlalchemy_test/pgmq_sqlalchemy

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
install: ## Install dependencies and `ruff` pre-commit hooks
44
pre-commit install
5-
poetry install --with dev
5+
uv sync --extra dev
66

77
build: ## Build the package
8-
poetry build
8+
uv build
99

1010
test-local: ## Run tests locally
11-
poetry run pytest tests --cov=pgmq_sqlalchemy.queue
11+
uv run pytest tests --cov=pgmq_sqlalchemy.queue
1212

1313

1414
test-docker-rebuild: ## Rebuild the docker image
@@ -38,10 +38,10 @@ exec-db: ## Enter the database container
3838
docker compose exec pgmq_postgres psql -U postgres -d postgres
3939

4040
doc-build: ## Build the documentation
41-
cd doc && poetry run sphinx-build -nW . _build
41+
cd doc && uv run sphinx-build -nW . _build
4242

4343
doc-serve: doc-clean ## Serve the documentation
44-
cd doc && poetry run sphinx-autobuild -nW . _build
44+
cd doc && uv run sphinx-autobuild -nW . _build
4545

4646
doc-clean: ## Clean the documentation
4747
cd doc && rm -r _build

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
1+
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
22
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
33
![PyPI - Version](https://img.shields.io/pypi/v/pgmq-sqlalchemy)
44
[![PyPI - License](https://img.shields.io/pypi/l/pgmq-sqlalchemy.svg)](https://github.com/jason810496/pgmq-sqlalchemy/blob/main/LICENSE)

doc/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.. _index:
22

33

4-
.. image:: https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json
5-
:target: https://python-poetry.org/
6-
:alt: Poetry
4+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json
5+
:target: https://github.com/astral-sh/uv
6+
:alt: uv
77
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
88
:target: https://github.com/astral-sh/ruff
99
:alt: Ruff

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.8'
21
services:
32
pgmq_postgres:
43
container_name: pgmq_postgres

pgmq_sqlalchemy/queue.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -814,14 +814,12 @@ def read_with_poll(
814814
queue_name, vt, qty, max_poll_seconds, poll_interval_ms
815815
)
816816

817-
def _set_vt_sync(
818-
self, queue_name: str, msg_id: int, vt_offset: int
819-
) -> Optional[Message]:
817+
def _set_vt_sync(self, queue_name: str, msg_id: int, vt: int) -> Optional[Message]:
820818
"""Set the visibility timeout for a message."""
821819
with self.session_maker() as session:
822820
row = session.execute(
823-
text("select * from pgmq.set_vt(:queue_name,:msg_id,:vt_offset);"),
824-
{"queue_name": queue_name, "msg_id": msg_id, "vt_offset": vt_offset},
821+
text("select * from pgmq.set_vt(:queue_name,:msg_id,:vt);"),
822+
{"queue_name": queue_name, "msg_id": msg_id, "vt": vt},
825823
).fetchone()
826824
session.commit()
827825
if row is None:
@@ -831,17 +829,17 @@ def _set_vt_sync(
831829
)
832830

833831
async def _set_vt_async(
834-
self, queue_name: str, msg_id: int, vt_offset: int
832+
self, queue_name: str, msg_id: int, vt: int
835833
) -> Optional[Message]:
836834
"""Set the visibility timeout for a message."""
837835
async with self.session_maker() as session:
838836
row = (
839837
await session.execute(
840-
text("select * from pgmq.set_vt(:queue_name,:msg_id,:vt_offset);"),
838+
text("select * from pgmq.set_vt(:queue_name,:msg_id,:vt);"),
841839
{
842840
"queue_name": queue_name,
843841
"msg_id": msg_id,
844-
"vt_offset": vt_offset,
842+
"vt": vt,
845843
},
846844
)
847845
).fetchone()
@@ -853,7 +851,7 @@ async def _set_vt_async(
853851
msg_id=row[0], read_ct=row[1], enqueued_at=row[2], vt=row[3], message=row[4]
854852
)
855853

856-
def set_vt(self, queue_name: str, msg_id: int, vt_offset: int) -> Optional[Message]:
854+
def set_vt(self, queue_name: str, msg_id: int, vt: int) -> Optional[Message]:
857855
"""
858856
.. _set_vt_method: ref:`pgmq_sqlalchemy.PGMQueue.set_vt`
859857
.. |set_vt_method| replace:: :py:meth:`~pgmq_sqlalchemy.PGMQueue.set_vt`
@@ -863,7 +861,7 @@ def set_vt(self, queue_name: str, msg_id: int, vt_offset: int) -> Optional[Messa
863861
Args:
864862
queue_name (str): The name of the queue.
865863
msg_id (int): The message id.
866-
vt_offset (int): The visibility timeout in seconds.
864+
vt (int): The visibility timeout in seconds.
867865
868866
Returns:
869867
|schema_message_class|_ or ``None`` if the message does not exist.
@@ -906,15 +904,15 @@ def consumer_with_backoff_retry(pgmq_client: PGMQueue, queue_name: str):
906904
pgmq_client.set_vt(
907905
queue_name=query_name,
908906
msg_id=msg.msg_id,
909-
vt_offset=_exp_backoff_retry(msg)
907+
vt=_exp_backoff_retry(msg)
910908
)
911909
912910
"""
913911
if self.is_async:
914912
return self.loop.run_until_complete(
915-
self._set_vt_async(queue_name, msg_id, vt_offset)
913+
self._set_vt_async(queue_name, msg_id, vt)
916914
)
917-
return self._set_vt_sync(queue_name, msg_id, vt_offset)
915+
return self._set_vt_sync(queue_name, msg_id, vt)
918916

919917
def _pop_sync(self, queue_name: str) -> Optional[Message]:
920918
with self.session_maker() as session:

0 commit comments

Comments
 (0)