-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python] Create opentitanlib package that contains tool
For now only rom_chip_info is moved, and a copy of version_file.py is included. An entry point is exported that is then used by our bazel build system. Signed-off-by: Amaury Pouly <amaury.pouly@lowrisc.org>
- Loading branch information
Showing
11 changed files
with
429 additions
and
313 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This directory is managed as a python package, imported by | ||
# python-requirements. | ||
# This file is here just to prevent bazel from looking into this repository. |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This directory is managed as a python package, imported by | ||
# python-requirements. | ||
# This file is here just to prevent bazel from looking into this repository. |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[project] | ||
name = "opentitanlib" | ||
version = "0.1.0" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
dependencies = [] | ||
|
||
[project.scripts] | ||
rom_chip_info = "opentitanlib.scripts.rom_chip_info:main" | ||
|
||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["src/opentitanlib"] |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import sys | ||
from typing import Union | ||
|
||
|
||
class VersionInformation(): | ||
def __init__(self, path: str): | ||
""" | ||
Parse a bazel version file and store a dictionary of the values. | ||
If `path` is None, an empty dictionary will be created. | ||
If an error occurs during parsing, an exception is raised. | ||
""" | ||
self.version_stamp = {} | ||
if path is None: | ||
return | ||
try: | ||
with open(path, 'rt') as f: | ||
for line in f: | ||
k, v = line.strip().split(' ', 1) | ||
self.version_stamp[k] = v | ||
except ValueError: | ||
raise SystemExit(sys.exc_info()[1]) | ||
|
||
def scm_version(self, default: Union[str, None] = None) -> Union[str, None]: | ||
return self.version_stamp.get('BUILD_GIT_VERSION', default) | ||
|
||
def scm_revision(self, default: Union[str, None] = None) -> Union[str, None]: | ||
return self.version_stamp.get('BUILD_SCM_REVISION', default) | ||
|
||
def scm_status(self, default: Union[str, None] = None) -> Union[str, None]: | ||
return self.version_stamp.get('BUILD_SCM_STATUS', default) |
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
File renamed without changes.