Creates a file similar to PyTorch core's `torch/version.py`.
(cls, path: str)
| 156 | |
| 157 | @classmethod |
| 158 | def write_to_python_file(cls, path: str) -> None: |
| 159 | """Creates a file similar to PyTorch core's `torch/version.py`.""" |
| 160 | |
| 161 | lines = [ |
| 162 | "from typing import Optional", |
| 163 | '__all__ = ["__version__", "git_version"]', |
| 164 | f'__version__ = "{cls.string()}"', |
| 165 | # A string or None. |
| 166 | f"git_version: Optional[str] = {repr(cls.git_hash())}", |
| 167 | ] |
| 168 | with open(path, "w") as fp: |
| 169 | fp.write("\n".join(lines) + "\n") |
| 170 | |
| 171 | |
| 172 | # The build type is determined by the DEBUG environment variable. If DEBUG is |