• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dsavransky / EXOSIMS / 11979115482

22 Nov 2024 07:45PM UTC coverage: 65.499% (-0.2%) from 65.737%
11979115482

Pull #403

github

web-flow
Merge 0d3dd536f into 86cc76cd9
Pull Request #403: Improved version tracking and deprecated SVN

36 of 54 new or added lines in 2 files covered. (66.67%)

43 existing lines in 5 files now uncovered.

9534 of 14556 relevant lines covered (65.5%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.87
/EXOSIMS/util/version_util.py
1
from importlib import metadata
1✔
2
import platform
1✔
3
import subprocess
1✔
4
import os
1✔
5

6

7
def get_git_info():
1✔
8
    """
9
    Get Git information including commit hash and status of changes
10
    """
NEW
11
    try:
×
12
        # Check if we are in a Git repository
NEW
13
        subprocess.run(
×
14
            ["git", "rev-parse"],
15
            stdout=subprocess.PIPE,
16
            stderr=subprocess.PIPE,
17
            check=True,
18
        )
19

20
        # Get the current commit hash
NEW
21
        commit_hash = (
×
22
            subprocess.check_output(["git", "rev-parse", "HEAD"])
23
            .strip()
24
            .decode("utf-8")
25
        )
26

27
        # Check for uncommitted changes
NEW
28
        status = (
×
29
            subprocess.check_output(["git", "status", "--porcelain"])
30
            .strip()
31
            .decode("utf-8")
32
        )
33

NEW
34
        uncommitted_changes = status != ""
×
35

NEW
36
        return commit_hash, uncommitted_changes
×
NEW
37
    except subprocess.CalledProcessError:
×
NEW
38
        return None, False  # Not a Git repository
×
39

40

41
def is_editable_installation():
1✔
42
    """
43
    Check if EXOSIMS is installed in editable mode
44
    """
45
    try:
1✔
46
        # Check if EXOSIMS is installed via pip in editable mode
47
        site_packages = metadata.distribution("EXOSIMS").locate_file("").parent
1✔
48
        editable_marker_file = os.path.join(site_packages, "EXOSIMS.egg-link")
1✔
49
        return os.path.exists(editable_marker_file)
1✔
NEW
50
    except Exception:
×
NEW
51
        return False
×
52

53

54
def get_version():
1✔
55
    """
56
    Retrieve the Python version and EXOSIMS version.
57
    """
58
    python_version = platform.python_version()
1✔
59

60
    exosims_version = metadata.version("EXOSIMS")
1✔
61
    editable = is_editable_installation()
1✔
62

63
    if editable:
1✔
NEW
64
        print("EXOSIMS is installed in editable mode")
×
NEW
65
        exosims_version = f"{exosims_version} (editable"
×
NEW
66
        commit_hash, uncommitted_changes = get_git_info()
×
NEW
67
        if commit_hash is not None:
×
NEW
68
            exosims_version = f"{exosims_version} / commit {commit_hash}"
×
NEW
69
        if uncommitted_changes:
×
NEW
70
            exosims_version = f"{exosims_version} / warning! uncommited changes"
×
NEW
71
        exosims_version = f"{exosims_version})"
×
72
    else:
73
        exosims_version = f"{exosims_version} (not editable)"
1✔
74

75
    reqs = metadata.distribution("EXOSIMS").requires
1✔
76
    required_packages = [str(req) for req in reqs]
1✔
77

78
    # Get installed versions of required packages
79
    installed_packages = {
1✔
80
        dist.metadata["Name"]: dist.version for dist in metadata.distributions()
81
    }
82

83
    # Filter installed packages to those listed in requirements
84
    relevant_packages = {
1✔
85
        pkg: installed_packages.get(pkg.split(">=")[0], "Not installed")
86
        for pkg in required_packages
87
    }
88

89
    return {
1✔
90
        "Python": python_version,
91
        "EXOSIMS": exosims_version,
92
        "Packages": relevant_packages,
93
    }
94

95

96
version_info = get_version()
1✔
97
for key, value in version_info.items():
1✔
98
    if isinstance(value, dict):
1✔
99
        print(f"{key}:")
1✔
100
        for sub_key, sub_value in value.items():
1✔
101
            print(f"  {sub_key}:".ljust(25) + f"{sub_value}")
1✔
102
    else:
103
        print(f"{key}:".ljust(25) + f"{value}")
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc