|
7 | 7 | from packaging import version |
8 | 8 | from packaging.version import Version |
9 | 9 |
|
| 10 | +from tomlkit import parse |
| 11 | + |
10 | 12 | from protostar.git import get_git_version, ProtostarGitException |
11 | 13 |
|
12 | 14 | from .protostar_compatibility_with_project_checker import ( |
13 | 15 | ProtostarVersion, |
14 | 16 | parse_protostar_version, |
15 | 17 | ) |
16 | 18 |
|
| 19 | + |
17 | 20 | RuntimeConstantName = Literal["PROTOSTAR_VERSION", "CAIRO_VERSION"] |
18 | 21 | RuntimeConstantValue = str |
19 | 22 | RuntimeConstantsDict = dict[RuntimeConstantName, RuntimeConstantValue] |
@@ -52,6 +55,11 @@ def protostar_cairo1_corelib_path(self) -> Path: |
52 | 55 | assert self.protostar_binary_dir_path is not None |
53 | 56 | return self.protostar_binary_dir_path / "cairo" / "corelib" |
54 | 57 |
|
| 58 | + @property |
| 59 | + def protostar_cairo1_compiler_path(self) -> Path: |
| 60 | + assert self.protostar_binary_dir_path is not None |
| 61 | + return self.protostar_binary_dir_path / "cairo" |
| 62 | + |
55 | 63 | def _read_runtime_constants(self) -> Optional[RuntimeConstantsDict]: |
56 | 64 | constants_str = ( |
57 | 65 | self.info_dir_path / ProtostarDirectory.RUNTIME_CONSTANTS_FILE_NAME |
@@ -109,6 +117,20 @@ def git_version(self) -> Optional[Version]: |
109 | 117 | pass |
110 | 118 | return None |
111 | 119 |
|
| 120 | + @property |
| 121 | + def cairo1_compiler_version(self) -> Optional[Version]: |
| 122 | + try: |
| 123 | + compiler_cargo = ( |
| 124 | + self._protostar_directory.protostar_cairo1_compiler_path / "Cargo.toml" |
| 125 | + ) |
| 126 | + with open(compiler_cargo, "r") as file: |
| 127 | + cargo = parse(file.read()) |
| 128 | + version_str: str = cargo["workspace"]["package"]["version"] # type: ignore |
| 129 | + return version.parse(version_str) |
| 130 | + except BaseException: |
| 131 | + return None |
| 132 | + |
112 | 133 | def print_current_version(self) -> None: |
113 | 134 | print(f"Protostar version: {self.protostar_version or 'unknown'}") |
114 | 135 | print(f"Cairo-lang version: {self.cairo_version or 'unknown'}") |
| 136 | + print(f"Cairo 1 compiler version: {self.cairo1_compiler_version or 'unknown'}") |
0 commit comments