Get version information or return default if unable to do so.
()
| 612 | |
| 613 | |
| 614 | def get_versions(): |
| 615 | """Get version information or return default if unable to do so.""" |
| 616 | # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have |
| 617 | # __file__, we can work backwards from there to the root. Some |
| 618 | # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which |
| 619 | # case we can only use expanded keywords. |
| 620 | |
| 621 | cfg = get_config() |
| 622 | verbose = cfg.verbose |
| 623 | |
| 624 | try: |
| 625 | return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, |
| 626 | verbose) |
| 627 | except NotThisMethod: |
| 628 | pass |
| 629 | |
| 630 | try: |
| 631 | root = os.path.realpath(__file__) |
| 632 | # versionfile_source is the relative path from the top of the source |
| 633 | # tree (where the .git directory might live) to this file. Invert |
| 634 | # this to find the root from __file__. |
| 635 | for _ in cfg.versionfile_source.split('/'): |
| 636 | root = os.path.dirname(root) |
| 637 | except NameError: |
| 638 | return {"version": "0+unknown", "full-revisionid": None, |
| 639 | "dirty": None, |
| 640 | "error": "unable to find root of source tree", |
| 641 | "date": None} |
| 642 | |
| 643 | try: |
| 644 | pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose) |
| 645 | return render(pieces, cfg.style) |
| 646 | except NotThisMethod: |
| 647 | pass |
| 648 | |
| 649 | try: |
| 650 | if cfg.parentdir_prefix: |
| 651 | return versions_from_parentdir(cfg.parentdir_prefix, root, verbose) |
| 652 | except NotThisMethod: |
| 653 | pass |
| 654 | |
| 655 | return {"version": "0+unknown", "full-revisionid": None, |
| 656 | "dirty": None, |
| 657 | "error": "unable to compute version", "date": None} |
no test coverage detected
searching dependent graphs…