Skip to content

Commit b435cae

Browse files
committed
format quickstart, fix minor example inconsistency
clean up intersphinx mapping use current year in docs use setup.cfg to tag dev builds
1 parent bbf0389 commit b435cae

File tree

4 files changed

+51
-49
lines changed

4 files changed

+51
-49
lines changed

docs/conf.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
# All configuration values have a default; values that are commented out
1212
# serve to show the default.
1313

14-
import sys, os
14+
import os
15+
import sys
16+
from datetime import datetime
17+
import pkg_resources
1518

1619
# If extensions (or modules to document with autodoc) are in another directory,
1720
# add these directories to sys.path here. If the directory is relative to the
1821
# documentation root, use os.path.abspath to make it absolute, like shown here.
19-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
22+
2023
sys.path.append(os.path.abspath('_themes'))
2124

2225
# -- General configuration -----------------------------------------------------
@@ -42,24 +45,23 @@
4245

4346
# General information about the project.
4447
project = u'Flask-SQLAlchemy'
45-
copyright = u'2010-2014, Armin Ronacher'
48+
copyright = u'2010 - {}, Armin Ronacher'.format(datetime.utcnow().year)
4649

4750
# The version info for the project you're documenting, acts as replacement for
4851
# |version| and |release|, also used in various other places throughout the
4952
# built documents.
50-
import pkg_resources
5153
try:
5254
release = pkg_resources.get_distribution('Flask-SQLAlchemy').version
5355
except pkg_resources.DistributionNotFound:
54-
print('To build the documentation, The distribution information of')
56+
print('To build the documentation, the distribution information of')
5557
print('Flask-SQLAlchemy has to be available. Either install the package')
5658
print('into your development environment or run "setup.py develop"')
5759
print('to setup the metadata. A virtualenv is recommended!')
5860
sys.exit(1)
59-
del pkg_resources
6061

6162
if 'dev' in release:
62-
release = release.split('dev')[0] + 'dev'
63+
release = ''.join(release.partition('dev')[:2])
64+
6365
version = '.'.join(release.split('.')[:2])
6466

6567
# The language for content autogenerated by Sphinx. Refer to documentation
@@ -104,7 +106,7 @@
104106
# further. For a list of options available for each theme, see the
105107
# documentation.
106108
html_theme_options = {
107-
'index_logo': 'flask-sqlalchemy.png'
109+
'index_logo': 'flask-sqlalchemy.png'
108110
}
109111

110112
# Add any paths that contain custom themes here, relative to this directory.
@@ -141,9 +143,8 @@
141143

142144
# Custom sidebar templates, maps document names to template names.
143145
html_sidebars = {
144-
'index': ['sidebarintro.html', 'sourcelink.html', 'searchbox.html'],
145-
'**': ['sidebarlogo.html', 'localtoc.html', 'relations.html',
146-
'sourcelink.html', 'searchbox.html']
146+
'index': ['sidebarintro.html', 'sourcelink.html', 'searchbox.html'],
147+
'**': ['sidebarlogo.html', 'localtoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']
147148
}
148149

149150
# Additional templates that should be rendered to pages, maps page names to
@@ -224,9 +225,11 @@
224225

225226

226227
# Example configuration for intersphinx: refer to the Python standard library.
227-
intersphinx_mapping = {'http://docs.python.org/': None,
228-
'http://flask.pocoo.org/docs/': None,
229-
'http://www.sqlalchemy.org/docs/': None}
228+
intersphinx_mapping = {
229+
'python': ('https://docs.python.org/3/', None),
230+
'flask': ('http://flask.pocoo.org/docs/', None),
231+
'sqlalchemy': ('http://docs.sqlalchemy.org/en/latest/', None)
232+
}
230233
pygments_style = 'flask_theme_support.FlaskyStyle'
231234

232235
# fall back if theme is not there

docs/quickstart.rst

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ then create the :class:`SQLAlchemy` object by passing it the application.
1818

1919
Once created, that object then contains all the functions and helpers
2020
from both :mod:`sqlalchemy` and :mod:`sqlalchemy.orm`. Furthermore it
21-
provides a class called `Model` that is a declarative base which can be
21+
provides a class called ``Model`` that is a declarative base which can be
2222
used to declare models::
2323

2424
from flask import Flask
@@ -44,29 +44,29 @@ used to declare models::
4444
To create the initial database, just import the `db` object from an
4545
interactive Python shell and run the
4646
:meth:`SQLAlchemy.create_all` method to create the
47-
tables and database:
47+
tables and database::
4848

49-
>>> from yourapplication import db
50-
>>> db.create_all()
49+
>>> from yourapplication import db
50+
>>> db.create_all()
5151

52-
Boom, and there is your database. Now to create some users:
52+
Boom, and there is your database. Now to create some users::
5353

54-
>>> from yourapplication import User
55-
>>> admin = User('admin', '[email protected]')
56-
>>> guest = User('guest', '[email protected]')
54+
>>> from yourapplication import User
55+
>>> admin = User('admin', '[email protected]')
56+
>>> guest = User('guest', '[email protected]')
5757

58-
But they are not yet in the database, so let's make sure they are:
58+
But they are not yet in the database, so let's make sure they are::
5959

60-
>>> db.session.add(admin)
61-
>>> db.session.add(guest)
62-
>>> db.session.commit()
60+
>>> db.session.add(admin)
61+
>>> db.session.add(guest)
62+
>>> db.session.commit()
6363

64-
Accessing the data in database is easy as a pie:
64+
Accessing the data in database is easy as a pie::
6565

66-
>>> users = User.query.all()
67-
[<User u'admin'>, <User u'guest'>]
68-
>>> admin = User.query.filter_by(username='admin').first()
69-
<User u'admin'>
66+
>>> User.query.all()
67+
[<User u'admin'>, <User u'guest'>]
68+
>>> User.query.filter_by(username='admin').first()
69+
<User u'admin'>
7070

7171
Simple Relationships
7272
--------------------
@@ -75,7 +75,6 @@ SQLAlchemy connects to relational databases and what relational databases
7575
are really good at are relations. As such, we shall have an example of an
7676
application that uses two tables that have a relationship to each other::
7777

78-
7978
from datetime import datetime
8079

8180

@@ -111,24 +110,24 @@ application that uses two tables that have a relationship to each other::
111110
def __repr__(self):
112111
return '<Category %r>' % self.name
113112

114-
First let's create some objects:
113+
First let's create some objects::
115114

116-
>>> py = Category('Python')
117-
>>> p = Post('Hello Python!', 'Python is pretty cool', py)
118-
>>> db.session.add(py)
119-
>>> db.session.add(p)
115+
>>> py = Category('Python')
116+
>>> p = Post('Hello Python!', 'Python is pretty cool', py)
117+
>>> db.session.add(py)
118+
>>> db.session.add(p)
120119

121-
Now because we declared `posts` as dynamic relationship in the backref
122-
it shows up as query:
120+
Now because we declared ``posts`` as dynamic relationship in the backref
121+
it shows up as query::
123122

124-
>>> py.posts
125-
<sqlalchemy.orm.dynamic.AppenderBaseQuery object at 0x1027d37d0>
123+
>>> py.posts
124+
<sqlalchemy.orm.dynamic.AppenderBaseQuery object at 0x1027d37d0>
126125

127126
It behaves like a regular query object so we can ask it for all posts that
128-
are associated with our test “Python category:
127+
are associated with our "Python" category::
129128

130-
>>> py.posts.all()
131-
[<Post 'Hello Python!'>]
129+
>>> py.posts.all()
130+
[<Post 'Hello Python!'>]
132131

133132

134133
Road to Enlightenment
@@ -140,15 +139,15 @@ The only things you need to know compared to plain SQLAlchemy are:
140139

141140
- all the functions and classes from :mod:`sqlalchemy` and
142141
:mod:`sqlalchemy.orm`
143-
- a preconfigured scoped session called `session`
142+
- a preconfigured scoped session called ``session``
144143
- the :attr:`~SQLAlchemy.metadata`
145144
- the :attr:`~SQLAlchemy.engine`
146145
- a :meth:`SQLAlchemy.create_all` and :meth:`SQLAlchemy.drop_all`
147146
methods to create and drop tables according to the models.
148147
- a :class:`Model` baseclass that is a configured declarative base.
149148

150149
2. The :class:`Model` declarative base class behaves like a regular
151-
Python class but has a `query` attribute attached that can be used to
150+
Python class but has a ``query`` attribute attached that can be used to
152151
query the model. (:class:`Model` and :class:`BaseQuery`)
153152

154153
3. You have to commit the session, but you don't have to remove it at

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[egg_info]
2-
tag_date = true
2+
tag_build = .dev
3+
tag_date = 1
34

45
[aliases]
56
release = egg_info -RDb ''

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
"""
1616
from setuptools import setup
1717

18-
1918
setup(
2019
name='Flask-SQLAlchemy',
21-
version='3.0-dev',
20+
version='3.0',
2221
url='http://github.com/mitsuhiko/flask-sqlalchemy',
2322
license='BSD',
2423
author='Armin Ronacher',

0 commit comments

Comments
 (0)