Skip to content

Commit 19cc0ac

Browse files
committed
Wrapped some documents at 88 columns
1 parent c5b1c3a commit 19cc0ac

File tree

3 files changed

+92
-77
lines changed

3 files changed

+92
-77
lines changed

CHANGES.rst

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Version history
44
**UNRELEASED**
55

66
- Migrated all packaging/testing configuration to ``pyproject.toml``
7-
- Fixed unwarranted ``ForeignKey`` declarations appearing in column attributes when there are
8-
named, single column foreign key constraints (PR by Leonardus Chen)
7+
- Fixed unwarranted ``ForeignKey`` declarations appearing in column attributes when
8+
there are named, single column foreign key constraints (PR by Leonardus Chen)
99
. Fixed ``KeyError`` when rendering an index without any columns
1010
- Fixed improper handling of schema prefixes in sequence names in server defaults
1111
- Fixed identically named tables from different schemas resulting in invalid generated
@@ -18,28 +18,29 @@ Version history
1818
- Dropped support for SQLAlchemy 1.3
1919
- Added a ``__main__`` module which can be used as an alternate entry point to the CLI
2020
- Added detection for sequence use in column defaults on PostgreSQL
21-
- Fixed ``sqlalchemy.exc.InvalidRequestError`` when encountering a column named "metadata"
22-
(regression from 2.0)
23-
- Fixed missing ``MetaData`` import with ``DeclarativeGenerator`` when only plain tables are
24-
generated
25-
- Fixed invalid data classes being generated due to some relationships having been rendered without
26-
a default value
27-
- Improved translation of column names into column attributes where the column name has whitespace
28-
at the beginning or end
29-
- Modified constraint and index rendering to add them explicitly instead of using shortcuts like
30-
``unique=True``, ``index=True`` or ``primary=True`` when the constraint or index has a name that
31-
does not match the default naming convention
21+
- Fixed ``sqlalchemy.exc.InvalidRequestError`` when encountering a column named
22+
"metadata" (regression from 2.0)
23+
- Fixed missing ``MetaData`` import with ``DeclarativeGenerator`` when only plain tables
24+
are generated
25+
- Fixed invalid data classes being generated due to some relationships having been
26+
rendered without a default value
27+
- Improved translation of column names into column attributes where the column name has
28+
whitespace at the beginning or end
29+
- Modified constraint and index rendering to add them explicitly instead of using
30+
shortcuts like ``unique=True``, ``index=True`` or ``primary=True`` when the constraint
31+
or index has a name that does not match the default naming convention
3232

3333
**3.0.0b2**
3434

35-
- Fixed ``IDENTITY`` columns not rendering properly when they are part of the primary key
35+
- Fixed ``IDENTITY`` columns not rendering properly when they are part of the primary
36+
key
3637

3738
**3.0.0b1**
3839

39-
**NOTE**: Both the API and the command line interface have been refactored in a backwards
40-
incompatible fashion. Notably several command line options have been moved to specific generators
41-
and are no longer visible from ``sqlacodegen --help``. Their replacement are documented in the
42-
README.
40+
**NOTE**: Both the API and the command line interface have been refactored in a
41+
backwards incompatible fashion. Notably several command line options have been moved to
42+
specific generators and are no longer visible from ``sqlacodegen --help``. Their
43+
replacement are documented in the README.
4344

4445
- Dropped support for Python < 3.6
4546
- Added support for Python 3.10
@@ -49,14 +50,15 @@ README.
4950
- Added support for ``IDENTITY`` columns
5051
- Disabled inflection during table/relationship name generation by default
5152
(use ``--option use_inflect`` to re-enable)
52-
- Refactored the old ``CodeGenerator`` class into separate generator classes, selectable via
53-
``--generator``
53+
- Refactored the old ``CodeGenerator`` class into separate generator classes, selectable
54+
via ``--generator``
5455
- Refactored several command line options into generator specific options:
5556

5657
- ``--noindexes`` → ``--option noindexes``
5758
- ``--noconstraints`` → ``--option noconstraints``
5859
- ``--nocomments`` → ``--option nocomments``
59-
- ``--nojoined`` → ``--option nojoined`` (``declarative`` and ``dataclass`` generators only)
60+
- ``--nojoined`` → ``--option nojoined`` (``declarative`` and ``dataclass`` generators
61+
only)
6062
- ``--noinflect`` → (now the default; use ``--option use_inflect`` instead)
6163
(``declarative`` and ``dataclass`` generators only)
6264
- Fixed missing import for ``JSONB`` ``astext_type`` argument
@@ -101,7 +103,8 @@ README.
101103
- Fixed attribute name of columns named ``metadata`` in mapped classes (fixes #62)
102104
- Fixed rendered column types being changed from the original (fixes #11)
103105
- Fixed server defaults which contain double quotes (fixes #7, #17, #28, #33, #36)
104-
- Fixed ``secondary=`` not taking into account the association table's schema name (fixes #30)
106+
- Fixed ``secondary=`` not taking into account the association table's schema name
107+
(fixes #30)
105108
- Sort models by foreign key dependencies instead of schema and name (fixes #15, #16)
106109

107110
**1.1.6**
@@ -111,7 +114,8 @@ README.
111114

112115
**1.1.5**
113116

114-
- Fixed potential assignment of columns or relationships into invalid attribute names (fixes #10)
117+
- Fixed potential assignment of columns or relationships into invalid attribute names
118+
(fixes #10)
115119
- Fixed unique=True missing from unique Index declarations
116120
- Fixed several issues with server defaults
117121
- Fixed potential assignment of columns or relationships into invalid attribute names
@@ -136,7 +140,8 @@ README.
136140

137141
**1.1.1**
138142

139-
- Fixed TypeError when inflect could not determine the singular name of a table for a many-to-1 relationship
143+
- Fixed TypeError when inflect could not determine the singular name of a table for a
144+
many-to-1 relationship
140145
- Fixed _IntegerType, _StringType etc. being rendered instead of proper types on MySQL
141146

142147
**1.1.0**

CONTRIBUTING.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
Contributing to sqlacodegen
22
===========================
33

4-
If you wish to contribute a fix or feature to sqlacodegen, please follow the following guidelines.
4+
If you wish to contribute a fix or feature to sqlacodegen, please follow the following
5+
guidelines.
56

6-
When you make a pull request against the main sqlacodegen codebase, Github runs the sqlacodegen
7-
test suite against your modified code. Before making a pull request, you should ensure that the
8-
modified code passes tests locally. To that end, the use of tox_ is recommended. The default tox
9-
run first runs ``pre-commit`` and then the actual test suite. To run the checks on all environments
10-
in parallel, invoke tox with ``tox -p``.
7+
When you make a pull request against the main sqlacodegen codebase, Github runs the
8+
sqlacodegen test suite against your modified code. Before making a pull request, you
9+
should ensure that the modified code passes tests locally. To that end, the use of tox_
10+
is recommended. The default tox run first runs ``pre-commit`` and then the actual test
11+
suite. To run the checks on all environments in parallel, invoke tox with ``tox -p``.
1112

12-
To build the documentation, run ``tox -e docs`` which will generate a directory named ``build``
13-
in which you may view the formatted HTML documentation.
13+
To build the documentation, run ``tox -e docs`` which will generate a directory named
14+
``build`` in which you may view the formatted HTML documentation.
1415

15-
sqlacodegen uses pre-commit_ to perform several code style/quality checks. It is recommended to
16-
activate pre-commit_ on your local clone of the repository (using ``pre-commit install``) to ensure
17-
that your changes will pass the same checks on GitHub.
16+
sqlacodegen uses pre-commit_ to perform several code style/quality checks. It is
17+
recommended to activate pre-commit_ on your local clone of the repository (using
18+
``pre-commit install``) to ensure that your changes will pass the same checks on GitHub.
1819

1920
.. _tox: https://tox.readthedocs.io/en/latest/install.html
2021
.. _pre-commit: https://pre-commit.com/#installation
@@ -31,7 +32,8 @@ To get your changes merged to the main codebase, you need a Github account.
3132
#. Create a branch for your pull request, like ``git checkout -b myfixname``
3233
#. Make the desired changes to the code base.
3334
#. Commit your changes locally. If your changes close an existing issue, add the text
34-
``Fixes #XXX.`` or ``Closes #XXX.`` to the commit message (where XXX is the issue number).
35+
``Fixes #XXX.`` or ``Closes #XXX.`` to the commit message (where XXX is the issue
36+
number).
3537
#. Push the changeset(s) to your forked repository (``git push``)
3638
#. Navigate to Pull requests page on the original repository (not your fork) and click
3739
"New pull request"

README.rst

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
:target: https://coveralls.io/github/agronholm/sqlacodegen?branch=master
66
:alt: Code Coverage
77

8-
This is a tool that reads the structure of an existing database and generates the appropriate
9-
SQLAlchemy model code, using the declarative style if possible.
8+
This is a tool that reads the structure of an existing database and generates the
9+
appropriate SQLAlchemy model code, using the declarative style if possible.
1010

11-
This tool was written as a replacement for `sqlautocode`_, which was suffering from several issues
12-
(including, but not limited to, incompatibility with Python 3 and the latest SQLAlchemy version).
11+
This tool was written as a replacement for `sqlautocode`_, which was suffering from
12+
several issues (including, but not limited to, incompatibility with Python 3 and the
13+
latest SQLAlchemy version).
1314

1415
.. _sqlautocode: http://code.google.com/p/sqlautocode/
1516

@@ -34,18 +35,18 @@ To install, do::
3435

3536
pip install sqlacodegen
3637

37-
To include support for the PostgreSQL ``CITEXT`` extension type (which should be considered as
38-
tested only under a few environments) specify the ``citext`` extra::
38+
To include support for the PostgreSQL ``CITEXT`` extension type (which should be
39+
considered as tested only under a few environments) specify the ``citext`` extra::
3940

4041
pip install sqlacodegen[citext]
4142

4243

4344
Quickstart
4445
==========
4546

46-
At the minimum, you have to give sqlacodegen a database URL. The URL is passed directly to
47-
SQLAlchemy's `create_engine()`_ method so please refer to `SQLAlchemy's documentation`_ for
48-
instructions on how to construct a proper URL.
47+
At the minimum, you have to give sqlacodegen a database URL. The URL is passed directly
48+
to SQLAlchemy's `create_engine()`_ method so please refer to
49+
`SQLAlchemy's documentation`_ for instructions on how to construct a proper URL.
4950

5051
Examples::
5152

@@ -74,8 +75,8 @@ The following built-in generators are available:
7475
Generator-specific options
7576
==========================
7677

77-
The following options can be turned on by passing them using ``--option`` (can be used multiple
78-
times):
78+
The following options can be turned on by passing them using ``--option`` (can be used
79+
multiple times):
7980

8081
* ``tables``
8182

@@ -89,8 +90,9 @@ times):
8990
* ``use_inflect``: use the ``inflect`` library when naming classes and relationships
9091
(turning plural names into singular; see below for details)
9192
* ``nojoined``: don't try to detect joined-class inheritance (see below for details)
92-
* ``nobidi``: generate relationships in a unidirectional fashion, so only the many-to-one
93-
or first side of many-to-many relationships gets a relationship attribute, as on v2.X
93+
* ``nobidi``: generate relationships in a unidirectional fashion, so only the
94+
many-to-one or first side of many-to-many relationships gets a relationship
95+
attribute, as on v2.X
9496

9597
* ``dataclasses``
9698

@@ -99,35 +101,40 @@ times):
99101
Model class generators
100102
----------------------
101103

102-
The code generators that generate classes try to generate model classes whenever possible.
103-
There are two circumstances in which a ``Table`` is generated instead:
104+
The code generators that generate classes try to generate model classes whenever
105+
possible. There are two circumstances in which a ``Table`` is generated instead:
104106

105-
* the table has no primary key constraint (which is required by SQLAlchemy for every model class)
106-
* the table is an association table between two other tables (see below for the specifics)
107+
* the table has no primary key constraint (which is required by SQLAlchemy for every
108+
model class)
109+
* the table is an association table between two other tables (see below for the
110+
specifics)
107111

108112
Model class naming logic
109113
++++++++++++++++++++++++
110114

111-
By default, table names are converted to valid PEP 8 compliant class names by replacing all
112-
characters unsuitable for Python identifiers with ``_``. Then, each valid parts (separated by
113-
underscores) are title cased and then joined together, eliminating the underscores. So,
114-
``example_name`` becomes ``ExampleName``.
115+
By default, table names are converted to valid PEP 8 compliant class names by replacing
116+
all characters unsuitable for Python identifiers with ``_``. Then, each valid parts
117+
(separated by underscores) are title cased and then joined together, eliminating the
118+
underscores. So, ``example_name`` becomes ``ExampleName``.
115119

116-
If the ``use_inflect`` option is used, the table name (which is assumed to be in English) is
117-
converted to singular form using the "inflect" library. For example, ``sales_invoices`` becomes
118-
``SalesInvoice``. Since table names are not always in English, and the inflection process is far
119-
from perfect, inflection is disabled by default.
120+
If the ``use_inflect`` option is used, the table name (which is assumed to be in
121+
English) is converted to singular form using the "inflect" library. For example,
122+
``sales_invoices`` becomes ``SalesInvoice``. Since table names are not always in
123+
English, and the inflection process is far from perfect, inflection is disabled by
124+
default.
120125

121126
Relationship detection logic
122127
++++++++++++++++++++++++++++
123128

124129
Relationships are detected based on existing foreign key constraints as follows:
125130

126131
* **many-to-one**: a foreign key constraint exists on the table
127-
* **one-to-one**: same as **many-to-one**, but a unique constraint exists on the column(s) involved
132+
* **one-to-one**: same as **many-to-one**, but a unique constraint exists on the
133+
column(s) involved
128134
* **many-to-many**: an association table is found to exist between two tables
129135

130-
A table is considered an association table if it satisfies all of the following conditions:
136+
A table is considered an association table if it satisfies all of the following
137+
conditions:
131138

132139
#. has exactly two foreign key constraints
133140
#. all its columns are involved in said constraints
@@ -136,26 +143,27 @@ Relationship naming logic
136143
+++++++++++++++++++++++++
137144

138145
Relationships are typically named based on the table name of the opposite class.
139-
For example, if a class has a relationship to another class with the table named ``companies``, the
140-
relationship would be named ``companies`` (unless the ``use_inflect`` option was enabled, in which
141-
case it would be named ``company`` in the case of a many-to-one or one-to-one relationship).
146+
For example, if a class has a relationship to another class with the table named
147+
``companies``, the relationship would be named ``companies`` (unless the ``use_inflect``
148+
option was enabled, in which case it would be named ``company`` in the case of a
149+
many-to-one or one-to-one relationship).
142150

143-
A special case for single column many-to-one and one-to-one relationships, however, is if the
144-
column is named like ``employer_id``. Then the relationship is named ``employer`` due to that
145-
``_id`` suffix.
151+
A special case for single column many-to-one and one-to-one relationships, however, is
152+
if the column is named like ``employer_id``. Then the relationship is named ``employer``
153+
due to that ``_id`` suffix.
146154

147-
For self referential relationships, the reverse side of the relationship will be named with the
148-
``_reverse`` suffix appended to it.
155+
For self referential relationships, the reverse side of the relationship will be named
156+
with the ``_reverse`` suffix appended to it.
149157

150158
Customizing code generation logic
151159
=================================
152160

153-
If the built-in generators with all their options don't quite do what you want, you can customize
154-
the logic by subclassing one of the existing code generator classes. Override whichever methods
155-
you need, and then add an `entry point`_ in the ``sqlacodegen.generators`` namespace that points
156-
to your new class. Once the entry point is in place (you typically have to install the project with
157-
``pip install``), you can use ``--generator <yourentrypoint>`` to invoke your custom code
158-
generator.
161+
If the built-in generators with all their options don't quite do what you want, you can
162+
customize the logic by subclassing one of the existing code generator classes. Override
163+
whichever methods you need, and then add an `entry point`_ in the
164+
``sqlacodegen.generators`` namespace that points to your new class. Once the entry point
165+
is in place (you typically have to install the project with ``pip install``), you can
166+
use ``--generator <yourentrypoint>`` to invoke your custom code generator.
159167

160168
For examples, you can look at sqlacodegen's own entry points in its `setup.cfg`_.
161169

0 commit comments

Comments
 (0)