mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Type-annotate tools/generate_torch_version (#51637)
Summary: And add it to mypy.ini Pull Request resolved: https://github.com/pytorch/pytorch/pull/51637 Reviewed By: janeyx99 Differential Revision: D26225123 Pulled By: malfet fbshipit-source-id: d70d539ae58a14321e82f4592aaa44b3ce6b6358
This commit is contained in:
committed by
Facebook GitHub Bot
parent
50d903f19f
commit
627ec8badf
@ -3,21 +3,22 @@ import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from distutils.util import strtobool
|
||||
from typing import Optional, Union
|
||||
|
||||
def get_sha(pytorch_root):
|
||||
def get_sha(pytorch_root: Union[str, Path]) -> str:
|
||||
try:
|
||||
return subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=pytorch_root).decode('ascii').strip()
|
||||
except Exception:
|
||||
return 'Unknown'
|
||||
|
||||
def get_torch_version(sha=None):
|
||||
def get_torch_version(sha: Optional[str] = None) -> str:
|
||||
pytorch_root = Path(__file__).parent.parent
|
||||
version = open('version.txt', 'r').read().strip()
|
||||
|
||||
if os.getenv('PYTORCH_BUILD_VERSION'):
|
||||
assert os.getenv('PYTORCH_BUILD_NUMBER') is not None
|
||||
build_number = int(os.getenv('PYTORCH_BUILD_NUMBER'))
|
||||
version = os.getenv('PYTORCH_BUILD_VERSION')
|
||||
build_number = int(os.getenv('PYTORCH_BUILD_NUMBER', ""))
|
||||
version = os.getenv('PYTORCH_BUILD_VERSION', "")
|
||||
if build_number > 1:
|
||||
version += '.post' + str(build_number)
|
||||
elif sha != 'Unknown':
|
||||
|
Reference in New Issue
Block a user