Skip to content

Commit 4f58159

Browse files
authored
Merge branch 'master' into render_column_type
2 parents ac1bdb0 + e34718c commit 4f58159

17 files changed

+817
-3703
lines changed

.github/workflows/publish.yml

+22-4
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,50 @@ on:
1010

1111
jobs:
1212
build:
13+
name: Build the source tarball and the wheel
1314
runs-on: ubuntu-latest
1415
environment: release
1516
steps:
16-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1718
- name: Set up Python
18-
uses: actions/setup-python@v4
19+
uses: actions/setup-python@v5
1920
with:
2021
python-version: 3.x
2122
- name: Install dependencies
2223
run: pip install build
2324
- name: Create packages
2425
run: python -m build
2526
- name: Archive packages
26-
uses: actions/upload-artifact@v3
27+
uses: actions/upload-artifact@v4
2728
with:
2829
name: dist
2930
path: dist
3031

3132
publish:
33+
name: Publish build artifacts to the PyPI
3234
needs: build
3335
runs-on: ubuntu-latest
3436
environment: release
3537
permissions:
3638
id-token: write
3739
steps:
3840
- name: Retrieve packages
39-
uses: actions/download-artifact@v3
41+
uses: actions/download-artifact@v4
4042
- name: Upload packages
4143
uses: pypa/gh-action-pypi-publish@release/v1
44+
45+
release:
46+
name: Create a GitHub release
47+
needs: build
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: write
51+
steps:
52+
- uses: actions/checkout@v4
53+
- id: changelog
54+
uses: agronholm/release-notes@v1
55+
with:
56+
path: CHANGES.rst
57+
- uses: ncipollo/release-action@v1
58+
with:
59+
body: ${{ steps.changelog.outputs.changelog }}

.github/workflows/test.yml

+12-23
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,32 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
14-
sqlalchemy-version: ["1.4", "2.0"]
13+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1514
runs-on: ubuntu-latest
1615
steps:
17-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1817
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v4
18+
uses: actions/setup-python@v5
2019
with:
2120
python-version: ${{ matrix.python-version }}
2221
allow-prereleases: true
2322
cache: pip
2423
cache-dependency-path: pyproject.toml
25-
- name: Install dependencies SQLAlchemy 1.4
26-
if: matrix.sqlalchemy-version == 1.4
27-
run: pip install -e .[test,sqlmodel] coveralls SQLAlchemy==1.4.*
28-
- name: Install dependencies SQLAlchemy 2.0
29-
if: matrix.sqlalchemy-version == 2.0
30-
run: pip install -e .[test] coveralls SQLAlchemy==2.0.*
24+
- name: Install dependencies
25+
run: pip install -e .[test]
3126
- name: Test with pytest
3227
run: coverage run -m pytest
3328
- name: Upload Coverage
34-
run: coveralls --service=github
35-
env:
36-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
COVERALLS_FLAG_NAME: ${{ matrix.test-name }}
38-
COVERALLS_PARALLEL: true
39-
SQLALCHEMY_WARN_20: "true"
29+
uses: coverallsapp/github-action@v2
30+
with:
31+
parallel: true
4032

4133
coveralls:
4234
name: Finish Coveralls
43-
needs: [test]
35+
needs: test
4436
runs-on: ubuntu-latest
45-
container: python:3-slim
4637
steps:
4738
- name: Finished
48-
run: |
49-
pip install coveralls
50-
coveralls --service=github --finish
51-
env:
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
uses: coverallsapp/github-action@v2
40+
with:
41+
parallel-finished: true

.pre-commit-config.yaml

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# * Run "pre-commit install".
66
repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v4.4.0
8+
rev: v5.0.0
99
hooks:
1010
- id: check-toml
1111
- id: check-yaml
@@ -16,18 +16,14 @@ repos:
1616
- id: trailing-whitespace
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.0.290
19+
rev: v0.9.2
2020
hooks:
2121
- id: ruff
2222
args: [--fix, --show-fixes]
23-
24-
- repo: https://github.com/psf/black
25-
rev: 23.9.1
26-
hooks:
27-
- id: black
23+
- id: ruff-format
2824

2925
- repo: https://github.com/pre-commit/mirrors-mypy
30-
rev: v1.5.1
26+
rev: v1.14.1
3127
hooks:
3228
- id: mypy
3329
additional_dependencies:

CHANGES.rst

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
Version history
22
===============
33

4+
**UNRELEASED**
5+
6+
- Dropped support for Python 3.8
7+
8+
**3.0.0rc5**
9+
10+
- Fixed pgvector support not working
11+
12+
**3.0.0rc4**
13+
14+
- Dropped support for Python 3.7
15+
- Dropped support for SQLAlchemy 1.x
16+
- Added support for the ``pgvector`` extension (with help from KellyRousselHoomano)
17+
418
**3.0.0rc3**
519

620
- Added support for SQLAlchemy 2 (PR by rbuffat with help from mhauru)

README.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ latest SQLAlchemy version).
1818
Features
1919
========
2020

21-
* Supports SQLAlchemy 1.4.x and 2
21+
* Supports SQLAlchemy 2.x
2222
* Produces declarative code that almost looks like it was hand written
2323
* Produces `PEP 8`_ compliant code
2424
* Accurately determines relationships, including many-to-many, one-to-one
@@ -45,6 +45,11 @@ To include support for the PostgreSQL ``GEOMETRY``, ``GEOGRAPHY``, and ``RASTER`
4545
(which should be considered as tested only under a few environments) specify the
4646
``geoalchemy2`` extra:
4747

48+
To include support for the PostgreSQL ``PGVECTOR`` extension type, specify the
49+
``pgvector`` extra::
50+
51+
pip install sqlacodegen[pgvector]
52+
4853
.. code-block:: bash
4954
5055
pip install sqlacodegen[geoalchemy2]
@@ -110,7 +115,7 @@ values must be delimited by commas, e.g. ``--options noconstraints,nobidi``):
110115

111116
* all the options from ``declarative``
112117

113-
* ``sqlmodel``
118+
* ``sqlmodels``
114119

115120
* all the options from ``declarative``
116121

pyproject.toml

+20-24
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ classifiers = [
2121
"Topic :: Software Development :: Code Generators",
2222
"Programming Language :: Python",
2323
"Programming Language :: Python :: 3",
24-
"Programming Language :: Python :: 3.7",
25-
"Programming Language :: Python :: 3.8",
2624
"Programming Language :: Python :: 3.9",
2725
"Programming Language :: Python :: 3.10",
2826
"Programming Language :: Python :: 3.11",
27+
"Programming Language :: Python :: 3.12",
28+
"Programming Language :: Python :: 3.13",
2929
]
30-
requires-python = ">=3.7"
30+
requires-python = ">=3.9"
3131
dependencies = [
32-
"SQLAlchemy >= 1.4.36",
32+
"SQLAlchemy >= 2.0.23",
3333
"inflect >= 4.0.0",
3434
"importlib_metadata; python_version < '3.10'",
35-
"greenlet >= 3.0.0a1; python_version >= '3.12'",
3635
]
3736
dynamic = ["version"]
3837

@@ -42,16 +41,16 @@ dynamic = ["version"]
4241

4342
[project.optional-dependencies]
4443
test = [
45-
"pytest",
46-
"pytest-cov",
44+
"sqlacodegen[sqlmodel]",
45+
"pytest >= 7.4",
46+
"coverage >= 7",
4747
"psycopg2-binary",
4848
"mysql-connector-python",
4949
]
50-
sqlmodel = [
51-
"sqlmodel",
52-
]
50+
sqlmodel = ["sqlmodel >= 0.0.22"]
5351
citext = ["sqlalchemy-citext >= 1.7.0"]
5452
geoalchemy2 = ["geoalchemy2 >= 0.11.1"]
53+
pgvector = ["pgvector >= 0.2.4"]
5554

5655
[project.entry-points."sqlacodegen.generators"]
5756
tables = "sqlacodegen.generators:TablesGenerator"
@@ -67,22 +66,24 @@ version_scheme = "post-release"
6766
local_scheme = "dirty-tag"
6867

6968
[tool.ruff]
70-
select = [
71-
"E", "F", "W", # default Flake8
69+
src = ["src"]
70+
71+
[tool.ruff.lint]
72+
extend-select = [
7273
"I", # isort
7374
"ISC", # flake8-implicit-str-concat
7475
"PGH", # pygrep-hooks
7576
"RUF100", # unused noqa (yesqa)
7677
"UP", # pyupgrade
78+
"W", # pycodestyle warnings
7779
]
7880
src = ["src"]
7981

8082
[tool.mypy]
8183
strict = true
82-
plugins = ["sqlalchemy.ext.mypy.plugin"]
8384

8485
[tool.pytest.ini_options]
85-
addopts = "-rsx --tb=short"
86+
addopts = "-rsfE --tb=short"
8687
testpaths = ["tests"]
8788

8889
[coverage.run]
@@ -93,15 +94,10 @@ relative_files = true
9394
show_missing = true
9495

9596
[tool.tox]
96-
legacy_tox_ini = """
97-
[tox]
98-
envlist = py37, py38, py39, py310, py311, py312
97+
env_list = ["py39", "py310", "py311", "py312", "py313"]
9998
skip_missing_interpreters = true
100-
isolated_build = true
10199

102-
[testenv]
103-
extras = test
104-
setenv =
105-
SQLALCHEMY_WARN_20 = true
106-
commands = python -m pytest {posargs}
107-
"""
100+
[tool.tox.env_run_base]
101+
package = "editable"
102+
commands = [["python", "-m", "pytest", { replace = "posargs", extend = true }]]
103+
extras = ["test"]

src/sqlacodegen/cli.py

+28-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
except ImportError:
1919
geoalchemy2 = None
2020

21+
try:
22+
import pgvector.sqlalchemy
23+
except ImportError:
24+
pgvector = None
25+
2126
if sys.version_info < (3, 10):
2227
from importlib_metadata import entry_points, version
2328
else:
@@ -48,37 +53,55 @@ def main() -> None:
4853
parser.add_argument(
4954
"--tables", help="tables to process (comma-delimited, default: all)"
5055
)
51-
parser.add_argument("--noviews", action="store_true", help="ignore views")
56+
parser.add_argument(
57+
"--noviews",
58+
action="store_true",
59+
help="ignore views (always true for sqlmodels generator)",
60+
)
5261
parser.add_argument("--outfile", help="file to write output to (default: stdout)")
5362
args = parser.parse_args()
5463

5564
if args.version:
5665
print(version("sqlacodegen"))
5766
return
67+
5868
if not args.url:
5969
print("You must supply a url\n", file=sys.stderr)
6070
parser.print_help()
6171
return
6272

6373
if citext:
64-
print(f"Using sqlalchemy-citext {citext.__version__}")
74+
print(f"Using sqlalchemy-citext {version('citext')}")
6575

6676
if geoalchemy2:
67-
print(f"Using geoalchemy2 {geoalchemy2.__version__}")
77+
print(f"Using geoalchemy2 {version('geoalchemy2')}")
78+
79+
if pgvector:
80+
print(f"Using pgvector {version('pgvector')}")
6881

6982
# Use reflection to fill in the metadata
7083
engine = create_engine(args.url)
7184
metadata = MetaData()
7285
tables = args.tables.split(",") if args.tables else None
7386
schemas = args.schemas.split(",") if args.schemas else [None]
7487
options = set(args.options.split(",")) if args.options else set()
75-
for schema in schemas:
76-
metadata.reflect(engine, schema, not args.noviews, tables)
7788

7889
# Instantiate the generator
7990
generator_class = generators[args.generator].load()
8091
generator = generator_class(metadata, engine, options)
8192

93+
if not generator.views_supported:
94+
name = generator_class.__name__
95+
print(
96+
f"VIEW models will not be generated when using the '{name}' generator",
97+
file=sys.stderr,
98+
)
99+
100+
for schema in schemas:
101+
metadata.reflect(
102+
engine, schema, (generator.views_supported and not args.noviews), tables
103+
)
104+
82105
# Open the target file (if given)
83106
with ExitStack() as stack:
84107
outfile: TextIO

0 commit comments

Comments
 (0)