Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into double-pluralizat…
Browse files Browse the repository at this point in the history
…ion-of-names
  • Loading branch information
dkratzert committed Nov 29, 2024
2 parents d2725f2 + eb7b95f commit 5229e1b
Show file tree
Hide file tree
Showing 14 changed files with 3,290 additions and 249 deletions.
40 changes: 36 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,51 @@ on:
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"

jobs:
publish:
build:
name: Build the source tarball and the wheel
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
run: pip install build
- name: Create packages
run: python -m build
- name: Archive packages
uses: actions/upload-artifact@v3
with:
name: dist
path: dist

publish:
name: Publish build artifacts to the PyPI
needs: build
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- name: Retrieve packages
uses: actions/download-artifact@v3
- name: Upload packages
uses: pypa/gh-action-pypi-publish@release/v1

release:
name: Create a GitHub release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- id: changelog
uses: agronholm/release-notes@v1
with:
path: CHANGES.rst
- uses: ncipollo/release-action@v1
with:
password: ${{ secrets.pypi_password }}
body: ${{ steps.changelog.outputs.changelog }}
29 changes: 12 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,32 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.9", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: pip
cache-dependency-path: pyproject.toml
- name: Install dependencies
run: pip install -e .[test] coveralls
run: pip install -e .[test]
- name: Test with pytest
run: coverage run -m pytest
- name: Upload Coverage
run: coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: ${{ matrix.test-name }}
COVERALLS_PARALLEL: true
SQLALCHEMY_WARN_20: "true"
uses: coverallsapp/github-action@v2
with:
parallel: true

coveralls:
name: Finish Coveralls
needs: [test]
needs: test
runs-on: ubuntu-latest
container: python:3-slim
steps:
- name: Finished
run: |
pip install coveralls
coveralls --service=github --finish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
37 changes: 10 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# * Run "pre-commit install".
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-toml
- id: check-yaml
Expand All @@ -15,29 +15,15 @@ repos:
args: [ "--fix=lf" ]
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.4
hooks:
- id: pyupgrade
args: [ "--py37-plus" ]

- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/csachs/pyproject-flake8
rev: v6.0.0.post1
hooks:
- id: pyproject-flake8
- id: ruff
args: [--fix, --show-fixes]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
rev: v1.11.0
hooks:
- id: mypy
additional_dependencies:
Expand All @@ -47,9 +33,6 @@ repos:
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-no-eval
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
16 changes: 16 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
Version history
===============

**3.0.0rc5**

- Fixed pgvector support not working

**3.0.0rc4**

- Dropped support for Python 3.7
- Dropped support for SQLAlchemy 1.x
- Added support for the ``pgvector`` extension (with help from KellyRousselHoomano)

**3.0.0rc3**

- Added support for SQLAlchemy 2 (PR by rbuffat with help from mhauru)
- Renamed ``--option`` to ``--options`` and made its values delimited by commas
- Restored CIText and GeoAlchemy2 support (PR by stavvy-rotte)

**3.0.0rc2**

- Added support for generating SQLModel classes (PR by Andrii Khirilov)
Expand Down
20 changes: 17 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ latest SQLAlchemy version).
Features
========

* Supports SQLAlchemy 1.4.x
* Supports SQLAlchemy 2.x
* Produces declarative code that almost looks like it was hand written
* Produces `PEP 8`_ compliant code
* Accurately determines relationships, including many-to-many, one-to-one
Expand All @@ -41,6 +41,20 @@ considered as tested only under a few environments) specify the ``citext`` extra
pip install sqlacodegen[citext]


To include support for the PostgreSQL ``GEOMETRY``, ``GEOGRAPHY``, and ``RASTER`` types
(which should be considered as tested only under a few environments) specify the
``geoalchemy2`` extra:

To include support for the PostgreSQL ``PGVECTOR`` extension type, specify the
``pgvector`` extra::

pip install sqlacodegen[pgvector]

.. code-block:: bash
pip install sqlacodegen[geoalchemy2]
Quickstart
==========

Expand Down Expand Up @@ -78,8 +92,8 @@ The following built-in generators are available:
Generator-specific options
==========================

The following options can be turned on by passing them using ``--option`` (can be used
multiple times):
The following options can be turned on by passing them using ``--options`` (multiple
values must be delimited by commas, e.g. ``--options noconstraints,nobidi``):

* ``tables``

Expand Down
40 changes: 21 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ classifiers = [
"Topic :: Software Development :: Code Generators",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
requires-python = ">=3.7"
requires-python = ">=3.8"
dependencies = [
"SQLAlchemy >= 1.4.36, < 2.0",
"SQLAlchemy >= 2.0.23",
"inflect >= 4.0.0",
"importlib_metadata; python_version < '3.10'",
]
Expand All @@ -40,13 +41,15 @@ dynamic = ["version"]

[project.optional-dependencies]
test = [
"pytest",
"pytest-cov",
"pytest >= 7.4",
"coverage >= 7",
"psycopg2-binary",
"mysql-connector-python",
"sqlmodel",
]
sqlmodel = ["sqlmodel >= 0.0.12"]
citext = ["sqlalchemy-citext >= 1.7.0"]
geoalchemy2 = ["geoalchemy2 >= 0.11.1"]
pgvector = ["pgvector >= 0.2.4"]

[project.entry-points."sqlacodegen.generators"]
tables = "sqlacodegen.generators:TablesGenerator"
Expand All @@ -61,18 +64,19 @@ sqlacodegen = "sqlacodegen.cli:main"
version_scheme = "post-release"
local_scheme = "dirty-tag"

[tool.isort]
src_paths = ["src"]
skip_gitignore = true
profile = "black"

[tool.flake8]
max-line-length = 88
[tool.ruff]
select = [
"E", "F", "W", # default Flake8
"I", # isort
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"RUF100", # unused noqa (yesqa)
"UP", # pyupgrade
]
src = ["src"]

[tool.mypy]
python_version = "3.7"
strict = true
plugins = ["sqlalchemy.ext.mypy.plugin"]

[tool.pytest.ini_options]
addopts = "-rsx --tb=short"
Expand All @@ -88,13 +92,11 @@ show_missing = true
[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py37, py38, py39, py310
envlist = py38, py39, py310, py311, py312
skip_missing_interpreters = true
isolated_build = true
minversion = 4.0.0
[testenv]
extras = test
setenv =
SQLALCHEMY_WARN_20 = true
commands = python -m pytest {posargs}
"""
34 changes: 30 additions & 4 deletions src/sqlacodegen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
from sqlalchemy.engine import create_engine
from sqlalchemy.schema import MetaData

try:
import citext
except ImportError:
citext = None

try:
import geoalchemy2
except ImportError:
geoalchemy2 = None

try:
import pgvector.sqlalchemy
except ImportError:
pgvector = None

if sys.version_info < (3, 10):
from importlib_metadata import entry_points, version
else:
Expand All @@ -21,13 +36,13 @@ def main() -> None:
)
parser.add_argument("url", nargs="?", help="SQLAlchemy url to the database")
parser.add_argument(
"--option", nargs="*", help="options passed to the generator class"
"--options", help="options (comma-delimited) passed to the generator class"
)
parser.add_argument(
"--version", action="store_true", help="print the version number and exit"
)
parser.add_argument(
"--schemas", help="load tables from the given schemas (comma separated)"
"--schemas", help="load tables from the given schemas (comma-delimited)"
)
parser.add_argument(
"--generator",
Expand All @@ -36,7 +51,7 @@ def main() -> None:
help="generator class to use",
)
parser.add_argument(
"--tables", help="tables to process (comma-separated, default: all)"
"--tables", help="tables to process (comma-delimited, default: all)"
)
parser.add_argument("--noviews", action="store_true", help="ignore views")
parser.add_argument("--outfile", help="file to write output to (default: stdout)")
Expand All @@ -45,22 +60,33 @@ def main() -> None:
if args.version:
print(version("sqlacodegen"))
return

if not args.url:
print("You must supply a url\n", file=sys.stderr)
parser.print_help()
return

if citext:
print(f"Using sqlalchemy-citext {version('citext')}")

if geoalchemy2:
print(f"Using geoalchemy2 {version('geoalchemy2')}")

if pgvector:
print(f"Using pgvector {version('pgvector')}")

# Use reflection to fill in the metadata
engine = create_engine(args.url)
metadata = MetaData()
tables = args.tables.split(",") if args.tables else None
schemas = args.schemas.split(",") if args.schemas else [None]
options = set(args.options.split(",")) if args.options else set()
for schema in schemas:
metadata.reflect(engine, schema, not args.noviews, tables)

# Instantiate the generator
generator_class = generators[args.generator].load()
generator = generator_class(metadata, engine, set(args.option or ()))
generator = generator_class(metadata, engine, options)

# Open the target file (if given)
with ExitStack() as stack:
Expand Down
Loading

0 comments on commit 5229e1b

Please sign in to comment.