Skip to content

Commit

Permalink
Fix git based package versioning for setuptools >= 67.0.0 (#691)
Browse files Browse the repository at this point in the history
* Fix git based package version

* Use setuptools_scm

Signed-off-by: Dennis Keck <26092524+fellhorn@users.noreply.github.com>

* Fix write to version

Signed-off-by: Dennis Keck <26092524+fellhorn@users.noreply.github.com>

* Fix version var backwards compatibility

Signed-off-by: Dennis Keck <26092524+fellhorn@users.noreply.github.com>

* Revert "Fix version var backwards compatibility"

This reverts commit f9a9238.

* Try - catch version handling

Signed-off-by: Dennis Keck <26092524+fellhorn@users.noreply.github.com>

---------

Signed-off-by: Dennis Keck <26092524+fellhorn@users.noreply.github.com>
  • Loading branch information
fellhorn committed Apr 23, 2023
1 parent 87a7a7b commit 5f1f074
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dist
runs/*
*.pyc
mnist
tensorboardX/_version.py
25 changes: 5 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
# -*- coding: utf-8 -*-

import subprocess
import os
import sys
from setuptools import setup, find_packages
from setuptools import setup
from setuptools.command.develop import develop
from setuptools.command.install import install

Expand All @@ -31,23 +30,6 @@ def run(self):
history = history_file.read()

preparing_PyPI_package = 'sdist' in sys.argv or 'bdist_wheel' in sys.argv
version_git = version = subprocess.check_output(['git', 'describe', '--always']).decode('ascii').strip()

# pass version without using argparse
# format example: v1.2.3
publish_version = sys.argv[-1]
if publish_version[0] == 'v':
version_git = publish_version[1:]
sys.argv = sys.argv[:-1]
print(version_git)

if not preparing_PyPI_package:
if os.path.exists('.git'):
sha = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
version_git = version_git + '+' + sha[:7]

with open('tensorboardX/__init__.py', 'a') as f:
f.write('\n__version__ = "{}"\n'.format(version_git))

requirements = [
'numpy',
Expand All @@ -58,7 +40,6 @@ def run(self):

setup(
name='tensorboardX',
version=version_git,
description='TensorBoardX lets you watch Tensors Flow without Tensorflow',
long_description=history,
author='Tzu-Wei Huang',
Expand All @@ -67,6 +48,10 @@ def run(self):
packages=['tensorboardX'],
include_package_data=True,
install_requires=requirements,
use_scm_version={
'write_to': "tensorboardX/_version.py",
},
setup_requires=['setuptools_scm'],
license='MIT license',
zip_safe=False,
classifiers=[
Expand Down
9 changes: 5 additions & 4 deletions tensorboardX/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from .torchvis import TorchVis
from .writer import FileWriter, SummaryWriter
from .global_writer import GlobalSummaryWriter
__version__ = "dev"
# will be overwritten if run setup.py
# specifically, `python setup.py install` creates [version in setup.py + git SHA hash]
# python setup.py sdist creates a decimal version number

try:
from ._version import __version__
except ImportError:
__version__ = "unknown version"

0 comments on commit 5f1f074

Please sign in to comment.