From e0737c3c2985d2a71f0a30bb29f6d8741b4f87f3 Mon Sep 17 00:00:00 2001 From: Myle Ott Date: Thu, 22 Oct 2020 12:45:19 -0700 Subject: [PATCH] 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 --- .gitignore | 1 + docs/conf.py | 7 ++++--- examples/__init__.py | 4 +--- fairseq/__init__.py | 13 ++++++++++--- fairseq/version.txt | 1 + setup.py | 24 +++++++++++++++++++++++- 6 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 fairseq/version.txt diff --git a/.gitignore b/.gitignore index a7c457714..9546cffd9 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/docs/conf.py b/docs/conf.py index 52971a27e..440784bfa 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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. diff --git a/examples/__init__.py b/examples/__init__.py index 9a6b08a75..80d95f5fe 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -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 diff --git a/fairseq/__init__.py b/fairseq/__init__.py index cac3d0e43..4ccfc9025 100644 --- a/fairseq/__init__.py +++ b/fairseq/__init__.py @@ -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 diff --git a/fairseq/version.txt b/fairseq/version.txt new file mode 100644 index 000000000..41432f00d --- /dev/null +++ b/fairseq/version.txt @@ -0,0 +1 @@ +1.0.0a0 diff --git a/setup.py b/setup.py index edc019671..7b13f13e4 100644 --- a/setup.py +++ b/setup.py @@ -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=[