pglib 5.8.1__tar.gz → 5.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pglib-5.8.1/pglib.egg-info → pglib-5.9.0}/PKG-INFO +1 -4
- {pglib-5.8.1 → pglib-5.9.0}/pglib/__init__.py +0 -4
- {pglib-5.8.1 → pglib-5.9.0/pglib.egg-info}/PKG-INFO +1 -4
- {pglib-5.8.1 → pglib-5.9.0}/pglib.egg-info/SOURCES.txt +0 -1
- {pglib-5.8.1 → pglib-5.9.0}/setup.py +1 -1
- {pglib-5.8.1 → pglib-5.9.0}/src/connection.cpp +24 -1
- {pglib-5.8.1 → pglib-5.9.0}/src/getdata.cpp +7 -2
- {pglib-5.8.1 → pglib-5.9.0}/src/params.cpp +1 -1
- {pglib-5.8.1 → pglib-5.9.0}/src/pgarrays.cpp +172 -59
- {pglib-5.8.1 → pglib-5.9.0}/src/pgarrays.h +1 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/pglib.h +2 -1
- {pglib-5.8.1 → pglib-5.9.0}/test/test_sync.py +10 -0
- pglib-5.8.1/pglib/_version.py +0 -484
- {pglib-5.8.1 → pglib-5.9.0}/LICENSE +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/MANIFEST.in +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/README.rst +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/pglib/asyncpglib.py +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/pglib.egg-info/dependency_links.txt +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/pglib.egg-info/top_level.txt +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/setup.cfg +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/byteswap.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/connection.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/conninfoopt.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/conninfoopt.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/datatypes.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/datatypes.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/debug.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/debug.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/enums.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/enums.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/errors.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/errors.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/getdata.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/juliandate.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/juliandate.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/params.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/pglib.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/pgtypes.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/resultset.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/resultset.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/row.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/row.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/runtime.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/runtime.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/type_hstore.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/type_hstore.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/type_json.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/type_json.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/type_ltree.cpp +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/src/type_ltree.h +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/test/test_async.py +0 -0
- {pglib-5.8.1 → pglib-5.9.0}/test/testutils.py +0 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pglib
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.9.0
|
|
4
4
|
Summary: A PostgreSQL interface
|
|
5
5
|
Home-page: https://gitlab.com/mkleehammer/pglib
|
|
6
6
|
Maintainer: Michael Kleehammer
|
|
7
7
|
Maintainer-email: michael@kleehammer.com
|
|
8
8
|
License: MIT
|
|
9
9
|
Keywords: postgresql postgres
|
|
10
|
-
Platform: UNKNOWN
|
|
11
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
12
11
|
Classifier: Intended Audience :: Developers
|
|
13
12
|
Classifier: Topic :: Database
|
|
@@ -21,5 +20,3 @@ A PostgreSQL interface for Python.
|
|
|
21
20
|
This provides an interface to the libpq library. It is not an DB API
|
|
22
21
|
library, but is instead designed to match the interface PostgreSQL
|
|
23
22
|
offers.
|
|
24
|
-
|
|
25
|
-
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pglib
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.9.0
|
|
4
4
|
Summary: A PostgreSQL interface
|
|
5
5
|
Home-page: https://gitlab.com/mkleehammer/pglib
|
|
6
6
|
Maintainer: Michael Kleehammer
|
|
7
7
|
Maintainer-email: michael@kleehammer.com
|
|
8
8
|
License: MIT
|
|
9
9
|
Keywords: postgresql postgres
|
|
10
|
-
Platform: UNKNOWN
|
|
11
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
12
11
|
Classifier: Intended Audience :: Developers
|
|
13
12
|
Classifier: Topic :: Database
|
|
@@ -21,5 +20,3 @@ A PostgreSQL interface for Python.
|
|
|
21
20
|
This provides an interface to the libpq library. It is not an DB API
|
|
22
21
|
library, but is instead designed to match the interface PostgreSQL
|
|
23
22
|
offers.
|
|
24
|
-
|
|
25
|
-
|
|
@@ -150,6 +150,8 @@ static PGresult* internal_execute(PyObject* self, PyObject* args)
|
|
|
150
150
|
return 0;
|
|
151
151
|
}
|
|
152
152
|
const char* szSQL = PyUnicode_AsUTF8(pSql);
|
|
153
|
+
if (!szSQL)
|
|
154
|
+
return 0;
|
|
153
155
|
|
|
154
156
|
Params params(cParams);
|
|
155
157
|
if (!BindParams(cnxn, params, args))
|
|
@@ -190,7 +192,11 @@ static PyObject* Connection_script(PyObject* self, PyObject* args)
|
|
|
190
192
|
if (!PyArg_ParseTuple(args, "U", &pScript))
|
|
191
193
|
return 0;
|
|
192
194
|
|
|
193
|
-
|
|
195
|
+
const char* szScript = PyUnicode_AsUTF8(pScript);
|
|
196
|
+
if (!szScript)
|
|
197
|
+
return 0;
|
|
198
|
+
|
|
199
|
+
ResultHolder result = PQexec(cnxn->pgconn, szScript);
|
|
194
200
|
if (result == 0)
|
|
195
201
|
return 0;
|
|
196
202
|
|
|
@@ -256,6 +262,9 @@ static PyObject* Connection_copy_from(PyObject* self, PyObject* args)
|
|
|
256
262
|
return 0;
|
|
257
263
|
|
|
258
264
|
const char* szSQL = PyUnicode_AsUTF8(command);
|
|
265
|
+
if (!szSQL)
|
|
266
|
+
return 0;
|
|
267
|
+
|
|
259
268
|
ResultHolder result;
|
|
260
269
|
Py_BEGIN_ALLOW_THREADS
|
|
261
270
|
result = PQexec(cnxn->pgconn, szSQL);
|
|
@@ -413,8 +422,13 @@ static PyObject* Connection_copy_to_csv(PyObject* self, PyObject* args, PyObject
|
|
|
413
422
|
|
|
414
423
|
Object sql(PyUnicode_FromFormat("copy %U to stdout with csv %s delimiter '%s' quote '%s'",
|
|
415
424
|
table, header_token, pszDelimiter, pszQuote));
|
|
425
|
+
if (!sql)
|
|
426
|
+
return 0;
|
|
416
427
|
|
|
417
428
|
const char* szSQL = PyUnicode_AsUTF8(sql);
|
|
429
|
+
if (!szSQL)
|
|
430
|
+
return 0;
|
|
431
|
+
|
|
418
432
|
ResultHolder result;
|
|
419
433
|
Py_BEGIN_ALLOW_THREADS
|
|
420
434
|
result = PQexec(cnxn->pgconn, szSQL);
|
|
@@ -555,6 +569,9 @@ static PyObject* Connection_copy_from_csv(PyObject* self, PyObject* args, PyObje
|
|
|
555
569
|
return 0;
|
|
556
570
|
|
|
557
571
|
const char* szSQL = PyUnicode_AsUTF8(sql);
|
|
572
|
+
if (!szSQL)
|
|
573
|
+
return 0;
|
|
574
|
+
|
|
558
575
|
ResultHolder result;
|
|
559
576
|
Py_BEGIN_ALLOW_THREADS
|
|
560
577
|
result = PQexec(cnxn->pgconn, szSQL);
|
|
@@ -1137,6 +1154,9 @@ static PyObject* Connection_sendQuery(PyObject* self, PyObject* args)
|
|
|
1137
1154
|
|
|
1138
1155
|
int sent;
|
|
1139
1156
|
const char* szSQL = PyUnicode_AsUTF8(pScript);
|
|
1157
|
+
if (!szSQL)
|
|
1158
|
+
return 0;
|
|
1159
|
+
|
|
1140
1160
|
Py_BEGIN_ALLOW_THREADS
|
|
1141
1161
|
sent = PQsendQuery(cnxn->pgconn, szSQL);
|
|
1142
1162
|
Py_END_ALLOW_THREADS
|
|
@@ -1176,7 +1196,10 @@ static PyObject* Connection_sendQueryParams(PyObject* self, PyObject* args)
|
|
|
1176
1196
|
PyErr_SetString(PyExc_TypeError, "The first argument must be the SQL string.");
|
|
1177
1197
|
return 0;
|
|
1178
1198
|
}
|
|
1199
|
+
|
|
1179
1200
|
const char* szSQL = PyUnicode_AsUTF8(pSql);
|
|
1201
|
+
if (!szSQL)
|
|
1202
|
+
return 0;
|
|
1180
1203
|
|
|
1181
1204
|
Params params(cParams);
|
|
1182
1205
|
if (!BindParams(cnxn, params, args))
|
|
@@ -286,8 +286,10 @@ static PyObject* GetInterval(const char* p) // , bool integer_datetimes)
|
|
|
286
286
|
uint32_t month = swaps4(pinterval->month);
|
|
287
287
|
uint32_t year = month / 12;
|
|
288
288
|
|
|
289
|
-
if (month || year)
|
|
290
|
-
|
|
289
|
+
if (month || year) {
|
|
290
|
+
PyErr_SetString(Error, "Years and months are not supported in intervals");
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
291
293
|
|
|
292
294
|
int seconds = (second) + (60 * minute) + (3600 * hour);
|
|
293
295
|
int days = day;
|
|
@@ -399,6 +401,9 @@ PyObject* ConvertValue(PGresult* result, int iRow, int iCol, bool integer_dateti
|
|
|
399
401
|
case TEXTARRAYOID:
|
|
400
402
|
return GetTextArray(p);
|
|
401
403
|
|
|
404
|
+
case JSONBARRAYOID:
|
|
405
|
+
return GetJSONBArray(p);
|
|
406
|
+
|
|
402
407
|
case DATEARRAYOID:
|
|
403
408
|
return GetDateArray(p);
|
|
404
409
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
// Sending and receiving arrays. Right now we only support strings and integers, but there is
|
|
3
2
|
// no reason we can't add more types.
|
|
4
3
|
//
|
|
@@ -28,6 +27,7 @@
|
|
|
28
27
|
#include "params.h"
|
|
29
28
|
#include "juliandate.h"
|
|
30
29
|
#include "errors.h"
|
|
30
|
+
#include "runtime.h"
|
|
31
31
|
#include "debug.h"
|
|
32
32
|
|
|
33
33
|
|
|
@@ -39,6 +39,12 @@ void Arrays_Init()
|
|
|
39
39
|
|
|
40
40
|
struct ArrayHeader
|
|
41
41
|
{
|
|
42
|
+
// The fields in a PostgreSQL array. We use this when writing an array. All int fields
|
|
43
|
+
// will be in host / big endian, so use ntohl and htonl.
|
|
44
|
+
//
|
|
45
|
+
// Technically an array header only includes the first 3 fields. Each dimension then has a
|
|
46
|
+
// count and lbound. Since we only support one dimension right now, I've put them together.
|
|
47
|
+
|
|
42
48
|
uint32_t ndim; // number of dimensions - we support 1
|
|
43
49
|
uint32_t flags; // binary format? 0 or 1, but unused by the server?
|
|
44
50
|
Oid oid; // type of elements
|
|
@@ -47,6 +53,46 @@ struct ArrayHeader
|
|
|
47
53
|
char buffer[0];
|
|
48
54
|
};
|
|
49
55
|
|
|
56
|
+
|
|
57
|
+
struct ArrayInfo {
|
|
58
|
+
// The important array fields, copied and converted to native endianess (so don't use ntohl
|
|
59
|
+
// or htonl).
|
|
60
|
+
Oid oid; // type of elements
|
|
61
|
+
uint32_t len; // number of elements
|
|
62
|
+
const char* data; // pointer to first element
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
inline uint8_t ReadU8(const char ** pp) {
|
|
67
|
+
// Reads an unsigned int from `pp` *and* increments the pointer *pp.
|
|
68
|
+
uint8_t n = **(uint8_t**)pp;
|
|
69
|
+
*pp += sizeof(char);
|
|
70
|
+
return n;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
inline int64_t Read64(const char ** pp) {
|
|
74
|
+
// Reads an int64 from `pp` *and* increments the pointer *pp.
|
|
75
|
+
uint64_t n = **(uint64_t**)pp;
|
|
76
|
+
*pp += sizeof(uint64_t);
|
|
77
|
+
return swaps8(n);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
inline int32_t Read32(const char ** pp) {
|
|
81
|
+
// Reads an int from `pp` *and* increments the pointer *pp.
|
|
82
|
+
uint32_t n = **(uint32_t**)pp;
|
|
83
|
+
*pp += sizeof(uint32_t);
|
|
84
|
+
return (int32_t)htonl(n);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
inline uint32_t ReadU32(const char ** pp) {
|
|
88
|
+
// Reads an unsigned int from `pp` *and* increments the pointer *pp.
|
|
89
|
+
uint32_t n = **(uint32_t**)pp;
|
|
90
|
+
*pp += sizeof(uint32_t);
|
|
91
|
+
return htonl(n);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
50
96
|
static PyObject* FindFirstParam(Object& seq)
|
|
51
97
|
{
|
|
52
98
|
// Returns a *borrowed* reference to the first non-None parameter in the sequence. Returns
|
|
@@ -63,6 +109,40 @@ static PyObject* FindFirstParam(Object& seq)
|
|
|
63
109
|
}
|
|
64
110
|
|
|
65
111
|
|
|
112
|
+
static bool ReadArrayInfo(const char* p, ArrayInfo &info, Oid expected_type) {
|
|
113
|
+
// Read the array header from `p` into `info` and return true if valid and something pglib
|
|
114
|
+
// can handle. If there is an error, an exception will be set and false will be returned.
|
|
115
|
+
|
|
116
|
+
uint32_t ndim = ReadU32(&p);
|
|
117
|
+
if (ndim > 1) {
|
|
118
|
+
SetStringError(Error, "pglib can only read single dimensional arrays (ndim=%d)", (int)ndim);
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
ReadU32(&p); // format: 0 or 1. Not used right now.
|
|
123
|
+
|
|
124
|
+
info.oid = (Oid)ReadU32(&p);
|
|
125
|
+
if (info.oid != expected_type) {
|
|
126
|
+
SetStringError(Error, "Unable to read array. Expected element type %u not %u",
|
|
127
|
+
(uint)expected_type, (uint)info.oid);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// The length is within the dimension header, which we don't have if there are no dimensions.
|
|
132
|
+
|
|
133
|
+
if (ndim != 0) {
|
|
134
|
+
info.len = ReadU32(&p);
|
|
135
|
+
ReadU32(&p); // lower bound
|
|
136
|
+
} else {
|
|
137
|
+
info.len = 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
info.data = p;
|
|
141
|
+
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
66
146
|
static bool BindDateArray(Params& params, Object& seq, Py_ssize_t cItems)
|
|
67
147
|
{
|
|
68
148
|
// Loop through the array and make sure each entry is a date.
|
|
@@ -328,26 +408,22 @@ bool BindArray(Params& params, PyObject* param)
|
|
|
328
408
|
PyObject* GetDateArray(const char* p)
|
|
329
409
|
{
|
|
330
410
|
// Reads a DATEARRAYOID array result and returns a list of datetime.date objects.
|
|
411
|
+
ArrayInfo info;
|
|
412
|
+
if (!ReadArrayInfo(p, info, DATEOID)) {
|
|
413
|
+
return 0;
|
|
414
|
+
}
|
|
331
415
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (ntohl(phdr->ndim) > 1)
|
|
335
|
-
return SetStringError(Error, "pglib can only read single dimensional arrays (ndim=%d)",
|
|
336
|
-
ntohl(phdr->ndim));
|
|
337
|
-
|
|
338
|
-
Py_ssize_t dim = ntohl(phdr->ndim) == 0 ? 0 : ntohl(phdr->dim);
|
|
339
|
-
|
|
340
|
-
Object list(PyList_New(dim));
|
|
416
|
+
Object list(PyList_New(info.len));
|
|
341
417
|
if (!list)
|
|
342
418
|
return 0;
|
|
343
419
|
|
|
344
|
-
if (
|
|
345
|
-
|
|
346
|
-
int32_t* pT = (int32_t*)&phdr->buffer[0];
|
|
420
|
+
if (info.len) {
|
|
421
|
+
const char* data = info.data;
|
|
347
422
|
|
|
348
|
-
for (
|
|
423
|
+
for (uint32_t i = 0; i < info.len; i++)
|
|
349
424
|
{
|
|
350
|
-
int32_t len =
|
|
425
|
+
int32_t len = Read32(&data);
|
|
426
|
+
|
|
351
427
|
if (len == -1)
|
|
352
428
|
{
|
|
353
429
|
Py_INCREF(Py_None);
|
|
@@ -355,7 +431,7 @@ PyObject* GetDateArray(const char* p)
|
|
|
355
431
|
}
|
|
356
432
|
else
|
|
357
433
|
{
|
|
358
|
-
uint32_t value =
|
|
434
|
+
uint32_t value = Read32(&data) + JULIAN_START;
|
|
359
435
|
int year, month, date;
|
|
360
436
|
julianToDate(value, year, month, date);
|
|
361
437
|
PyObject* d = PyDate_FromDate(year, month, date);
|
|
@@ -374,25 +450,22 @@ PyObject* GetInt4Array(const char* p)
|
|
|
374
450
|
{
|
|
375
451
|
// Reads an INT4ARRAYOID array result and returns a list of integers.
|
|
376
452
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
ntohl(phdr->ndim));
|
|
382
|
-
|
|
383
|
-
Py_ssize_t dim = ntohl(phdr->ndim) == 0 ? 0 : ntohl(phdr->dim);
|
|
453
|
+
ArrayInfo info;
|
|
454
|
+
if (!ReadArrayInfo(p, info, INT4OID)) {
|
|
455
|
+
return 0;
|
|
456
|
+
}
|
|
384
457
|
|
|
385
|
-
Object list(PyList_New(
|
|
458
|
+
Object list(PyList_New(info.len));
|
|
386
459
|
if (!list)
|
|
387
460
|
return 0;
|
|
388
461
|
|
|
389
|
-
if (
|
|
390
|
-
|
|
391
|
-
int32_t* pT = (int32_t*)&phdr->buffer[0];
|
|
462
|
+
if (info.len) {
|
|
463
|
+
const char* data = info.data;
|
|
392
464
|
|
|
393
|
-
for (
|
|
465
|
+
for (uint32_t i = 0; i < info.len; i++)
|
|
394
466
|
{
|
|
395
|
-
int32_t len =
|
|
467
|
+
int32_t len = Read32(&data);
|
|
468
|
+
|
|
396
469
|
if (len == -1)
|
|
397
470
|
{
|
|
398
471
|
Py_INCREF(Py_None);
|
|
@@ -400,10 +473,11 @@ PyObject* GetInt4Array(const char* p)
|
|
|
400
473
|
}
|
|
401
474
|
else
|
|
402
475
|
{
|
|
403
|
-
int32_t val =
|
|
476
|
+
int32_t val = Read32(&data);
|
|
404
477
|
PyObject* l = PyLong_FromLong(val);
|
|
405
478
|
if (!l)
|
|
406
479
|
return 0;
|
|
480
|
+
|
|
407
481
|
PyList_SET_ITEM(list.Get(), i, l);
|
|
408
482
|
}
|
|
409
483
|
}
|
|
@@ -416,26 +490,21 @@ PyObject* GetInt8Array(const char* p)
|
|
|
416
490
|
{
|
|
417
491
|
// Reads an INT4ARRAYOID array result and returns a list of integers.
|
|
418
492
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
ntohl(phdr->ndim));
|
|
424
|
-
|
|
425
|
-
Py_ssize_t dim = ntohl(phdr->ndim) == 0 ? 0 : ntohl(phdr->dim);
|
|
493
|
+
ArrayInfo info;
|
|
494
|
+
if (!ReadArrayInfo(p, info, INT8OID)) {
|
|
495
|
+
return 0;
|
|
496
|
+
}
|
|
426
497
|
|
|
427
|
-
Object list(PyList_New(
|
|
498
|
+
Object list(PyList_New(info.len));
|
|
428
499
|
if (!list)
|
|
429
500
|
return 0;
|
|
430
501
|
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
const char* pT = &phdr->buffer[0];
|
|
502
|
+
if (info.len) {
|
|
503
|
+
const char* data = info.data;
|
|
434
504
|
|
|
435
|
-
for (
|
|
505
|
+
for (uint32_t i = 0; i < info.len; i++)
|
|
436
506
|
{
|
|
437
|
-
int32_t len =
|
|
438
|
-
pT += 4;
|
|
507
|
+
int32_t len = Read32(&data);
|
|
439
508
|
|
|
440
509
|
if (len == -1)
|
|
441
510
|
{
|
|
@@ -444,11 +513,11 @@ PyObject* GetInt8Array(const char* p)
|
|
|
444
513
|
}
|
|
445
514
|
else
|
|
446
515
|
{
|
|
447
|
-
int64_t val =
|
|
448
|
-
pT += 8;
|
|
516
|
+
int64_t val = Read64(&data);
|
|
449
517
|
PyObject* l = PyLong_FromLongLong(val);
|
|
450
518
|
if (!l)
|
|
451
519
|
return 0;
|
|
520
|
+
|
|
452
521
|
PyList_SET_ITEM(list.Get(), i, l);
|
|
453
522
|
}
|
|
454
523
|
}
|
|
@@ -458,28 +527,25 @@ PyObject* GetInt8Array(const char* p)
|
|
|
458
527
|
}
|
|
459
528
|
|
|
460
529
|
|
|
530
|
+
|
|
461
531
|
PyObject* GetTextArray(const char* p)
|
|
462
532
|
{
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
ntohl(phdr->ndim));
|
|
468
|
-
|
|
469
|
-
Py_ssize_t dim = ntohl(phdr->ndim) == 0 ? 0 : ntohl(phdr->dim);
|
|
533
|
+
ArrayInfo info;
|
|
534
|
+
if (!ReadArrayInfo(p, info, TEXTOID)) {
|
|
535
|
+
return 0;
|
|
536
|
+
}
|
|
470
537
|
|
|
471
|
-
Object list(PyList_New(
|
|
538
|
+
Object list(PyList_New(info.len));
|
|
472
539
|
if (!list)
|
|
473
540
|
return 0;
|
|
474
541
|
|
|
475
|
-
if (
|
|
542
|
+
if (info.len > 0)
|
|
476
543
|
{
|
|
477
|
-
const char* pT =
|
|
544
|
+
const char* pT = info.data;
|
|
478
545
|
|
|
479
|
-
for (
|
|
546
|
+
for (uint32_t i = 0; i < info.len; i++)
|
|
480
547
|
{
|
|
481
|
-
int32_t len =
|
|
482
|
-
pT += 4;
|
|
548
|
+
int32_t len = Read32(&pT);
|
|
483
549
|
|
|
484
550
|
if (len == -1)
|
|
485
551
|
{
|
|
@@ -499,3 +565,50 @@ PyObject* GetTextArray(const char* p)
|
|
|
499
565
|
|
|
500
566
|
return list.Detach();
|
|
501
567
|
}
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
PyObject* GetJSONBArray(const char* p) {
|
|
571
|
+
ArrayInfo info;
|
|
572
|
+
if (!ReadArrayInfo(p, info, JSONBOID)) {
|
|
573
|
+
return 0;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
Object list(PyList_New(info.len));
|
|
577
|
+
if (!list)
|
|
578
|
+
return 0;
|
|
579
|
+
|
|
580
|
+
if (info.len > 0) {
|
|
581
|
+
PyObject* func = GetFunction("json.loads");
|
|
582
|
+
if (!func)
|
|
583
|
+
return 0;
|
|
584
|
+
|
|
585
|
+
const char* data = info.data;
|
|
586
|
+
|
|
587
|
+
for (uint32_t i = 0; i < info.len; i++) {
|
|
588
|
+
// Each element is (len, version (1), cstr)
|
|
589
|
+
|
|
590
|
+
int32_t len = Read32(&data);
|
|
591
|
+
|
|
592
|
+
PyObject* value = 0;
|
|
593
|
+
if (len == -1) {
|
|
594
|
+
value = Py_None;
|
|
595
|
+
Py_INCREF(Py_None);
|
|
596
|
+
} else {
|
|
597
|
+
uint8_t version = ReadU8(&data);
|
|
598
|
+
|
|
599
|
+
if (version != 1) {
|
|
600
|
+
return SetStringError(Error, "Unexpected JSONB version %u in array", (uint32_t)version);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
value = PyObject_CallFunction(func, "s", data);
|
|
604
|
+
if (!value)
|
|
605
|
+
return 0;
|
|
606
|
+
data += len - 1; // -1 because we already incremented past version
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
PyList_SET_ITEM(list.Get(), i, value);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return list.Detach();
|
|
614
|
+
}
|
|
@@ -57,7 +57,7 @@ inline void UNUSED(...) { }
|
|
|
57
57
|
|
|
58
58
|
extern PyObject* Error;
|
|
59
59
|
|
|
60
|
-
// From pg_type.
|
|
60
|
+
// From src/include/catalog/pg_type.dat
|
|
61
61
|
|
|
62
62
|
#define ANYARRAYOID 2277
|
|
63
63
|
#define ANYOID 2276
|
|
@@ -89,6 +89,7 @@ extern PyObject* Error;
|
|
|
89
89
|
#define VARCHAROID 1043
|
|
90
90
|
#define JSONOID 114
|
|
91
91
|
#define JSONBOID 3802
|
|
92
|
+
#define JSONBARRAYOID 3807
|
|
92
93
|
|
|
93
94
|
// #define TIMESTAMPARRAYOID 1115
|
|
94
95
|
// #define TIMEARRAYOID 1183
|
|
@@ -1230,6 +1230,16 @@ def test_empty_jsonb(cnxn):
|
|
|
1230
1230
|
assert value == result
|
|
1231
1231
|
|
|
1232
1232
|
|
|
1233
|
+
def test_jsonb_array(cnxn):
|
|
1234
|
+
# REVIEW: We can only read these for now.
|
|
1235
|
+
value = [{"a": 1}, {"a": 22}]
|
|
1236
|
+
cnxn.execute("create table t1(j jsonb)")
|
|
1237
|
+
cnxn.execute("""insert into t1 values('{"a": 1}')""")
|
|
1238
|
+
cnxn.execute("""insert into t1 values('{"a": 22}')""")
|
|
1239
|
+
|
|
1240
|
+
result = cnxn.fetchval("select array_agg(j) from t1")
|
|
1241
|
+
assert result == value
|
|
1242
|
+
|
|
1233
1243
|
def test_info(cnxn):
|
|
1234
1244
|
info = cnxn.info()
|
|
1235
1245
|
assert info['dbname'] == 'test'
|
pglib-5.8.1/pglib/_version.py
DELETED
|
@@ -1,484 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# This file helps to compute a version number in source trees obtained from
|
|
3
|
-
# git-archive tarball (such as those provided by githubs download-from-tag
|
|
4
|
-
# feature). Distribution tarballs (built by setup.py sdist) and build
|
|
5
|
-
# directories (produced by setup.py build) will contain a much shorter file
|
|
6
|
-
# that just contains the computed version number.
|
|
7
|
-
|
|
8
|
-
# This file is released into the public domain. Generated by
|
|
9
|
-
# versioneer-0.16 (https://github.com/warner/python-versioneer)
|
|
10
|
-
|
|
11
|
-
"""Git implementation of _version.py."""
|
|
12
|
-
|
|
13
|
-
import errno
|
|
14
|
-
import os
|
|
15
|
-
import re
|
|
16
|
-
import subprocess
|
|
17
|
-
import sys
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def get_keywords():
|
|
21
|
-
"""Get the keywords needed to look up the version information."""
|
|
22
|
-
# these strings will be replaced by git during git-archive.
|
|
23
|
-
# setup.py/versioneer.py will grep for the variable names, so they must
|
|
24
|
-
# each be defined on a line of their own. _version.py will just call
|
|
25
|
-
# get_keywords().
|
|
26
|
-
git_refnames = "$Format:%d$"
|
|
27
|
-
git_full = "$Format:%H$"
|
|
28
|
-
keywords = {"refnames": git_refnames, "full": git_full}
|
|
29
|
-
return keywords
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class VersioneerConfig:
|
|
33
|
-
"""Container for Versioneer configuration parameters."""
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def get_config():
|
|
37
|
-
"""Create, populate and return the VersioneerConfig() object."""
|
|
38
|
-
# these strings are filled in when 'setup.py versioneer' creates
|
|
39
|
-
# _version.py
|
|
40
|
-
cfg = VersioneerConfig()
|
|
41
|
-
cfg.VCS = "git"
|
|
42
|
-
cfg.style = "pep440"
|
|
43
|
-
cfg.tag_prefix = ""
|
|
44
|
-
cfg.parentdir_prefix = "None"
|
|
45
|
-
cfg.versionfile_source = "pglib/_version.py"
|
|
46
|
-
cfg.verbose = False
|
|
47
|
-
return cfg
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class NotThisMethod(Exception):
|
|
51
|
-
"""Exception raised if a method is not valid for the current scenario."""
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
LONG_VERSION_PY = {}
|
|
55
|
-
HANDLERS = {}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def register_vcs_handler(vcs, method): # decorator
|
|
59
|
-
"""Decorator to mark a method as the handler for a particular VCS."""
|
|
60
|
-
def decorate(f):
|
|
61
|
-
"""Store f in HANDLERS[vcs][method]."""
|
|
62
|
-
if vcs not in HANDLERS:
|
|
63
|
-
HANDLERS[vcs] = {}
|
|
64
|
-
HANDLERS[vcs][method] = f
|
|
65
|
-
return f
|
|
66
|
-
return decorate
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
|
|
70
|
-
"""Call the given command(s)."""
|
|
71
|
-
assert isinstance(commands, list)
|
|
72
|
-
p = None
|
|
73
|
-
for c in commands:
|
|
74
|
-
try:
|
|
75
|
-
dispcmd = str([c] + args)
|
|
76
|
-
# remember shell=False, so use git.cmd on windows, not just git
|
|
77
|
-
p = subprocess.Popen([c] + args, cwd=cwd, stdout=subprocess.PIPE,
|
|
78
|
-
stderr=(subprocess.PIPE if hide_stderr
|
|
79
|
-
else None))
|
|
80
|
-
break
|
|
81
|
-
except EnvironmentError:
|
|
82
|
-
e = sys.exc_info()[1]
|
|
83
|
-
if e.errno == errno.ENOENT:
|
|
84
|
-
continue
|
|
85
|
-
if verbose:
|
|
86
|
-
print("unable to run %s" % dispcmd)
|
|
87
|
-
print(e)
|
|
88
|
-
return None
|
|
89
|
-
else:
|
|
90
|
-
if verbose:
|
|
91
|
-
print("unable to find command, tried %s" % (commands,))
|
|
92
|
-
return None
|
|
93
|
-
stdout = p.communicate()[0].strip()
|
|
94
|
-
if sys.version_info[0] >= 3:
|
|
95
|
-
stdout = stdout.decode()
|
|
96
|
-
if p.returncode != 0:
|
|
97
|
-
if verbose:
|
|
98
|
-
print("unable to run %s (error)" % dispcmd)
|
|
99
|
-
return None
|
|
100
|
-
return stdout
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def versions_from_parentdir(parentdir_prefix, root, verbose):
|
|
104
|
-
"""Try to determine the version from the parent directory name.
|
|
105
|
-
|
|
106
|
-
Source tarballs conventionally unpack into a directory that includes
|
|
107
|
-
both the project name and a version string.
|
|
108
|
-
"""
|
|
109
|
-
dirname = os.path.basename(root)
|
|
110
|
-
if not dirname.startswith(parentdir_prefix):
|
|
111
|
-
if verbose:
|
|
112
|
-
print("guessing rootdir is '%s', but '%s' doesn't start with "
|
|
113
|
-
"prefix '%s'" % (root, dirname, parentdir_prefix))
|
|
114
|
-
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
|
|
115
|
-
return {"version": dirname[len(parentdir_prefix):],
|
|
116
|
-
"full-revisionid": None,
|
|
117
|
-
"dirty": False, "error": None}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
@register_vcs_handler("git", "get_keywords")
|
|
121
|
-
def git_get_keywords(versionfile_abs):
|
|
122
|
-
"""Extract version information from the given file."""
|
|
123
|
-
# the code embedded in _version.py can just fetch the value of these
|
|
124
|
-
# keywords. When used from setup.py, we don't want to import _version.py,
|
|
125
|
-
# so we do it with a regexp instead. This function is not used from
|
|
126
|
-
# _version.py.
|
|
127
|
-
keywords = {}
|
|
128
|
-
try:
|
|
129
|
-
f = open(versionfile_abs, "r")
|
|
130
|
-
for line in f.readlines():
|
|
131
|
-
if line.strip().startswith("git_refnames ="):
|
|
132
|
-
mo = re.search(r'=\s*"(.*)"', line)
|
|
133
|
-
if mo:
|
|
134
|
-
keywords["refnames"] = mo.group(1)
|
|
135
|
-
if line.strip().startswith("git_full ="):
|
|
136
|
-
mo = re.search(r'=\s*"(.*)"', line)
|
|
137
|
-
if mo:
|
|
138
|
-
keywords["full"] = mo.group(1)
|
|
139
|
-
f.close()
|
|
140
|
-
except EnvironmentError:
|
|
141
|
-
pass
|
|
142
|
-
return keywords
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
@register_vcs_handler("git", "keywords")
|
|
146
|
-
def git_versions_from_keywords(keywords, tag_prefix, verbose):
|
|
147
|
-
"""Get version information from git keywords."""
|
|
148
|
-
if not keywords:
|
|
149
|
-
raise NotThisMethod("no keywords at all, weird")
|
|
150
|
-
refnames = keywords["refnames"].strip()
|
|
151
|
-
if refnames.startswith("$Format"):
|
|
152
|
-
if verbose:
|
|
153
|
-
print("keywords are unexpanded, not using")
|
|
154
|
-
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
|
|
155
|
-
refs = set([r.strip() for r in refnames.strip("()").split(",")])
|
|
156
|
-
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
|
|
157
|
-
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
|
|
158
|
-
TAG = "tag: "
|
|
159
|
-
tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
|
|
160
|
-
if not tags:
|
|
161
|
-
# Either we're using git < 1.8.3, or there really are no tags. We use
|
|
162
|
-
# a heuristic: assume all version tags have a digit. The old git %d
|
|
163
|
-
# expansion behaves like git log --decorate=short and strips out the
|
|
164
|
-
# refs/heads/ and refs/tags/ prefixes that would let us distinguish
|
|
165
|
-
# between branches and tags. By ignoring refnames without digits, we
|
|
166
|
-
# filter out many common branch names like "release" and
|
|
167
|
-
# "stabilization", as well as "HEAD" and "master".
|
|
168
|
-
tags = set([r for r in refs if re.search(r'\d', r)])
|
|
169
|
-
if verbose:
|
|
170
|
-
print("discarding '%s', no digits" % ",".join(refs-tags))
|
|
171
|
-
if verbose:
|
|
172
|
-
print("likely tags: %s" % ",".join(sorted(tags)))
|
|
173
|
-
for ref in sorted(tags):
|
|
174
|
-
# sorting will prefer e.g. "2.0" over "2.0rc1"
|
|
175
|
-
if ref.startswith(tag_prefix):
|
|
176
|
-
r = ref[len(tag_prefix):]
|
|
177
|
-
if verbose:
|
|
178
|
-
print("picking %s" % r)
|
|
179
|
-
return {"version": r,
|
|
180
|
-
"full-revisionid": keywords["full"].strip(),
|
|
181
|
-
"dirty": False, "error": None
|
|
182
|
-
}
|
|
183
|
-
# no suitable tags, so version is "0+unknown", but full hex is still there
|
|
184
|
-
if verbose:
|
|
185
|
-
print("no suitable tags, using unknown + full revision id")
|
|
186
|
-
return {"version": "0+unknown",
|
|
187
|
-
"full-revisionid": keywords["full"].strip(),
|
|
188
|
-
"dirty": False, "error": "no suitable tags"}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
@register_vcs_handler("git", "pieces_from_vcs")
|
|
192
|
-
def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
|
|
193
|
-
"""Get version from 'git describe' in the root of the source tree.
|
|
194
|
-
|
|
195
|
-
This only gets called if the git-archive 'subst' keywords were *not*
|
|
196
|
-
expanded, and _version.py hasn't already been rewritten with a short
|
|
197
|
-
version string, meaning we're inside a checked out source tree.
|
|
198
|
-
"""
|
|
199
|
-
if not os.path.exists(os.path.join(root, ".git")):
|
|
200
|
-
if verbose:
|
|
201
|
-
print("no .git in %s" % root)
|
|
202
|
-
raise NotThisMethod("no .git directory")
|
|
203
|
-
|
|
204
|
-
GITS = ["git"]
|
|
205
|
-
if sys.platform == "win32":
|
|
206
|
-
GITS = ["git.cmd", "git.exe"]
|
|
207
|
-
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
|
|
208
|
-
# if there isn't one, this yields HEX[-dirty] (no NUM)
|
|
209
|
-
describe_out = run_command(GITS, ["describe", "--tags", "--dirty",
|
|
210
|
-
"--always", "--long",
|
|
211
|
-
"--match", "%s*" % tag_prefix],
|
|
212
|
-
cwd=root)
|
|
213
|
-
# --long was added in git-1.5.5
|
|
214
|
-
if describe_out is None:
|
|
215
|
-
raise NotThisMethod("'git describe' failed")
|
|
216
|
-
describe_out = describe_out.strip()
|
|
217
|
-
full_out = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
|
|
218
|
-
if full_out is None:
|
|
219
|
-
raise NotThisMethod("'git rev-parse' failed")
|
|
220
|
-
full_out = full_out.strip()
|
|
221
|
-
|
|
222
|
-
pieces = {}
|
|
223
|
-
pieces["long"] = full_out
|
|
224
|
-
pieces["short"] = full_out[:7] # maybe improved later
|
|
225
|
-
pieces["error"] = None
|
|
226
|
-
|
|
227
|
-
# parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
|
|
228
|
-
# TAG might have hyphens.
|
|
229
|
-
git_describe = describe_out
|
|
230
|
-
|
|
231
|
-
# look for -dirty suffix
|
|
232
|
-
dirty = git_describe.endswith("-dirty")
|
|
233
|
-
pieces["dirty"] = dirty
|
|
234
|
-
if dirty:
|
|
235
|
-
git_describe = git_describe[:git_describe.rindex("-dirty")]
|
|
236
|
-
|
|
237
|
-
# now we have TAG-NUM-gHEX or HEX
|
|
238
|
-
|
|
239
|
-
if "-" in git_describe:
|
|
240
|
-
# TAG-NUM-gHEX
|
|
241
|
-
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
|
|
242
|
-
if not mo:
|
|
243
|
-
# unparseable. Maybe git-describe is misbehaving?
|
|
244
|
-
pieces["error"] = ("unable to parse git-describe output: '%s'"
|
|
245
|
-
% describe_out)
|
|
246
|
-
return pieces
|
|
247
|
-
|
|
248
|
-
# tag
|
|
249
|
-
full_tag = mo.group(1)
|
|
250
|
-
if not full_tag.startswith(tag_prefix):
|
|
251
|
-
if verbose:
|
|
252
|
-
fmt = "tag '%s' doesn't start with prefix '%s'"
|
|
253
|
-
print(fmt % (full_tag, tag_prefix))
|
|
254
|
-
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
|
|
255
|
-
% (full_tag, tag_prefix))
|
|
256
|
-
return pieces
|
|
257
|
-
pieces["closest-tag"] = full_tag[len(tag_prefix):]
|
|
258
|
-
|
|
259
|
-
# distance: number of commits since tag
|
|
260
|
-
pieces["distance"] = int(mo.group(2))
|
|
261
|
-
|
|
262
|
-
# commit: short hex revision ID
|
|
263
|
-
pieces["short"] = mo.group(3)
|
|
264
|
-
|
|
265
|
-
else:
|
|
266
|
-
# HEX: no tags
|
|
267
|
-
pieces["closest-tag"] = None
|
|
268
|
-
count_out = run_command(GITS, ["rev-list", "HEAD", "--count"],
|
|
269
|
-
cwd=root)
|
|
270
|
-
pieces["distance"] = int(count_out) # total number of commits
|
|
271
|
-
|
|
272
|
-
return pieces
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
def plus_or_dot(pieces):
|
|
276
|
-
"""Return a + if we don't already have one, else return a ."""
|
|
277
|
-
if "+" in pieces.get("closest-tag", ""):
|
|
278
|
-
return "."
|
|
279
|
-
return "+"
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
def render_pep440(pieces):
|
|
283
|
-
"""Build up version string, with post-release "local version identifier".
|
|
284
|
-
|
|
285
|
-
Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
|
|
286
|
-
get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
|
|
287
|
-
|
|
288
|
-
Exceptions:
|
|
289
|
-
1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
|
|
290
|
-
"""
|
|
291
|
-
if pieces["closest-tag"]:
|
|
292
|
-
rendered = pieces["closest-tag"]
|
|
293
|
-
if pieces["distance"] or pieces["dirty"]:
|
|
294
|
-
rendered += plus_or_dot(pieces)
|
|
295
|
-
rendered += "%d.g%s" % (pieces["distance"], pieces["short"])
|
|
296
|
-
if pieces["dirty"]:
|
|
297
|
-
rendered += ".dirty"
|
|
298
|
-
else:
|
|
299
|
-
# exception #1
|
|
300
|
-
rendered = "0+untagged.%d.g%s" % (pieces["distance"],
|
|
301
|
-
pieces["short"])
|
|
302
|
-
if pieces["dirty"]:
|
|
303
|
-
rendered += ".dirty"
|
|
304
|
-
return rendered
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
def render_pep440_pre(pieces):
|
|
308
|
-
"""TAG[.post.devDISTANCE] -- No -dirty.
|
|
309
|
-
|
|
310
|
-
Exceptions:
|
|
311
|
-
1: no tags. 0.post.devDISTANCE
|
|
312
|
-
"""
|
|
313
|
-
if pieces["closest-tag"]:
|
|
314
|
-
rendered = pieces["closest-tag"]
|
|
315
|
-
if pieces["distance"]:
|
|
316
|
-
rendered += ".post.dev%d" % pieces["distance"]
|
|
317
|
-
else:
|
|
318
|
-
# exception #1
|
|
319
|
-
rendered = "0.post.dev%d" % pieces["distance"]
|
|
320
|
-
return rendered
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
def render_pep440_post(pieces):
|
|
324
|
-
"""TAG[.postDISTANCE[.dev0]+gHEX] .
|
|
325
|
-
|
|
326
|
-
The ".dev0" means dirty. Note that .dev0 sorts backwards
|
|
327
|
-
(a dirty tree will appear "older" than the corresponding clean one),
|
|
328
|
-
but you shouldn't be releasing software with -dirty anyways.
|
|
329
|
-
|
|
330
|
-
Exceptions:
|
|
331
|
-
1: no tags. 0.postDISTANCE[.dev0]
|
|
332
|
-
"""
|
|
333
|
-
if pieces["closest-tag"]:
|
|
334
|
-
rendered = pieces["closest-tag"]
|
|
335
|
-
if pieces["distance"] or pieces["dirty"]:
|
|
336
|
-
rendered += ".post%d" % pieces["distance"]
|
|
337
|
-
if pieces["dirty"]:
|
|
338
|
-
rendered += ".dev0"
|
|
339
|
-
rendered += plus_or_dot(pieces)
|
|
340
|
-
rendered += "g%s" % pieces["short"]
|
|
341
|
-
else:
|
|
342
|
-
# exception #1
|
|
343
|
-
rendered = "0.post%d" % pieces["distance"]
|
|
344
|
-
if pieces["dirty"]:
|
|
345
|
-
rendered += ".dev0"
|
|
346
|
-
rendered += "+g%s" % pieces["short"]
|
|
347
|
-
return rendered
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
def render_pep440_old(pieces):
|
|
351
|
-
"""TAG[.postDISTANCE[.dev0]] .
|
|
352
|
-
|
|
353
|
-
The ".dev0" means dirty.
|
|
354
|
-
|
|
355
|
-
Eexceptions:
|
|
356
|
-
1: no tags. 0.postDISTANCE[.dev0]
|
|
357
|
-
"""
|
|
358
|
-
if pieces["closest-tag"]:
|
|
359
|
-
rendered = pieces["closest-tag"]
|
|
360
|
-
if pieces["distance"] or pieces["dirty"]:
|
|
361
|
-
rendered += ".post%d" % pieces["distance"]
|
|
362
|
-
if pieces["dirty"]:
|
|
363
|
-
rendered += ".dev0"
|
|
364
|
-
else:
|
|
365
|
-
# exception #1
|
|
366
|
-
rendered = "0.post%d" % pieces["distance"]
|
|
367
|
-
if pieces["dirty"]:
|
|
368
|
-
rendered += ".dev0"
|
|
369
|
-
return rendered
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
def render_git_describe(pieces):
|
|
373
|
-
"""TAG[-DISTANCE-gHEX][-dirty].
|
|
374
|
-
|
|
375
|
-
Like 'git describe --tags --dirty --always'.
|
|
376
|
-
|
|
377
|
-
Exceptions:
|
|
378
|
-
1: no tags. HEX[-dirty] (note: no 'g' prefix)
|
|
379
|
-
"""
|
|
380
|
-
if pieces["closest-tag"]:
|
|
381
|
-
rendered = pieces["closest-tag"]
|
|
382
|
-
if pieces["distance"]:
|
|
383
|
-
rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
|
|
384
|
-
else:
|
|
385
|
-
# exception #1
|
|
386
|
-
rendered = pieces["short"]
|
|
387
|
-
if pieces["dirty"]:
|
|
388
|
-
rendered += "-dirty"
|
|
389
|
-
return rendered
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
def render_git_describe_long(pieces):
|
|
393
|
-
"""TAG-DISTANCE-gHEX[-dirty].
|
|
394
|
-
|
|
395
|
-
Like 'git describe --tags --dirty --always -long'.
|
|
396
|
-
The distance/hash is unconditional.
|
|
397
|
-
|
|
398
|
-
Exceptions:
|
|
399
|
-
1: no tags. HEX[-dirty] (note: no 'g' prefix)
|
|
400
|
-
"""
|
|
401
|
-
if pieces["closest-tag"]:
|
|
402
|
-
rendered = pieces["closest-tag"]
|
|
403
|
-
rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
|
|
404
|
-
else:
|
|
405
|
-
# exception #1
|
|
406
|
-
rendered = pieces["short"]
|
|
407
|
-
if pieces["dirty"]:
|
|
408
|
-
rendered += "-dirty"
|
|
409
|
-
return rendered
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
def render(pieces, style):
|
|
413
|
-
"""Render the given version pieces into the requested style."""
|
|
414
|
-
if pieces["error"]:
|
|
415
|
-
return {"version": "unknown",
|
|
416
|
-
"full-revisionid": pieces.get("long"),
|
|
417
|
-
"dirty": None,
|
|
418
|
-
"error": pieces["error"]}
|
|
419
|
-
|
|
420
|
-
if not style or style == "default":
|
|
421
|
-
style = "pep440" # the default
|
|
422
|
-
|
|
423
|
-
if style == "pep440":
|
|
424
|
-
rendered = render_pep440(pieces)
|
|
425
|
-
elif style == "pep440-pre":
|
|
426
|
-
rendered = render_pep440_pre(pieces)
|
|
427
|
-
elif style == "pep440-post":
|
|
428
|
-
rendered = render_pep440_post(pieces)
|
|
429
|
-
elif style == "pep440-old":
|
|
430
|
-
rendered = render_pep440_old(pieces)
|
|
431
|
-
elif style == "git-describe":
|
|
432
|
-
rendered = render_git_describe(pieces)
|
|
433
|
-
elif style == "git-describe-long":
|
|
434
|
-
rendered = render_git_describe_long(pieces)
|
|
435
|
-
else:
|
|
436
|
-
raise ValueError("unknown style '%s'" % style)
|
|
437
|
-
|
|
438
|
-
return {"version": rendered, "full-revisionid": pieces["long"],
|
|
439
|
-
"dirty": pieces["dirty"], "error": None}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
def get_versions():
|
|
443
|
-
"""Get version information or return default if unable to do so."""
|
|
444
|
-
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
|
|
445
|
-
# __file__, we can work backwards from there to the root. Some
|
|
446
|
-
# py2exe/bbfreeze/non-CPython implementations don't do __file__, in which
|
|
447
|
-
# case we can only use expanded keywords.
|
|
448
|
-
|
|
449
|
-
cfg = get_config()
|
|
450
|
-
verbose = cfg.verbose
|
|
451
|
-
|
|
452
|
-
try:
|
|
453
|
-
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
|
|
454
|
-
verbose)
|
|
455
|
-
except NotThisMethod:
|
|
456
|
-
pass
|
|
457
|
-
|
|
458
|
-
try:
|
|
459
|
-
root = os.path.realpath(__file__)
|
|
460
|
-
# versionfile_source is the relative path from the top of the source
|
|
461
|
-
# tree (where the .git directory might live) to this file. Invert
|
|
462
|
-
# this to find the root from __file__.
|
|
463
|
-
for i in cfg.versionfile_source.split('/'):
|
|
464
|
-
root = os.path.dirname(root)
|
|
465
|
-
except NameError:
|
|
466
|
-
return {"version": "0+unknown", "full-revisionid": None,
|
|
467
|
-
"dirty": None,
|
|
468
|
-
"error": "unable to find root of source tree"}
|
|
469
|
-
|
|
470
|
-
try:
|
|
471
|
-
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
|
|
472
|
-
return render(pieces, cfg.style)
|
|
473
|
-
except NotThisMethod:
|
|
474
|
-
pass
|
|
475
|
-
|
|
476
|
-
try:
|
|
477
|
-
if cfg.parentdir_prefix:
|
|
478
|
-
return versions_from_parentdir(cfg.parentdir_prefix, root, verbose)
|
|
479
|
-
except NotThisMethod:
|
|
480
|
-
pass
|
|
481
|
-
|
|
482
|
-
return {"version": "0+unknown", "full-revisionid": None,
|
|
483
|
-
"dirty": None,
|
|
484
|
-
"error": "unable to compute version"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|