xoscar 0.9.0__cp312-cp312-macosx_10_13_x86_64.whl

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.
Files changed (94) hide show
  1. xoscar/__init__.py +61 -0
  2. xoscar/_utils.cpython-312-darwin.so +0 -0
  3. xoscar/_utils.pxd +36 -0
  4. xoscar/_utils.pyx +246 -0
  5. xoscar/_version.py +693 -0
  6. xoscar/aio/__init__.py +16 -0
  7. xoscar/aio/base.py +86 -0
  8. xoscar/aio/file.py +59 -0
  9. xoscar/aio/lru.py +228 -0
  10. xoscar/aio/parallelism.py +39 -0
  11. xoscar/api.py +527 -0
  12. xoscar/backend.py +67 -0
  13. xoscar/backends/__init__.py +14 -0
  14. xoscar/backends/allocate_strategy.py +160 -0
  15. xoscar/backends/communication/__init__.py +30 -0
  16. xoscar/backends/communication/base.py +315 -0
  17. xoscar/backends/communication/core.py +69 -0
  18. xoscar/backends/communication/dummy.py +253 -0
  19. xoscar/backends/communication/errors.py +20 -0
  20. xoscar/backends/communication/socket.py +444 -0
  21. xoscar/backends/communication/ucx.py +538 -0
  22. xoscar/backends/communication/utils.py +97 -0
  23. xoscar/backends/config.py +157 -0
  24. xoscar/backends/context.py +437 -0
  25. xoscar/backends/core.py +352 -0
  26. xoscar/backends/indigen/__init__.py +16 -0
  27. xoscar/backends/indigen/__main__.py +19 -0
  28. xoscar/backends/indigen/backend.py +51 -0
  29. xoscar/backends/indigen/driver.py +26 -0
  30. xoscar/backends/indigen/fate_sharing.py +221 -0
  31. xoscar/backends/indigen/pool.py +515 -0
  32. xoscar/backends/indigen/shared_memory.py +548 -0
  33. xoscar/backends/message.cpython-312-darwin.so +0 -0
  34. xoscar/backends/message.pyi +255 -0
  35. xoscar/backends/message.pyx +646 -0
  36. xoscar/backends/pool.py +1630 -0
  37. xoscar/backends/router.py +285 -0
  38. xoscar/backends/test/__init__.py +16 -0
  39. xoscar/backends/test/backend.py +38 -0
  40. xoscar/backends/test/pool.py +233 -0
  41. xoscar/batch.py +256 -0
  42. xoscar/collective/__init__.py +27 -0
  43. xoscar/collective/backend/__init__.py +13 -0
  44. xoscar/collective/backend/nccl_backend.py +160 -0
  45. xoscar/collective/common.py +102 -0
  46. xoscar/collective/core.py +737 -0
  47. xoscar/collective/process_group.py +687 -0
  48. xoscar/collective/utils.py +41 -0
  49. xoscar/collective/xoscar_pygloo.cpython-312-darwin.so +0 -0
  50. xoscar/collective/xoscar_pygloo.pyi +239 -0
  51. xoscar/constants.py +23 -0
  52. xoscar/context.cpython-312-darwin.so +0 -0
  53. xoscar/context.pxd +21 -0
  54. xoscar/context.pyx +368 -0
  55. xoscar/core.cpython-312-darwin.so +0 -0
  56. xoscar/core.pxd +51 -0
  57. xoscar/core.pyx +664 -0
  58. xoscar/debug.py +188 -0
  59. xoscar/driver.py +42 -0
  60. xoscar/errors.py +63 -0
  61. xoscar/libcpp.pxd +31 -0
  62. xoscar/metrics/__init__.py +21 -0
  63. xoscar/metrics/api.py +288 -0
  64. xoscar/metrics/backends/__init__.py +13 -0
  65. xoscar/metrics/backends/console/__init__.py +13 -0
  66. xoscar/metrics/backends/console/console_metric.py +82 -0
  67. xoscar/metrics/backends/metric.py +149 -0
  68. xoscar/metrics/backends/prometheus/__init__.py +13 -0
  69. xoscar/metrics/backends/prometheus/prometheus_metric.py +70 -0
  70. xoscar/nvutils.py +717 -0
  71. xoscar/profiling.py +260 -0
  72. xoscar/serialization/__init__.py +20 -0
  73. xoscar/serialization/aio.py +141 -0
  74. xoscar/serialization/core.cpython-312-darwin.so +0 -0
  75. xoscar/serialization/core.pxd +28 -0
  76. xoscar/serialization/core.pyi +57 -0
  77. xoscar/serialization/core.pyx +944 -0
  78. xoscar/serialization/cuda.py +111 -0
  79. xoscar/serialization/exception.py +48 -0
  80. xoscar/serialization/mlx.py +67 -0
  81. xoscar/serialization/numpy.py +82 -0
  82. xoscar/serialization/pyfury.py +37 -0
  83. xoscar/serialization/scipy.py +72 -0
  84. xoscar/serialization/torch.py +180 -0
  85. xoscar/utils.py +522 -0
  86. xoscar/virtualenv/__init__.py +34 -0
  87. xoscar/virtualenv/core.py +268 -0
  88. xoscar/virtualenv/platform.py +56 -0
  89. xoscar/virtualenv/utils.py +100 -0
  90. xoscar/virtualenv/uv.py +321 -0
  91. xoscar-0.9.0.dist-info/METADATA +230 -0
  92. xoscar-0.9.0.dist-info/RECORD +94 -0
  93. xoscar-0.9.0.dist-info/WHEEL +6 -0
  94. xoscar-0.9.0.dist-info/top_level.txt +2 -0
xoscar/_version.py ADDED
@@ -0,0 +1,693 @@
1
+ # This file helps to compute a version number in source trees obtained from
2
+ # git-archive tarball (such as those provided by githubs download-from-tag
3
+ # feature). Distribution tarballs (built by setup.py sdist) and build
4
+ # directories (produced by setup.py build) will contain a much shorter file
5
+ # that just contains the computed version number.
6
+
7
+ # This file is released into the public domain.
8
+ # Generated by versioneer-0.28
9
+ # https://github.com/python-versioneer/python-versioneer
10
+
11
+ """Git implementation of _version.py."""
12
+
13
+ import errno
14
+ import functools
15
+ import os
16
+ import re
17
+ import subprocess
18
+ import sys
19
+ from typing import Callable, Dict
20
+
21
+
22
+ def get_keywords():
23
+ """Get the keywords needed to look up the version information."""
24
+ # these strings will be replaced by git during git-archive.
25
+ # setup.py/versioneer.py will grep for the variable names, so they must
26
+ # each be defined on a line of their own. _version.py will just call
27
+ # get_keywords().
28
+ git_refnames = "$Format:%d$"
29
+ git_full = "$Format:%H$"
30
+ git_date = "$Format:%ci$"
31
+ keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
32
+ return keywords
33
+
34
+
35
+ class VersioneerConfig:
36
+ """Container for Versioneer configuration parameters."""
37
+
38
+
39
+ def get_config():
40
+ """Create, populate and return the VersioneerConfig() object."""
41
+ # these strings are filled in when 'setup.py versioneer' creates
42
+ # _version.py
43
+ cfg = VersioneerConfig()
44
+ cfg.VCS = "git"
45
+ cfg.style = "pep440"
46
+ cfg.tag_prefix = "v"
47
+ cfg.parentdir_prefix = "xoscar-"
48
+ cfg.versionfile_source = "xoscar/_version.py"
49
+ cfg.verbose = False
50
+ return cfg
51
+
52
+
53
+ class NotThisMethod(Exception):
54
+ """Exception raised if a method is not valid for the current scenario."""
55
+
56
+
57
+ LONG_VERSION_PY: Dict[str, str] = {}
58
+ HANDLERS: Dict[str, Dict[str, Callable]] = {}
59
+
60
+
61
+ def register_vcs_handler(vcs, method): # decorator
62
+ """Create decorator to mark a method as the handler of a VCS."""
63
+
64
+ def decorate(f):
65
+ """Store f in HANDLERS[vcs][method]."""
66
+ if vcs not in HANDLERS:
67
+ HANDLERS[vcs] = {}
68
+ HANDLERS[vcs][method] = f
69
+ return f
70
+
71
+ return decorate
72
+
73
+
74
+ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None):
75
+ """Call the given command(s)."""
76
+ assert isinstance(commands, list)
77
+ process = None
78
+
79
+ popen_kwargs = {}
80
+ if sys.platform == "win32":
81
+ # This hides the console window if pythonw.exe is used
82
+ startupinfo = subprocess.STARTUPINFO()
83
+ startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
84
+ popen_kwargs["startupinfo"] = startupinfo
85
+
86
+ for command in commands:
87
+ try:
88
+ dispcmd = str([command] + args)
89
+ # remember shell=False, so use git.cmd on windows, not just git
90
+ process = subprocess.Popen(
91
+ [command] + args,
92
+ cwd=cwd,
93
+ env=env,
94
+ stdout=subprocess.PIPE,
95
+ stderr=(subprocess.PIPE if hide_stderr else None),
96
+ **popen_kwargs,
97
+ )
98
+ break
99
+ except OSError:
100
+ e = sys.exc_info()[1]
101
+ if e.errno == errno.ENOENT:
102
+ continue
103
+ if verbose:
104
+ print("unable to run %s" % dispcmd)
105
+ print(e)
106
+ return None, None
107
+ else:
108
+ if verbose:
109
+ print("unable to find command, tried %s" % (commands,))
110
+ return None, None
111
+ stdout = process.communicate()[0].strip().decode()
112
+ if process.returncode != 0:
113
+ if verbose:
114
+ print("unable to run %s (error)" % dispcmd)
115
+ print("stdout was %s" % stdout)
116
+ return None, process.returncode
117
+ return stdout, process.returncode
118
+
119
+
120
+ def versions_from_parentdir(parentdir_prefix, root, verbose):
121
+ """Try to determine the version from the parent directory name.
122
+
123
+ Source tarballs conventionally unpack into a directory that includes both
124
+ the project name and a version string. We will also support searching up
125
+ two directory levels for an appropriately named parent directory
126
+ """
127
+ rootdirs = []
128
+
129
+ for _ in range(3):
130
+ dirname = os.path.basename(root)
131
+ if dirname.startswith(parentdir_prefix):
132
+ return {
133
+ "version": dirname[len(parentdir_prefix) :],
134
+ "full-revisionid": None,
135
+ "dirty": False,
136
+ "error": None,
137
+ "date": None,
138
+ }
139
+ rootdirs.append(root)
140
+ root = os.path.dirname(root) # up a level
141
+
142
+ if verbose:
143
+ print(
144
+ "Tried directories %s but none started with prefix %s"
145
+ % (str(rootdirs), parentdir_prefix)
146
+ )
147
+ raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
148
+
149
+
150
+ @register_vcs_handler("git", "get_keywords")
151
+ def git_get_keywords(versionfile_abs):
152
+ """Extract version information from the given file."""
153
+ # the code embedded in _version.py can just fetch the value of these
154
+ # keywords. When used from setup.py, we don't want to import _version.py,
155
+ # so we do it with a regexp instead. This function is not used from
156
+ # _version.py.
157
+ keywords = {}
158
+ try:
159
+ with open(versionfile_abs, "r") as fobj:
160
+ for line in fobj:
161
+ if line.strip().startswith("git_refnames ="):
162
+ mo = re.search(r'=\s*"(.*)"', line)
163
+ if mo:
164
+ keywords["refnames"] = mo.group(1)
165
+ if line.strip().startswith("git_full ="):
166
+ mo = re.search(r'=\s*"(.*)"', line)
167
+ if mo:
168
+ keywords["full"] = mo.group(1)
169
+ if line.strip().startswith("git_date ="):
170
+ mo = re.search(r'=\s*"(.*)"', line)
171
+ if mo:
172
+ keywords["date"] = mo.group(1)
173
+ except OSError:
174
+ pass
175
+ return keywords
176
+
177
+
178
+ @register_vcs_handler("git", "keywords")
179
+ def git_versions_from_keywords(keywords, tag_prefix, verbose):
180
+ """Get version information from git keywords."""
181
+ if "refnames" not in keywords:
182
+ raise NotThisMethod("Short version file found")
183
+ date = keywords.get("date")
184
+ if date is not None:
185
+ # Use only the last line. Previous lines may contain GPG signature
186
+ # information.
187
+ date = date.splitlines()[-1]
188
+
189
+ # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
190
+ # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
191
+ # -like" string, which we must then edit to make compliant), because
192
+ # it's been around since git-1.5.3, and it's too difficult to
193
+ # discover which version we're using, or to work around using an
194
+ # older one.
195
+ date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
196
+ refnames = keywords["refnames"].strip()
197
+ if refnames.startswith("$Format"):
198
+ if verbose:
199
+ print("keywords are unexpanded, not using")
200
+ raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
201
+ refs = {r.strip() for r in refnames.strip("()").split(",")}
202
+ # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
203
+ # just "foo-1.0". If we see a "tag: " prefix, prefer those.
204
+ TAG = "tag: "
205
+ tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
206
+ if not tags:
207
+ # Either we're using git < 1.8.3, or there really are no tags. We use
208
+ # a heuristic: assume all version tags have a digit. The old git %d
209
+ # expansion behaves like git log --decorate=short and strips out the
210
+ # refs/heads/ and refs/tags/ prefixes that would let us distinguish
211
+ # between branches and tags. By ignoring refnames without digits, we
212
+ # filter out many common branch names like "release" and
213
+ # "stabilization", as well as "HEAD" and "master".
214
+ tags = {r for r in refs if re.search(r"\d", r)}
215
+ if verbose:
216
+ print("discarding '%s', no digits" % ",".join(refs - tags))
217
+ if verbose:
218
+ print("likely tags: %s" % ",".join(sorted(tags)))
219
+ for ref in sorted(tags):
220
+ # sorting will prefer e.g. "2.0" over "2.0rc1"
221
+ if ref.startswith(tag_prefix):
222
+ r = ref[len(tag_prefix) :]
223
+ # Filter out refs that exactly match prefix or that don't start
224
+ # with a number once the prefix is stripped (mostly a concern
225
+ # when prefix is '')
226
+ if not re.match(r"\d", r):
227
+ continue
228
+ if verbose:
229
+ print("picking %s" % r)
230
+ return {
231
+ "version": r,
232
+ "full-revisionid": keywords["full"].strip(),
233
+ "dirty": False,
234
+ "error": None,
235
+ "date": date,
236
+ }
237
+ # no suitable tags, so version is "0+unknown", but full hex is still there
238
+ if verbose:
239
+ print("no suitable tags, using unknown + full revision id")
240
+ return {
241
+ "version": "0+unknown",
242
+ "full-revisionid": keywords["full"].strip(),
243
+ "dirty": False,
244
+ "error": "no suitable tags",
245
+ "date": None,
246
+ }
247
+
248
+
249
+ @register_vcs_handler("git", "pieces_from_vcs")
250
+ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
251
+ """Get version from 'git describe' in the root of the source tree.
252
+
253
+ This only gets called if the git-archive 'subst' keywords were *not*
254
+ expanded, and _version.py hasn't already been rewritten with a short
255
+ version string, meaning we're inside a checked out source tree.
256
+ """
257
+ GITS = ["git"]
258
+ if sys.platform == "win32":
259
+ GITS = ["git.cmd", "git.exe"]
260
+
261
+ # GIT_DIR can interfere with correct operation of Versioneer.
262
+ # It may be intended to be passed to the Versioneer-versioned project,
263
+ # but that should not change where we get our version from.
264
+ env = os.environ.copy()
265
+ env.pop("GIT_DIR", None)
266
+ runner = functools.partial(runner, env=env)
267
+
268
+ _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=not verbose)
269
+ if rc != 0:
270
+ if verbose:
271
+ print("Directory %s not under git control" % root)
272
+ raise NotThisMethod("'git rev-parse --git-dir' returned error")
273
+
274
+ # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
275
+ # if there isn't one, this yields HEX[-dirty] (no NUM)
276
+ describe_out, rc = runner(
277
+ GITS,
278
+ [
279
+ "describe",
280
+ "--tags",
281
+ "--dirty",
282
+ "--always",
283
+ "--long",
284
+ "--match",
285
+ f"{tag_prefix}[[:digit:]]*",
286
+ ],
287
+ cwd=root,
288
+ )
289
+ # --long was added in git-1.5.5
290
+ if describe_out is None:
291
+ raise NotThisMethod("'git describe' failed")
292
+ describe_out = describe_out.strip()
293
+ full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root)
294
+ if full_out is None:
295
+ raise NotThisMethod("'git rev-parse' failed")
296
+ full_out = full_out.strip()
297
+
298
+ pieces = {}
299
+ pieces["long"] = full_out
300
+ pieces["short"] = full_out[:7] # maybe improved later
301
+ pieces["error"] = None
302
+
303
+ branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], cwd=root)
304
+ # --abbrev-ref was added in git-1.6.3
305
+ if rc != 0 or branch_name is None:
306
+ raise NotThisMethod("'git rev-parse --abbrev-ref' returned error")
307
+ branch_name = branch_name.strip()
308
+
309
+ if branch_name == "HEAD":
310
+ # If we aren't exactly on a branch, pick a branch which represents
311
+ # the current commit. If all else fails, we are on a branchless
312
+ # commit.
313
+ branches, rc = runner(GITS, ["branch", "--contains"], cwd=root)
314
+ # --contains was added in git-1.5.4
315
+ if rc != 0 or branches is None:
316
+ raise NotThisMethod("'git branch --contains' returned error")
317
+ branches = branches.split("\n")
318
+
319
+ # Remove the first line if we're running detached
320
+ if "(" in branches[0]:
321
+ branches.pop(0)
322
+
323
+ # Strip off the leading "* " from the list of branches.
324
+ branches = [branch[2:] for branch in branches]
325
+ if "master" in branches:
326
+ branch_name = "master"
327
+ elif not branches:
328
+ branch_name = None
329
+ else:
330
+ # Pick the first branch that is returned. Good or bad.
331
+ branch_name = branches[0]
332
+
333
+ pieces["branch"] = branch_name
334
+
335
+ # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
336
+ # TAG might have hyphens.
337
+ git_describe = describe_out
338
+
339
+ # look for -dirty suffix
340
+ dirty = git_describe.endswith("-dirty")
341
+ pieces["dirty"] = dirty
342
+ if dirty:
343
+ git_describe = git_describe[: git_describe.rindex("-dirty")]
344
+
345
+ # now we have TAG-NUM-gHEX or HEX
346
+
347
+ if "-" in git_describe:
348
+ # TAG-NUM-gHEX
349
+ mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
350
+ if not mo:
351
+ # unparsable. Maybe git-describe is misbehaving?
352
+ pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
353
+ return pieces
354
+
355
+ # tag
356
+ full_tag = mo.group(1)
357
+ if not full_tag.startswith(tag_prefix):
358
+ if verbose:
359
+ fmt = "tag '%s' doesn't start with prefix '%s'"
360
+ print(fmt % (full_tag, tag_prefix))
361
+ pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
362
+ full_tag,
363
+ tag_prefix,
364
+ )
365
+ return pieces
366
+ pieces["closest-tag"] = full_tag[len(tag_prefix) :]
367
+
368
+ # distance: number of commits since tag
369
+ pieces["distance"] = int(mo.group(2))
370
+
371
+ # commit: short hex revision ID
372
+ pieces["short"] = mo.group(3)
373
+
374
+ else:
375
+ # HEX: no tags
376
+ pieces["closest-tag"] = None
377
+ out, rc = runner(GITS, ["rev-list", "HEAD", "--left-right"], cwd=root)
378
+ pieces["distance"] = len(out.split()) # total number of commits
379
+
380
+ # commit date: see ISO-8601 comment in git_versions_from_keywords()
381
+ date = runner(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip()
382
+ # Use only the last line. Previous lines may contain GPG signature
383
+ # information.
384
+ date = date.splitlines()[-1]
385
+ pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
386
+
387
+ return pieces
388
+
389
+
390
+ def plus_or_dot(pieces):
391
+ """Return a + if we don't already have one, else return a ."""
392
+ if "+" in pieces.get("closest-tag", ""):
393
+ return "."
394
+ return "+"
395
+
396
+
397
+ def render_pep440(pieces):
398
+ """Build up version string, with post-release "local version identifier".
399
+
400
+ Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
401
+ get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
402
+
403
+ Exceptions:
404
+ 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
405
+ """
406
+ if pieces["closest-tag"]:
407
+ rendered = pieces["closest-tag"]
408
+ if pieces["distance"] or pieces["dirty"]:
409
+ rendered += plus_or_dot(pieces)
410
+ rendered += "%d.g%s" % (pieces["distance"], pieces["short"])
411
+ if pieces["dirty"]:
412
+ rendered += ".dirty"
413
+ else:
414
+ # exception #1
415
+ rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
416
+ if pieces["dirty"]:
417
+ rendered += ".dirty"
418
+ return rendered
419
+
420
+
421
+ def render_pep440_branch(pieces):
422
+ """TAG[[.dev0]+DISTANCE.gHEX[.dirty]] .
423
+
424
+ The ".dev0" means not master branch. Note that .dev0 sorts backwards
425
+ (a feature branch will appear "older" than the master branch).
426
+
427
+ Exceptions:
428
+ 1: no tags. 0[.dev0]+untagged.DISTANCE.gHEX[.dirty]
429
+ """
430
+ if pieces["closest-tag"]:
431
+ rendered = pieces["closest-tag"]
432
+ if pieces["distance"] or pieces["dirty"]:
433
+ if pieces["branch"] != "master":
434
+ rendered += ".dev0"
435
+ rendered += plus_or_dot(pieces)
436
+ rendered += "%d.g%s" % (pieces["distance"], pieces["short"])
437
+ if pieces["dirty"]:
438
+ rendered += ".dirty"
439
+ else:
440
+ # exception #1
441
+ rendered = "0"
442
+ if pieces["branch"] != "master":
443
+ rendered += ".dev0"
444
+ rendered += "+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
445
+ if pieces["dirty"]:
446
+ rendered += ".dirty"
447
+ return rendered
448
+
449
+
450
+ def pep440_split_post(ver):
451
+ """Split pep440 version string at the post-release segment.
452
+
453
+ Returns the release segments before the post-release and the
454
+ post-release version number (or -1 if no post-release segment is present).
455
+ """
456
+ vc = str.split(ver, ".post")
457
+ return vc[0], int(vc[1] or 0) if len(vc) == 2 else None
458
+
459
+
460
+ def render_pep440_pre(pieces):
461
+ """TAG[.postN.devDISTANCE] -- No -dirty.
462
+
463
+ Exceptions:
464
+ 1: no tags. 0.post0.devDISTANCE
465
+ """
466
+ if pieces["closest-tag"]:
467
+ if pieces["distance"]:
468
+ # update the post release segment
469
+ tag_version, post_version = pep440_split_post(pieces["closest-tag"])
470
+ rendered = tag_version
471
+ if post_version is not None:
472
+ rendered += ".post%d.dev%d" % (post_version + 1, pieces["distance"])
473
+ else:
474
+ rendered += ".post0.dev%d" % (pieces["distance"])
475
+ else:
476
+ # no commits, use the tag as the version
477
+ rendered = pieces["closest-tag"]
478
+ else:
479
+ # exception #1
480
+ rendered = "0.post0.dev%d" % pieces["distance"]
481
+ return rendered
482
+
483
+
484
+ def render_pep440_post(pieces):
485
+ """TAG[.postDISTANCE[.dev0]+gHEX] .
486
+
487
+ The ".dev0" means dirty. Note that .dev0 sorts backwards
488
+ (a dirty tree will appear "older" than the corresponding clean one),
489
+ but you shouldn't be releasing software with -dirty anyways.
490
+
491
+ Exceptions:
492
+ 1: no tags. 0.postDISTANCE[.dev0]
493
+ """
494
+ if pieces["closest-tag"]:
495
+ rendered = pieces["closest-tag"]
496
+ if pieces["distance"] or pieces["dirty"]:
497
+ rendered += ".post%d" % pieces["distance"]
498
+ if pieces["dirty"]:
499
+ rendered += ".dev0"
500
+ rendered += plus_or_dot(pieces)
501
+ rendered += "g%s" % pieces["short"]
502
+ else:
503
+ # exception #1
504
+ rendered = "0.post%d" % pieces["distance"]
505
+ if pieces["dirty"]:
506
+ rendered += ".dev0"
507
+ rendered += "+g%s" % pieces["short"]
508
+ return rendered
509
+
510
+
511
+ def render_pep440_post_branch(pieces):
512
+ """TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] .
513
+
514
+ The ".dev0" means not master branch.
515
+
516
+ Exceptions:
517
+ 1: no tags. 0.postDISTANCE[.dev0]+gHEX[.dirty]
518
+ """
519
+ if pieces["closest-tag"]:
520
+ rendered = pieces["closest-tag"]
521
+ if pieces["distance"] or pieces["dirty"]:
522
+ rendered += ".post%d" % pieces["distance"]
523
+ if pieces["branch"] != "master":
524
+ rendered += ".dev0"
525
+ rendered += plus_or_dot(pieces)
526
+ rendered += "g%s" % pieces["short"]
527
+ if pieces["dirty"]:
528
+ rendered += ".dirty"
529
+ else:
530
+ # exception #1
531
+ rendered = "0.post%d" % pieces["distance"]
532
+ if pieces["branch"] != "master":
533
+ rendered += ".dev0"
534
+ rendered += "+g%s" % pieces["short"]
535
+ if pieces["dirty"]:
536
+ rendered += ".dirty"
537
+ return rendered
538
+
539
+
540
+ def render_pep440_old(pieces):
541
+ """TAG[.postDISTANCE[.dev0]] .
542
+
543
+ The ".dev0" means dirty.
544
+
545
+ Exceptions:
546
+ 1: no tags. 0.postDISTANCE[.dev0]
547
+ """
548
+ if pieces["closest-tag"]:
549
+ rendered = pieces["closest-tag"]
550
+ if pieces["distance"] or pieces["dirty"]:
551
+ rendered += ".post%d" % pieces["distance"]
552
+ if pieces["dirty"]:
553
+ rendered += ".dev0"
554
+ else:
555
+ # exception #1
556
+ rendered = "0.post%d" % pieces["distance"]
557
+ if pieces["dirty"]:
558
+ rendered += ".dev0"
559
+ return rendered
560
+
561
+
562
+ def render_git_describe(pieces):
563
+ """TAG[-DISTANCE-gHEX][-dirty].
564
+
565
+ Like 'git describe --tags --dirty --always'.
566
+
567
+ Exceptions:
568
+ 1: no tags. HEX[-dirty] (note: no 'g' prefix)
569
+ """
570
+ if pieces["closest-tag"]:
571
+ rendered = pieces["closest-tag"]
572
+ if pieces["distance"]:
573
+ rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
574
+ else:
575
+ # exception #1
576
+ rendered = pieces["short"]
577
+ if pieces["dirty"]:
578
+ rendered += "-dirty"
579
+ return rendered
580
+
581
+
582
+ def render_git_describe_long(pieces):
583
+ """TAG-DISTANCE-gHEX[-dirty].
584
+
585
+ Like 'git describe --tags --dirty --always -long'.
586
+ The distance/hash is unconditional.
587
+
588
+ Exceptions:
589
+ 1: no tags. HEX[-dirty] (note: no 'g' prefix)
590
+ """
591
+ if pieces["closest-tag"]:
592
+ rendered = pieces["closest-tag"]
593
+ rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
594
+ else:
595
+ # exception #1
596
+ rendered = pieces["short"]
597
+ if pieces["dirty"]:
598
+ rendered += "-dirty"
599
+ return rendered
600
+
601
+
602
+ def render(pieces, style):
603
+ """Render the given version pieces into the requested style."""
604
+ if pieces["error"]:
605
+ return {
606
+ "version": "unknown",
607
+ "full-revisionid": pieces.get("long"),
608
+ "dirty": None,
609
+ "error": pieces["error"],
610
+ "date": None,
611
+ }
612
+
613
+ if not style or style == "default":
614
+ style = "pep440" # the default
615
+
616
+ if style == "pep440":
617
+ rendered = render_pep440(pieces)
618
+ elif style == "pep440-branch":
619
+ rendered = render_pep440_branch(pieces)
620
+ elif style == "pep440-pre":
621
+ rendered = render_pep440_pre(pieces)
622
+ elif style == "pep440-post":
623
+ rendered = render_pep440_post(pieces)
624
+ elif style == "pep440-post-branch":
625
+ rendered = render_pep440_post_branch(pieces)
626
+ elif style == "pep440-old":
627
+ rendered = render_pep440_old(pieces)
628
+ elif style == "git-describe":
629
+ rendered = render_git_describe(pieces)
630
+ elif style == "git-describe-long":
631
+ rendered = render_git_describe_long(pieces)
632
+ else:
633
+ raise ValueError("unknown style '%s'" % style)
634
+
635
+ return {
636
+ "version": rendered,
637
+ "full-revisionid": pieces["long"],
638
+ "dirty": pieces["dirty"],
639
+ "error": None,
640
+ "date": pieces.get("date"),
641
+ }
642
+
643
+
644
+ def get_versions():
645
+ """Get version information or return default if unable to do so."""
646
+ # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
647
+ # __file__, we can work backwards from there to the root. Some
648
+ # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which
649
+ # case we can only use expanded keywords.
650
+
651
+ cfg = get_config()
652
+ verbose = cfg.verbose
653
+
654
+ try:
655
+ return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
656
+ except NotThisMethod:
657
+ pass
658
+
659
+ try:
660
+ root = os.path.realpath(__file__)
661
+ # versionfile_source is the relative path from the top of the source
662
+ # tree (where the .git directory might live) to this file. Invert
663
+ # this to find the root from __file__.
664
+ for _ in cfg.versionfile_source.split("/"):
665
+ root = os.path.dirname(root)
666
+ except NameError:
667
+ return {
668
+ "version": "0+unknown",
669
+ "full-revisionid": None,
670
+ "dirty": None,
671
+ "error": "unable to find root of source tree",
672
+ "date": None,
673
+ }
674
+
675
+ try:
676
+ pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
677
+ return render(pieces, cfg.style)
678
+ except NotThisMethod:
679
+ pass
680
+
681
+ try:
682
+ if cfg.parentdir_prefix:
683
+ return versions_from_parentdir(cfg.parentdir_prefix, root, verbose)
684
+ except NotThisMethod:
685
+ pass
686
+
687
+ return {
688
+ "version": "0+unknown",
689
+ "full-revisionid": None,
690
+ "dirty": None,
691
+ "error": "unable to compute version",
692
+ "date": None,
693
+ }