Skip to content

Commit

Permalink
Add torch.__version__
Browse files Browse the repository at this point in the history
  • Loading branch information
apaszke authored and soumith committed Feb 17, 2017
1 parent 5e150ca commit 1bdc281
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build/
dist/
torch.egg-info/
*/**/__pycache__
torch/version.py
torch/csrc/generic/TensorMethods.cpp
torch/lib/*.so*
torch/lib/*.dylib*
Expand Down
36 changes: 35 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 1bdc281

Please sign in to comment.