environment
gitversioned.utils.environment ¶
Build environment introspection utilities.
This module provides tools for extracting hardware, operating system, and Continuous Integration (CI) metadata during the build process. It enables reproducible and traceable builds by automatically capturing runtime context into structured Pydantic models.
BuildEnvironment ¶
Bases: BaseModel
Structured metadata representing the current system and build execution context.
Captures environmental data such as OS details, hardware specs, and CI presence. Utilized to record the provenance of a build artifact for auditing and debugging.
Example: >>> env = BuildEnvironment() >>> print(env.os_system) 'Darwin'
Source code in src/gitversioned/utils/environment.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
__repr__() ¶
Return a detailed string representation.
Source code in src/gitversioned/utils/environment.py
__str__() ¶
Return a concise string representation.
Source code in src/gitversioned/utils/environment.py
get_ci_info() ¶
Determine if the current execution is within a recognized Continuous Integration environment.
Queries standard environment variables to identify platforms like GitHub Actions, GitLab CI, and others.
Example: >>> is_ci, provider = get_ci_info() >>> print(f"CI: {is_ci}, Provider: {provider}") CI: True, Provider: GitHub Actions
Returns:
| Type | Description |
|---|---|
tuple[bool, str | None] | Tuple indicating CI presence and provider name if found. |
Source code in src/gitversioned/utils/environment.py
get_ram_gb() ¶
Calculate the total available system memory in gigabytes.
Relies on psutil if available in the environment.
Example: >>> get_ram_gb() 16.0
Returns:
| Type | Description |
|---|---|
float | The total RAM in GB, or 0.0 if |
Source code in src/gitversioned/utils/environment.py
get_user() ¶
Retrieve the current system or environment user.
Attempts to use standard library OS queries first, falling back to common environment variables.
Example: >>> get_user() 'markkurtz'
Returns:
| Type | Description |
|---|---|
str | The resolved username or "unknown" if undetermined. |