()
| 417 | |
| 418 | |
| 419 | def get_versions(): |
| 420 | # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have |
| 421 | # __file__, we can work backwards from there to the root. Some |
| 422 | # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which |
| 423 | # case we can only use expanded keywords. |
| 424 | |
| 425 | cfg = get_config() |
| 426 | verbose = cfg.verbose |
| 427 | |
| 428 | try: |
| 429 | return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, |
| 430 | verbose) |
| 431 | except NotThisMethod: |
| 432 | pass |
| 433 | |
| 434 | try: |
| 435 | root = os.path.realpath(__file__) |
| 436 | # versionfile_source is the relative path from the top of the source |
| 437 | # tree (where the .git directory might live) to this file. Invert |
| 438 | # this to find the root from __file__. |
| 439 | for i in cfg.versionfile_source.split('/'): |
| 440 | root = os.path.dirname(root) |
| 441 | except NameError: |
| 442 | return {"version": "0+unknown", "full-revisionid": None, |
| 443 | "dirty": None, |
| 444 | "error": "unable to find root of source tree"} |
| 445 | |
| 446 | try: |
| 447 | pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose) |
| 448 | return render(pieces, cfg.style) |
| 449 | except NotThisMethod: |
| 450 | pass |
| 451 | |
| 452 | try: |
| 453 | if cfg.parentdir_prefix: |
| 454 | return versions_from_parentdir(cfg.parentdir_prefix, root, verbose) |
| 455 | except NotThisMethod: |
| 456 | pass |
| 457 | |
| 458 | return {"version": "0+unknown", "full-revisionid": None, |
| 459 | "dirty": None, |
| 460 | "error": "unable to compute version"} |
no test coverage detected