-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
5 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,3 @@ | ||
import os | ||
import toml | ||
import importlib.metadata | ||
|
||
|
||
def get_version(): | ||
return get_version_from_toml_file() | ||
|
||
|
||
def get_version_from_toml_file( | ||
pyproject_path=os.path.join( | ||
os.path.dirname(__file__), '..', '..', 'pyproject.toml' | ||
) | ||
): | ||
version = (0, 0, 0) | ||
|
||
try: | ||
with open(pyproject_path, 'r') as file: | ||
pyproject_data = toml.load(file) | ||
except FileNotFoundError: | ||
raise FileNotFoundError( | ||
f"The pyproject.toml file was not found at {pyproject_path}" | ||
) | ||
|
||
# Access the version information from the parsed data | ||
if pyproject_data: | ||
version_info = pyproject_data.get('tool', {}).get('poetry', {}).get( | ||
'version', '0.0.0') | ||
try: | ||
version = tuple(map(int, version_info.split('.'))) | ||
except ValueError: | ||
raise ValueError( | ||
f"The pyproject.toml file has an invalid " | ||
f"version number: {version_info}" | ||
) | ||
|
||
return version | ||
__version__ = importlib.metadata.version("copilot") |