-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathdistutils.py
More file actions
189 lines (164 loc) · 5.23 KB
/
distutils.py
File metadata and controls
189 lines (164 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
##
# copyright 2009, James William Pye
# http://python.projects.postgresql.org
##
"""
Python distutils data provisions module.
For sub-packagers, the `prefixed_packages` and `prefixed_extensions` functions
should be of particular interest. It is not recommended that sub-packagers
include the `scripts` keyword from py-postgresql in their setup() call.
If the distribution including ``py-postgresql`` uses the standard layout,
chances are that `prefixed_extensions` and `prefixed_packages` will supply the
appropriate information by default as they use `default_prefix` which is derived
from the module's `__package__`.
"""
import sys
import os
from .. import \
__version__ as version, \
__project__ as name, \
__project_id__ as url
from distutils.core import Extension
LONG_DESCRIPTION = """
py-postgresql is a set of Python modules providing interfaces to various parts
of PostgreSQL. Notably, it provides a pure-Python driver + C optimizations for
querying a PostgreSQL database.
http://python.projects.postgresql.org
Features:
* Prepared Statement driven interfaces.
* Cluster tools for creating and controlling a cluster.
* Support for most PostgreSQL types: composites, arrays, numeric, lots more.
* COPY support.
Sample PG-API Code::
>>> import postgresql
>>> db = postgresql.open('pq://user:password@host:port/database')
>>> db.execute("CREATE TABLE emp (emp_first_name text, emp_last_name text, emp_salary numeric)")
>>> make_emp = db.prepare("INSERT INTO emp VALUES ($1, $2, $3)")
>>> make_emp("John", "Doe", "75,322")
>>> with db.xact():
... make_emp("Jane", "Doe", "75,322")
... make_emp("Edward", "Johnson", "82,744")
...
There is a DB-API 2.0 module as well::
postgresql.driver.dbapi20
However, PG-API is recommended as it provides greater utility.
Once installed, try out the ``pg_python`` console script::
$ pg_python -h localhost -p port -U theuser -d database_name
If a successful connection is made to the remote host, it will provide a Python
console with the database connection bound to the `db` name.
History
-------
py-postgresql is not yet another PostgreSQL driver, it's been in development for
years. py-postgresql is the Python 3 port of the ``pg_proboscis`` driver and
integration of the other ``pg/python`` projects.
"""
CLASSIFIERS = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'License :: OSI Approved :: MIT License',
'License :: OSI Approved :: Attribution Assurance License',
'License :: OSI Approved :: Python Software Foundation License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Database',
]
subpackages = [
'bin',
'encodings',
'lib',
'protocol',
'driver',
'test',
'documentation',
'python',
'release',
# Modules imported from other packages.
'resolved',
]
extensions_data = {
'protocol.optimized' : {
'sources' : [os.path.join('protocol', 'optimized', 'module.c')],
},
'python.optimized' : {
'sources' : [os.path.join('python', 'optimized.c')],
},
}
subpackage_data = {
'lib' : ['*.sql'],
'documentation' : ['*.txt']
}
scripts = [
'postgresql/bin/pg_dotconf',
'postgresql/bin/pg_python',
]
try:
# :)
if __package__ is not None:
default_prefix = __package__.split('.')[:-1]
else:
default_prefix = __name__.split('.')[:-2]
except NameError:
default_prefix = ['postgresql']
def prefixed_extensions(
prefix : "prefix to prepend to paths" = default_prefix,
extensions_data : "`extensions_data`" = extensions_data,
) -> [Extension]:
"""
Generator producing the `distutils` `Extension` objects.
"""
pkg_prefix = '.'.join(prefix) + '.'
path_prefix = os.path.sep.join(prefix)
for mod, data in extensions_data.items():
yield Extension(
pkg_prefix + mod,
[os.path.join(path_prefix, src) for src in data['sources']],
libraries = data.get('libraries', ())
)
def prefixed_packages(
prefix : "prefix to prepend to source paths" = default_prefix,
packages = subpackages,
):
"""
Generator producing the standard `package` list prefixed with `prefix`.
"""
prefix = '.'.join(prefix)
yield prefix
prefix = prefix + '.'
for pkg in packages:
yield prefix + pkg
def prefixed_package_data(
prefix : "prefix to prepend to dictionary keys paths" = default_prefix,
package_data = subpackage_data,
):
"""
Generator producing the standard `package` list prefixed with `prefix`.
"""
prefix = '.'.join(prefix)
prefix = prefix + '.'
for pkg, data in package_data.items():
yield prefix + pkg, data
def standard_setup_keywords(build_extensions = True, prefix = default_prefix):
"""
Used by the py-postgresql distribution.
"""
d = {
'name' : name,
'version' : version,
'description' : 'PostgreSQL driver and tools library.',
'long_description' : LONG_DESCRIPTION,
'author' : 'James William Pye',
'author_email' : '[email protected]',
'maintainer' : 'James William Pye',
'maintainer_email' : '[email protected]',
'url' : url,
'classifiers' : CLASSIFIERS,
'packages' : list(prefixed_packages(prefix = prefix)),
'package_data' : dict(prefixed_package_data(prefix = prefix)),
'scripts' : scripts,
}
if build_extensions:
d['ext_modules'] = list(prefixed_extensions(prefix = prefix))
return d