Skip to content

Commit b95984d

Browse files
author
James William Pye
committed
Move distutils data into pg.release.
This will aid projects who are including py-postgresql as a sub-package.
1 parent 814ab75 commit b95984d

3 files changed

Lines changed: 186 additions & 109 deletions

File tree

postgresql/release/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
##
2+
# copyright 2009, James William Pye
3+
# http://python.projects.postgresql.org
4+
##
5+
"""
6+
Release management code and project meta-data.
7+
"""

postgresql/release/distutils.py

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
##
2+
# copyright 2009, James William Pye
3+
# http://python.projects.postgresql.org
4+
##
5+
"""
6+
Python distutils data provisions module.
7+
8+
For sub-packagers, the `prefixed_packages` and `prefixed_extensions` functions
9+
should be of particular interest. It is not recommended that sub-packagers
10+
include the `scripts` keyword from py-postgresql in their setup() call.
11+
If the distribution including ``py-postgresql`` uses the standard layout,
12+
chances are that `prefixed_extensions` and `prefixed_packages` will supply the
13+
appropriate information by default as they use `default_prefix` which is derived
14+
from the module's `__package__`.
15+
"""
16+
import sys
17+
import os
18+
from .. import \
19+
__version__ as version, \
20+
__project__ as name, \
21+
__project_id__ as url
22+
from distutils.core import Extension
23+
24+
LONG_DESCRIPTION = """
25+
py-postgresql is a set of Python modules providing interfaces to various parts
26+
of PostgreSQL. Notably, it provides a driver for querying a PostgreSQL database.
27+
28+
Sample PG-API Code
29+
------------------
30+
31+
>>> import postresql.driver as pg_driver
32+
>>> db = pg_driver.connect(user = 'mydbuser', host = 'localhost', port = 5432, database = 'mydbname')
33+
>>> db.execute("CREATE TABLE emp (emp_first_name text, emp_last_name text, emp_salary numeric)")
34+
>>> make_emp = db.prepare("INSERT INTO emp VALUES ($1, $2, $3)")
35+
>>> make_emp("John", "Doe", "75,322")
36+
>>> with db.xact:
37+
... make_emp("Jane", "Doe", "75,322")
38+
... make_emp("Edward", "Johnson", "82,744")
39+
...
40+
41+
There is a DB-API 2.0 module as well::
42+
43+
postgresql.driver.dbapi20
44+
45+
However, PG-API is recommended as it provides greater utility.
46+
47+
Once you get it installed, try out the ``pg_python`` command::
48+
49+
$ pg_python -h localhost -U theuser -d database_name
50+
51+
That should give you a Python console with the database connection bound to the
52+
`db` name.
53+
54+
History
55+
-------
56+
57+
py-postgresql is not yet another PostgreSQL driver, it's been in development for
58+
years. py-postgresql is the Python 3.0 port of the ``pg_proboscis`` driver and
59+
integration of the other ``pg/python`` projects.
60+
61+
62+
More Information
63+
----------------
64+
65+
http://python.projects.postgresql.org
66+
"""
67+
68+
CLASSIFIERS = [
69+
'Development Status :: 5 - Production/Stable',
70+
'Intended Audience :: Developers',
71+
'License :: OSI Approved :: BSD License',
72+
'License :: OSI Approved :: MIT License',
73+
'License :: OSI Approved :: Attribution Assurance License',
74+
'License :: OSI Approved :: Python Software Foundation License',
75+
'Natural Language :: English',
76+
'Operating System :: OS Independent',
77+
'Programming Language :: Python',
78+
'Programming Language :: Python :: 3',
79+
'Topic :: Database',
80+
]
81+
82+
subpackages = [
83+
'bin',
84+
'encodings',
85+
'protocol',
86+
'driver',
87+
'test',
88+
'documentation',
89+
'python',
90+
'release',
91+
# Modules imported from other packages.
92+
'resolved',
93+
]
94+
extensions_data = {
95+
'protocol.cbuffer' : {
96+
'sources' : [os.path.join('protocol', 'buffer.c')],
97+
'libraries' : (sys.platform == 'win32' and ['ws2_32'] or []),
98+
}
99+
}
100+
101+
scripts = [
102+
'postgresql/bin/pg_dotconf',
103+
'postgresql/bin/pg_python',
104+
'postgresql/bin/pg_tin',
105+
'postgresql/bin/pg_withcluster'
106+
]
107+
108+
try:
109+
# :)
110+
if __package__ is not None:
111+
default_prefix = __package__.split('.')[:-1]
112+
else:
113+
default_prefix = __name__.split('.')[:-2]
114+
except NameError:
115+
default_prefix = ['postgresql']
116+
117+
def prefixed_extensions(
118+
prefix : "prefix to prepend to paths" = default_prefix,
119+
extensions_data : "`extensions_data`" = extensions_data,
120+
) -> [Extension]:
121+
"""
122+
Generator producing the `distutils` `Extension` objects.
123+
"""
124+
pkg_prefix = '.'.join(prefix) + '.'
125+
path_prefix = os.path.sep.join(prefix)
126+
for mod, data in extensions_data.items():
127+
yield Extension(
128+
pkg_prefix + mod,
129+
[os.path.join(path_prefix, src) for src in data['sources']],
130+
libraries = data['libraries']
131+
)
132+
133+
def prefixed_packages(
134+
prefix : "prefix to prepend to source paths" = default_prefix,
135+
packages = subpackages,
136+
):
137+
"""
138+
Generator producing the standard `package` list prefixed with `prefix`.
139+
"""
140+
prefix = '.'.join(prefix)
141+
yield prefix
142+
prefix = prefix + '.'
143+
for pkg in packages:
144+
yield prefix + pkg
145+
146+
def standard_setup_keywords(build_extensions = True, prefix = default_prefix):
147+
"""
148+
Used by the py-postgresql distribution.
149+
"""
150+
d = {
151+
'name' : name,
152+
'version' : version,
153+
'description' : 'PostgreSQL tools pacakges. Driver, API specifications, and cluster tools.',
154+
'long_description' : LONG_DESCRIPTION,
155+
'author' : 'James William Pye',
156+
'author_email' : 'x@jwp.name',
157+
'maintainer' : 'James William Pye',
158+
'maintainer_email' : 'python-general@pgfoundry.org',
159+
'url' : url,
160+
'classifiers' : CLASSIFIERS,
161+
'packages' : list(prefixed_packages(prefix = prefix)),
162+
'scripts' : scripts,
163+
}
164+
if build_extensions:
165+
d['ext_modules'] = list(prefixed_extensions(prefix = prefix))
166+
return d

setup.py

Lines changed: 13 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
##
66
import sys
77
import os
8-
import glob
9-
from distutils.core import Extension
108

119
if sys.version_info[:2] < (3,0):
1210
sys.stderr.write(
@@ -19,115 +17,21 @@
1917
)
2018
sys.exit(1)
2119

20+
# distutils data is kept in `postgresql.release.distutils`
2221
sys.path.insert(0, '')
23-
import postgresql
24-
VERSION = postgresql.__version__
25-
NAME = postgresql.__project__
26-
del postgresql
27-
del sys.path[0]
28-
29-
LONG_DESCRIPTION = """
30-
py-postgresql is a set of Python modules providing interfaces to various parts
31-
of PostgreSQL. Notably, it provides a driver for interacting with a database.
32-
33-
Sample PG-API Code
34-
------------------
35-
36-
>>> import postresql.driver as pg_driver
37-
>>> db = pg_driver.connect(user = 'mydbuser', host = 'localhost', port = 5432, database = 'mydbname')
38-
>>> db.execute("CREATE TABLE emp (emp_first_name text, emp_last_name text, emp_salary numeric)")
39-
>>> make_emp = db.prepare("INSERT INTO emp VALUES ($1, $2, $3)")
40-
>>> make_emp("John", "Doe", "75,322")
41-
>>> with db.xact:
42-
... make_emp("Jane", "Doe", "75,322")
43-
... make_emp("Edward", "Johnson", "82,744")
44-
...
45-
46-
There is a DB-API 2.0 module as well::
47-
48-
postgresql.driver.dbapi20
49-
50-
However, PG-API is recommended as it provides greater utility.
51-
52-
53-
History
54-
-------
55-
56-
py-postgresql is not yet another PostgreSQL driver, it's been in development for
57-
years. py-postgresql is the Python 3.0 port of the ``pg_proboscis`` driver and
58-
integration of the other ``pg/python`` projects.
59-
60-
61-
More Information
62-
----------------
63-
64-
http://python.projects.postgresql.org
65-
"""
66-
67-
CLASSIFIERS = [
68-
'Development Status :: 5 - Production/Stable',
69-
'Intended Audience :: Developers',
70-
'License :: OSI Approved :: BSD License',
71-
'License :: OSI Approved :: MIT License',
72-
'License :: OSI Approved :: Attribution Assurance License',
73-
'License :: OSI Approved :: Python Software Foundation License',
74-
'Natural Language :: English',
75-
'Operating System :: OS Independent',
76-
'Programming Language :: Python',
77-
'Programming Language :: Python :: 3',
78-
'Topic :: Database',
79-
]
80-
81-
extensions = [
82-
Extension(
83-
'postgresql.protocol.cbuffer',
84-
[os.path.join('postgresql', 'protocol', 'buffer.c')],
85-
libraries = (sys.platform == 'win32' and ['ws2_32'] or []),
86-
),
87-
]
88-
89-
defaults = {
90-
'name' : NAME,
91-
'version' : VERSION,
92-
'description' : 'PostgreSQL tool library. Driver, API specifications, and cluster tools.',
93-
'long_description' : LONG_DESCRIPTION,
94-
'author' : 'James William Pye',
95-
'author_email' : 'x@jwp.name',
96-
'maintainer' : 'James William Pye',
97-
'maintainer_email' : 'python-general@pgfoundry.org',
98-
'url' : 'http://python.projects.postgresql.org',
99-
'classifiers' : CLASSIFIERS,
100-
101-
'packages' : [
102-
'postgresql',
103-
'postgresql.bin',
104-
'postgresql.encodings',
105-
'postgresql.protocol',
106-
'postgresql.driver',
107-
'postgresql.test',
108-
# Modules imported from other packages.
109-
'postgresql.resolved',
110-
'postgresql.documentation',
111-
'postgresql.python',
112-
],
113-
114-
# Only build extension modules on win32 if PY_BUILD_EXTENSIONS is enabled.
115-
# People who get failures are more likely to just give up on the package
116-
# without reading the documentation. :(
117-
'ext_modules' : (
118-
extensions if os.environ.get('PY_BUILD_EXTENSIONS') or \
119-
not sys.platform in ('win32',)
120-
else ()
121-
),
122-
123-
'scripts' : [
124-
'postgresql/bin/pg_dotconf',
125-
'postgresql/bin/pg_python',
126-
'postgresql/bin/pg_tin',
127-
'postgresql/bin/pg_withcluster'
128-
],
129-
}
13022

23+
# Only build extension modules on win32 if PY_BUILD_EXTENSIONS is enabled.
24+
# People who get failures are more likely to just give up on the package
25+
# without reading the documentation. :(
26+
build_extensions = (
27+
os.environ.get('PY_BUILD_EXTENSIONS') \
28+
or not sys.platform in ('win32',)
29+
)
30+
31+
import postgresql.release.distutils as pg_dist
32+
defaults = pg_dist.standard_setup_keywords(
33+
build_extensions = build_extensions
34+
)
13135
if __name__ == '__main__':
13236
from distutils.core import setup
13337
setup(**defaults)

0 commit comments

Comments
 (0)