Skip to content

Commit d7e6f5c

Browse files
committed
Port modernization changes from pgspecial dbcli/pgspecial#154.
1 parent 9d9a912 commit d7e6f5c

File tree

9 files changed

+196
-109
lines changed

9 files changed

+196
-109
lines changed

.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: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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,29 +72,24 @@ 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'
91+
- name: Run style checks
92+
run: uv run tox -e style
9493

9594
- name: Coverage
9695
run: |

.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

.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.
10+
- id: ruff-format

DEVELOP.rst

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ repo.
2323
$ git remote add upstream git@github.com: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,8 @@ in the ``tests`` directory. An example::
165158
First, install the requirements for testing:
166159

167160
::
168-
$ pip install -U pip setuptools
169161
$ pip install --no-cache-dir ".[sshtunnel]"
170-
$ pip install -r requirements-dev.txt
162+
$ pip install --no-cache-dir ".[dev]"
171163

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

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.)
175+
After that:
185176

186177
::
187178

188-
# on directory /pgcli/tests
179+
$ cd pgcli/tests
189180
$ behave
190181

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

198184
To see stdout/stderr, use the following command:
199185

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

198+
Running the unit tests
199+
----------------------
200+
201+
The unit tests can be run with pytest:
202+
203+
::
204+
205+
$ cd pgcli
206+
$ pytest
207+
208+
212209
Coding Style
213210
------------
214211

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

217214
Releases
218215
--------

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.

pyproject.toml

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,26 @@ pgcli = "pgcli.main:cli"
5151
[project.optional-dependencies]
5252
keyring = ["keyring >= 12.2.0"]
5353
sshtunnel = ["sshtunnel >= 0.4.0"]
54+
dev = [
55+
"pytest>=2.7.0",
56+
"tox>=1.9.2",
57+
"behave>=1.2.4",
58+
"pexpect==3.3; platform_system != 'Windows'",
59+
"pre-commit>=1.16.0",
60+
"coverage>=5.0.4",
61+
"codecov>=1.5.1",
62+
"docutils>=0.13.1",
63+
"ruff>=0.11.7",
64+
"sshtunnel>=0.4.0",
65+
"build<0.10.0",
66+
]
5467

5568
[build-system]
56-
requires = ["setuptools>=61.2"]
69+
requires = ["setuptools>=64.0", "setuptools-scm>=8"]
5770
build-backend = "setuptools.build_meta"
5871

72+
[tool.setuptools_scm]
73+
5974
[tool.setuptools]
6075
include-package-data = false
6176

@@ -68,24 +83,15 @@ find = { namespaces = false }
6883
[tool.setuptools.package-data]
6984
pgcli = ["pgclirc", "packages/pgliterals/pgliterals.json"]
7085

71-
[tool.black]
72-
line-length = 88
73-
target-version = ['py38']
74-
include = '\.pyi?$'
75-
exclude = '''
76-
/(
77-
\.eggs
78-
| \.git
79-
| \.hg
80-
| \.mypy_cache
81-
| \.tox
82-
| \.venv
83-
| \.cache
84-
| \.pytest_cache
85-
| _build
86-
| buck-out
87-
| build
88-
| dist
89-
| tests/data
90-
)/
91-
'''
86+
[tool.ruff]
87+
target-version = 'py39'
88+
line-length = 140
89+
90+
[tool.ruff.lint.isort]
91+
force-sort-within-sections = true
92+
known-first-party = ['pgcli', 'tests']
93+
94+
[tool.pytest.ini_options]
95+
minversion = "6.0"
96+
addopts = "--capture=sys --showlocals -rxs"
97+
testpaths = ["tests"]

requirements-dev.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)