Skip to content

Commit

Permalink
Revert "tools: add ability to grab git tag (pytorch#77279)"
Browse files Browse the repository at this point in the history
This reverts commit ba55296.

Reverted pytorch#77279 on behalf of https://github.com/seemethere
  • Loading branch information
pytorchmergebot committed May 13, 2022
1 parent fa018ef commit 9728368
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions tools/generate_torch_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
from typing import Optional, Union


UNKNOWN = "Unknown"


def get_sha(pytorch_root: Union[str, Path]) -> str:
try:
return (
Expand All @@ -17,20 +14,7 @@ def get_sha(pytorch_root: Union[str, Path]) -> str:
.strip()
)
except Exception:
return UNKNOWN


def get_tag(pytorch_root: Union[str, Path]) -> str:
try:
return (
subprocess.check_output(
["git", "describe", "--tags", "--exact"], cwd=pytorch_root
)
.decode("ascii")
.strip()
)
except Exception:
return UNKNOWN
return "Unknown"


def get_torch_version(sha: Optional[str] = None) -> str:
Expand All @@ -43,7 +27,7 @@ def get_torch_version(sha: Optional[str] = None) -> str:
version = os.getenv("PYTORCH_BUILD_VERSION", "")
if build_number > 1:
version += ".post" + str(build_number)
elif sha != UNKNOWN:
elif sha != "Unknown":
if sha is None:
sha = get_sha(pytorch_root)
version += "+git" + sha[:7]
Expand All @@ -70,13 +54,8 @@ def get_torch_version(sha: Optional[str] = None) -> str:

pytorch_root = Path(__file__).parent.parent
version_path = pytorch_root / "torch" / "version.py"
# Attempt to get tag first, fall back to sha if a tag was not found
tagged_version = get_tag(pytorch_root)
sha = get_sha(pytorch_root)
if tagged_version == UNKNOWN:
version = get_torch_version(sha)
else:
version = tagged_version
version = get_torch_version(sha)

with open(version_path, "w") as f:
f.write("__version__ = '{}'\n".format(version))
Expand Down

0 comments on commit 9728368

Please sign in to comment.