Get version information or return default if unable to do so.
()
| 641 | |
| 642 | |
| 643 | def get_versions() -> dict: |
| 644 | """Get version information or return default if unable to do so.""" |
| 645 | # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have |
| 646 | # __file__, we can work backwards from there to the root. Some |
| 647 | # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which |
| 648 | # case we can only use expanded keywords. |
| 649 | |
| 650 | cfg = get_config() |
| 651 | verbose = cfg.verbose |
| 652 | |
| 653 | try: |
| 654 | return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose) |
| 655 | except NotThisMethod: |
| 656 | pass |
| 657 | |
| 658 | try: |
| 659 | root = os.path.realpath(__file__) |
| 660 | # versionfile_source is the relative path from the top of the source |
| 661 | # tree (where the .git directory might live) to this file. Invert |
| 662 | # this to find the root from __file__. |
| 663 | for _ in cfg.versionfile_source.split("/"): |
| 664 | root = os.path.dirname(root) |
| 665 | except NameError: |
| 666 | return { |
| 667 | "version": "0+unknown", |
| 668 | "full-revisionid": None, |
| 669 | "dirty": None, |
| 670 | "error": "unable to find root of source tree", |
| 671 | "date": None, |
| 672 | } |
| 673 | |
| 674 | try: |
| 675 | pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose) |
| 676 | return render(pieces, cfg.style) |
| 677 | except NotThisMethod: |
| 678 | pass |
| 679 | |
| 680 | try: |
| 681 | if cfg.parentdir_prefix: |
| 682 | return versions_from_parentdir(cfg.parentdir_prefix, root, verbose) |
| 683 | except NotThisMethod: |
| 684 | pass |
| 685 | |
| 686 | return { |
| 687 | "version": "0+unknown", |
| 688 | "full-revisionid": None, |
| 689 | "dirty": None, |
| 690 | "error": "unable to compute version", |
| 691 | "date": None, |
| 692 | } |
no test coverage detected