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:
Aaron Orenstein
2024-03-21 09:02:27 -07:00
committed by PyTorch MergeBot
parent 482f6c4693
commit f7b8d8e249
2 changed files with 28 additions and 12 deletions

View File

@ -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"