mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Support for sapling scm (#122072)
We can use Sapling (hg) with the pytorch repo but there are a couple minor issues to teach our scripting to be happier with having either a git or hg repo. This change fixes some issues in: - setup.py - lintrunner Pull Request resolved: https://github.com/pytorch/pytorch/pull/122072 Approved by: https://github.com/ezyang
This commit is contained in:
committed by
PyTorch MergeBot
parent
482f6c4693
commit
f7b8d8e249
@ -14,13 +14,20 @@ RELEASE_PATTERN = re.compile(r"/v[0-9]+(\.[0-9]+)*(-rc[0-9]+)?/")
|
||||
|
||||
def get_sha(pytorch_root: Union[str, Path]) -> str:
|
||||
try:
|
||||
return (
|
||||
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=pytorch_root)
|
||||
.decode("ascii")
|
||||
.strip()
|
||||
)
|
||||
rev = None
|
||||
if os.path.exists(os.path.join(pytorch_root, ".git")):
|
||||
rev = subprocess.check_output(
|
||||
["git", "rev-parse", "HEAD"], cwd=pytorch_root
|
||||
)
|
||||
elif os.path.exists(os.path.join(pytorch_root, ".hg")):
|
||||
rev = subprocess.check_output(
|
||||
["hg", "identify", "-r", "."], cwd=pytorch_root
|
||||
)
|
||||
if rev:
|
||||
return rev.decode("ascii").strip()
|
||||
except Exception:
|
||||
return UNKNOWN
|
||||
pass
|
||||
return UNKNOWN
|
||||
|
||||
|
||||
def get_tag(pytorch_root: Union[str, Path]) -> str:
|
||||
|
@ -13,13 +13,22 @@ from pathlib import Path
|
||||
from sysconfig import get_paths as gp
|
||||
from typing import Any, List, NamedTuple, Optional, Pattern
|
||||
|
||||
|
||||
# PyTorch directory root
|
||||
result = subprocess.run(
|
||||
["git", "rev-parse", "--show-toplevel"],
|
||||
stdout=subprocess.PIPE,
|
||||
check=True,
|
||||
)
|
||||
PYTORCH_ROOT = result.stdout.decode("utf-8").strip()
|
||||
def scm_root() -> str:
|
||||
path = os.path.abspath(os.getcwd())
|
||||
while True:
|
||||
if os.path.isdir(os.path.join(path, ".git")):
|
||||
return path
|
||||
if os.path.isdir(os.path.join(path, ".hg")):
|
||||
return path
|
||||
n = len(path)
|
||||
path = os.path.dirname(path)
|
||||
if len(path) == n:
|
||||
raise RuntimeError("Unable to find SCM root")
|
||||
|
||||
|
||||
PYTORCH_ROOT = scm_root()
|
||||
IS_WINDOWS: bool = os.name == "nt"
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user