From 1bdc28161a68d24ab21d05b195935ef81c67826e Mon Sep 17 00:00:00 2001 From: Adam Paszke Date: Wed, 15 Feb 2017 11:48:08 -0800 Subject: [PATCH] Add torch.__version__ --- .gitignore | 1 + setup.py | 36 +++++++++++++++++++++++++++++++++++- torch/__init__.py | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9dbdf09593f6fe..2052f1f74f6dba 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ build/ dist/ torch.egg-info/ */**/__pycache__ +torch/version.py torch/csrc/generic/TensorMethods.cpp torch/lib/*.so* torch/lib/*.dylib* diff --git a/setup.py b/setup.py index 6b3c0147186eee..1ce65bbd3f2b1c 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,8 @@ from setuptools import setup, Extension, distutils, Command, find_packages import setuptools.command.build_ext import setuptools.command.install +import setuptools.command.develop +import setuptools.command.build_py import distutils.unixccompiler import distutils.command.build import distutils.command.clean @@ -94,6 +96,28 @@ def run(self): self.run_command('build_ext') +class build_py(setuptools.command.build_py.build_py): + + def run(self): + self.create_version_file() + setuptools.command.build_py.build_py.run(self) + + @staticmethod + def create_version_file(): + global version, cwd + print('-- Building version ' + version) + version_path = os.path.join(cwd, 'torch', 'version.py') + with open(version_path, 'w') as f: + f.write("__version__ = '{}'\n".format(version)) + + +class develop(setuptools.command.develop.develop): + + def run(self): + build_py.create_version_file() + setuptools.command.develop.develop.run(self) + + class build_ext(setuptools.command.build_ext.build_ext): def run(self): @@ -362,18 +386,28 @@ def make_relative_rpath(path): ) extensions.append(THCUNN) -version = "0.1" +version = '0.1.9' if os.getenv('PYTORCH_BUILD_VERSION'): + assert os.getenv('PYTORCH_BUILD_NUMBER') is not None version = os.getenv('PYTORCH_BUILD_VERSION') \ + '_' + os.getenv('PYTORCH_BUILD_NUMBER') +else: + try: + sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip() + version += '+' + sha[:7] + except subprocess.CalledProcessError: + pass + setup(name="torch", version=version, ext_modules=extensions, cmdclass={ 'build': build, + 'build_py': build_py, 'build_ext': build_ext, 'build_deps': build_deps, 'build_module': build_module, + 'develop': develop, 'install': install, 'clean': clean, }, diff --git a/torch/__init__.py b/torch/__init__.py index 550a6442f7409f..647e6362feb034 100644 --- a/torch/__init__.py +++ b/torch/__init__.py @@ -10,6 +10,7 @@ import sys from ._utils import _import_dotted_name +from .version import __version__ __all__ = [ 'typename', 'is_tensor', 'is_storage', 'set_default_tensor_type',