Skip to content

Commit f9cd644

Browse files
authored
Modernize setup and publishing actions (#1506)
* Port modernization changes from pgspecial dbcli/pgspecial#154. * Lowest postgres to test with is 10. * Rename DEVELOP.rst -> CONTRIBUTING.rst. * Coverage action is already included. * uv pip. * Port ruff options from mycli. * Ruff fixes. * Ruff fixes. * Sort the reqs, add keyring.alt. * Remove unnecessary fixture call. * Update dev modules. * All tests steps depend on uv. * Add transaction scenarios to known problems. * Add transaction scenarios to known problems. * Skip yet another scenario. * Fix rst command. * Do not check ruff formatting. * Update changelog. * Comment out pre-commit ruff format hook.
1 parent 9d9a912 commit f9cd644

30 files changed

+676
-1064
lines changed

.coveragerc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
[run]
2-
parallel=True
32
source=pgcli

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
- [ ] I've added this contribution to the `changelog.rst`.
99
- [ ] I've added my name to the `AUTHORS` file (or it's already there).
1010
<!-- We would appreciate if you comply with our code style guidelines. -->
11-
- [ ] I installed pre-commit hooks (`pip install pre-commit && pre-commit install`), and ran `black` on my code.
11+
- [ ] I installed pre-commit hooks (`pip install pre-commit && pre-commit install`).
1212
- [x] Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

.github/workflows/ci.yml

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
services:
2020
postgres:
21-
image: postgres:9.6
21+
image: postgres:10
2222
env:
2323
POSTGRES_USER: postgres
2424
POSTGRES_PASSWORD: postgres
@@ -31,10 +31,14 @@ jobs:
3131
--health-retries 5
3232
3333
steps:
34-
- uses: actions/checkout@v4
34+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
35+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
36+
- uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
37+
with:
38+
version: "latest"
3539

3640
- name: Set up Python ${{ matrix.python-version }}
37-
uses: actions/setup-python@v4
41+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
3842
with:
3943
python-version: ${{ matrix.python-version }}
4044

@@ -68,32 +72,21 @@ jobs:
6872
psql -h localhost -U postgres -p 6432 pgbouncer -c 'show help'
6973
7074
- name: Install requirements
71-
run: |
72-
pip install -U pip setuptools
73-
pip install --no-cache-dir ".[sshtunnel]"
74-
pip install -r requirements-dev.txt
75-
pip install keyrings.alt>=3.1
75+
run: uv sync --all-extras -p ${{ matrix.python-version }}
7676

7777
- name: Run unit tests
78-
run: coverage run --source pgcli -m pytest
78+
run: uv run tox -e py${{ matrix.python-version }}
7979

8080
- name: Run integration tests
8181
env:
8282
PGUSER: postgres
8383
PGPASSWORD: postgres
8484
TERM: xterm
8585

86-
run: behave tests/features --no-capture
86+
run: uv run tox -e integration
8787

8888
- name: Check changelog for ReST compliance
89-
run: docutils --halt=warning changelog.rst >/dev/null
89+
run: uv run tox -e rest
9090

91-
- name: Run Black
92-
run: black --check .
93-
if: matrix.python-version == '3.8'
94-
95-
- name: Coverage
96-
run: |
97-
coverage combine
98-
coverage report
99-
codecov
91+
- name: Run style checks
92+
run: uv run tox -e style

.github/workflows/publish.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Publish Python Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
17+
18+
services:
19+
postgres:
20+
image: postgres:10
21+
env:
22+
POSTGRES_USER: postgres
23+
POSTGRES_PASSWORD: postgres
24+
ports:
25+
- 5432:5432
26+
options: >-
27+
--health-cmd pg_isready
28+
--health-interval 10s
29+
--health-timeout 5s
30+
--health-retries 5
31+
32+
steps:
33+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
35+
- uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
36+
with:
37+
version: "latest"
38+
39+
- name: Set up Python ${{ matrix.python-version }}
40+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
41+
with:
42+
python-version: ${{ matrix.python-version }}
43+
44+
- name: Install dependencies
45+
run: uv sync --all-extras -p ${{ matrix.python-version }}
46+
47+
- name: Run unit tests
48+
env:
49+
LANG: en_US.UTF-8
50+
run: uv run tox -e py${{ matrix.python-version }}
51+
52+
- name: Run Style Checks
53+
run: uv run tox -e style
54+
55+
build:
56+
runs-on: ubuntu-latest
57+
needs: [test]
58+
59+
steps:
60+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
61+
- uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
62+
with:
63+
version: "latest"
64+
65+
- name: Set up Python
66+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
67+
with:
68+
python-version: '3.13'
69+
70+
- name: Install dependencies
71+
run: uv sync --all-extras -p 3.13
72+
73+
- name: Build
74+
run: uv build
75+
76+
- name: Store the distribution packages
77+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
78+
with:
79+
name: python-packages
80+
path: dist/
81+
82+
publish:
83+
name: Publish to PyPI
84+
runs-on: ubuntu-latest
85+
if: startsWith(github.ref, 'refs/tags/')
86+
needs: [build]
87+
environment: release
88+
permissions:
89+
id-token: write
90+
steps:
91+
- name: Download distribution packages
92+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
93+
with:
94+
name: python-packages
95+
path: dist/
96+
- name: Publish to PyPI
97+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ target/
7272
venv/
7373

7474
.ropeproject/
75+
uv.lock
7576

.pre-commit-config.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 23.3.0
4-
hooks:
5-
- id: black
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.11.7
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
args: [ --fix ]
9+
# Run the formatter. TODO: uncomment when the rest of the code is ruff-formatted
10+
# - id: ruff-format

DEVELOP.rst renamed to CONTRIBUTING.rst

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ repo.
2323
$ git remote add upstream [email protected]:dbcli/pgcli.git
2424

2525
Once the 'upstream' end point is added you can then periodically do a ``git
26-
pull upstream master`` to update your local copy and then do a ``git push
27-
origin master`` to keep your own fork up to date.
26+
pull upstream main`` to update your local copy and then do a ``git push
27+
origin main`` to keep your own fork up to date.
2828

2929
Check Github's `Understanding the GitHub flow guide
3030
<https://guides.github.com/introduction/flow/>`_ for a more detailed
@@ -38,30 +38,23 @@ pgcli. If you're developing pgcli, you'll need to install it in a slightly
3838
different way so you can see the effects of your changes right away without
3939
having to go through the install cycle every time you change the code.
4040

41-
It is highly recommended to use virtualenv for development. If you don't know
42-
what a virtualenv is, `this guide <http://docs.python-guide.org/en/latest/dev/virtualenvs/#virtual-environments>`_
43-
will help you get started.
44-
45-
Create a virtualenv (let's call it pgcli-dev). Activate it:
41+
Set up [uv](https://docs.astral.sh/uv/getting-started/installation/) for development:
4642

4743
::
4844

45+
cd pgcli
46+
uv venv
4947
source ./pgcli-dev/bin/activate
5048

51-
or
52-
53-
.\pgcli-dev\scripts\activate (for Windows)
54-
55-
Once the virtualenv is activated, `cd` into the local clone of pgcli folder
56-
and install pgcli using pip as follows:
49+
Once the virtualenv is activated, install pgcli using pip as follows:
5750

5851
::
5952

60-
$ pip install --editable .
53+
$ uv pip install --editable .
6154

6255
or
6356

64-
$ pip install -e .
57+
$ uv pip install -e .
6558

6659
This will install the necessary dependencies as well as install pgcli from the
6760
working folder into the virtualenv. By installing it using `pip install -e`
@@ -165,9 +158,7 @@ in the ``tests`` directory. An example::
165158
First, install the requirements for testing:
166159

167160
::
168-
$ pip install -U pip setuptools
169-
$ pip install --no-cache-dir ".[sshtunnel]"
170-
$ pip install -r requirements-dev.txt
161+
$ uv pip install ".[dev]"
171162

172163
Ensure that the database user has permissions to create and drop test databases
173164
by checking your ``pg_hba.conf`` file. The default user should be ``postgres``
@@ -180,20 +171,14 @@ service for the changes to take effect.
180171
# ONLY IF YOU MADE CHANGES TO YOUR pg_hba.conf FILE
181172
$ sudo service postgresql restart
182173

183-
After that, tests in the ``/pgcli/tests`` directory can be run with:
184-
(Note that these ``behave`` tests do not currently work when developing on Windows due to pexpect incompatibility.)
174+
After that:
185175

186176
::
187177

188-
# on directory /pgcli/tests
178+
$ cd pgcli/tests
189179
$ behave
190180

191-
And on the ``/pgcli`` directory:
192-
193-
::
194-
195-
# on directory /pgcli
196-
$ py.test
181+
Note that these ``behave`` tests do not currently work when developing on Windows due to pexpect incompatibility.
197182

198183
To see stdout/stderr, use the following command:
199184

@@ -209,10 +194,21 @@ Troubleshooting the integration tests
209194
- Check `this issue <https://github.com/dbcli/pgcli/issues/945>`_ for relevant information.
210195
- `File an issue <https://github.com/dbcli/pgcli/issues/new>`_.
211196

197+
Running the unit tests
198+
----------------------
199+
200+
The unit tests can be run with pytest:
201+
202+
::
203+
204+
$ cd pgcli
205+
$ pytest
206+
207+
212208
Coding Style
213209
------------
214210

215-
``pgcli`` uses `black <https://github.com/ambv/black>`_ to format the source code. Make sure to install black.
211+
``pgcli`` uses `ruff <https://github.com/astral-sh/ruff>`_ to format the source code.
216212

217213
Releases
218214
--------

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ If you're interested in contributing to this project, first of all I would like
155155
to extend my heartfelt gratitude. I've written a small doc to describe how to
156156
get this running in a development setup.
157157

158-
https://github.com/dbcli/pgcli/blob/master/DEVELOP.rst
158+
https://github.com/dbcli/pgcli/blob/main/CONTRIBUTING.rst
159159

160160
Please feel free to reach out to us if you need help.
161161
* Amjith, pgcli author: [email protected], Twitter: `@amjithr <http://twitter.com/amjithr>`_
@@ -362,12 +362,12 @@ Thanks to all the beta testers and contributors for your time and patience. :)
362362
.. |Build Status| image:: https://github.com/dbcli/pgcli/actions/workflows/ci.yml/badge.svg?branch=main
363363
:target: https://github.com/dbcli/pgcli/actions/workflows/ci.yml
364364

365-
.. |CodeCov| image:: https://codecov.io/gh/dbcli/pgcli/branch/master/graph/badge.svg
365+
.. |CodeCov| image:: https://codecov.io/gh/dbcli/pgcli/branch/main/graph/badge.svg
366366
:target: https://codecov.io/gh/dbcli/pgcli
367367
:alt: Code coverage report
368368

369-
.. |Landscape| image:: https://landscape.io/github/dbcli/pgcli/master/landscape.svg?style=flat
370-
:target: https://landscape.io/github/dbcli/pgcli/master
369+
.. |Landscape| image:: https://landscape.io/github/dbcli/pgcli/main/landscape.svg?style=flat
370+
:target: https://landscape.io/github/dbcli/pgcli/main
371371
:alt: Code Health
372372

373373
.. |PyPI| image:: https://img.shields.io/pypi/v/pgcli.svg

RELEASES.md

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
Releasing pgcli
22
---------------
33

4-
You have been made the maintainer of `pgcli`? Congratulations! We have a release script to help you:
4+
You have been made the maintainer of `pgcli`? Congratulations!
55

6-
```sh
7-
> python release.py --help
8-
Usage: release.py [options]
9-
10-
Options:
11-
-h, --help show this help message and exit
12-
-c, --confirm-steps Confirm every step. If the step is not confirmed, it
13-
will be skipped.
14-
-d, --dry-run Print out, but not actually run any steps.
15-
```
16-
17-
The script can be run with `-c` to confirm or skip steps. There's also a `--dry-run` option that only prints out the steps.
18-
19-
To release a new version of the package:
20-
21-
* Create and merge a PR to bump the version in the changelog ([example PR](https://github.com/dbcli/pgcli/pull/1325)).
22-
* Pull `main` and bump the version number inside `pgcli/__init__.py`. Do not check in - the release script will do that.
23-
* Make sure you have the dev requirements installed: `pip install -r requirements-dev.txt -U --upgrade-strategy only-if-needed`.
24-
* Finally, run the release script: `python release.py`.
6+
To release a new version of the package, [create a new release](https://github.com/dbcli/pgcli/releases) in Github. This will trigger a Github action which will run all the tests, build the wheel and upload it to PyPI.

changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ Features:
88
* Provide `init-command` in the config file
99
* Support dsn specific init-command in the config file
1010

11+
Internal:
12+
---------
13+
14+
* Moderize the repository
15+
* Use uv instead of pip
16+
* Use github trusted publisher for pypi release
17+
* Update dev requirements and replace requirements-dev.txt with pyproject.toml
18+
* Use ruff instead of black
19+
1120
4.3.0 (2025-03-22)
1221
==================
1322

0 commit comments

Comments
 (0)