Dynamically generate versions based on commit hash (#2774)

Summary:
This will produce version strings like `1.0.0a0+3065963`, similar to PyTorch version strings.

Pull Request resolved: https://github.com/pytorch/fairseq/pull/2774

Reviewed By: alexeib

Differential Revision: D24453517

Pulled By: myleott

fbshipit-source-id: 03a0c324ed6124bbc513ba7edc954abd71d63a0f
This commit is contained in:
Myle Ott 2020-10-22 12:45:19 -07:00 committed by Facebook GitHub Bot
parent b8a938e96e
commit e0737c3c29
6 changed files with 40 additions and 10 deletions

1
.gitignore vendored
View File

@ -113,6 +113,7 @@ ENV/
/fairseq/temporal_convolution_tbc
/fairseq/modules/*_layer/*_forward.cu
/fairseq/modules/*_layer/*_backward.cu
/fairseq/version.py
# data
data-bin/

View File

@ -19,6 +19,7 @@
import os
import sys
from fairseq import __version__
# source code directory, relative to this file, for sphinx-autobuild
@ -51,7 +52,7 @@ master_doc = "index"
# General information about the project.
project = "fairseq"
copyright = "2019, Facebook AI Research (FAIR)"
copyright = "Facebook AI Research (FAIR)"
author = "Facebook AI Research (FAIR)"
github_doc_root = "https://github.com/pytorch/fairseq/tree/master/docs/"
@ -61,9 +62,9 @@ github_doc_root = "https://github.com/pytorch/fairseq/tree/master/docs/"
# built documents.
#
# The short X.Y version.
version = "0.9.0"
version = __version__
# The full version, including alpha/beta/rc tags.
release = "0.9.0"
release = __version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View File

@ -3,6 +3,4 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
__version__ = "0.9.0"
import examples.noisychannel # noqa
from fairseq.version import __version__ # noqa

View File

@ -4,11 +4,18 @@
# LICENSE file in the root directory of this source tree.
"""isort:skip_file"""
__all__ = ["pdb"]
__version__ = "1.0.0a0"
import os
import sys
try:
from .version import __version__ # noqa
except ImportError:
version_txt = os.path.join(os.path.dirname(__file__), "version.txt")
with open(version_txt) as f:
__version__ = f.read().strip()
__all__ = ["pdb"]
# backwards compatibility to support `from fairseq.meters import AverageMeter`
from fairseq.logging import meters, metrics, progress_bar # noqa

1
fairseq/version.txt Normal file
View File

@ -0,0 +1 @@
1.0.0a0

View File

@ -5,7 +5,9 @@
# LICENSE file in the root directory of this source tree.
import os
import subprocess
import sys
from setuptools import setup, find_packages, Extension
from setuptools import Extension, find_packages, setup
@ -14,6 +16,26 @@ if sys.version_info < (3, 6):
sys.exit("Sorry, Python >= 3.6 is required for fairseq.")
def write_version_py():
with open(os.path.join("fairseq", "version.txt")) as f:
version = f.read().strip()
# append latest commit hash to version string
try:
sha = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip()
version += "+" + sha[:7]
except Exception:
pass
# write version info to fairseq/version.py
with open(os.path.join("fairseq", "version.py"), "w") as f:
f.write("__version__ = \"{}\"\n".format(version))
return version
version = write_version_py()
with open("README.md") as f:
readme = f.read()
@ -130,7 +152,7 @@ if "clean" in sys.argv[1:]:
def do_setup(package_data):
setup(
name="fairseq",
version="0.9.0",
version=version,
description="Facebook AI Research Sequence-to-Sequence Toolkit",
url="https://github.com/pytorch/fairseq",
classifiers=[