Skip to content

Commit 2782ac8

Browse files
Set __version__ (onnx#705)
Co-authored-by: Chin Huang <[email protected]>
1 parent 9d80e43 commit 2782ac8

File tree

6 files changed

+61
-59
lines changed

6 files changed

+61
-59
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ Because users often have their own preferences for which variant of Tensorflow t
4747
[ONNX-Tensorflow API](https://github.com/onnx/onnx-tensorflow/blob/master/doc/API.md)
4848

4949
### Installation:
50-
- Run `git clone https://github.com/onnx/onnx.git && cd onnx`.
51-
- Run `git submodule update --init --recursive`.
52-
- Run `pip install -e .`.
50+
- Install ONNX master branch from source.
5351
- Install Tensorflow >= 2.2.0 and tensorflow-addons. (Note for Tensorflow 1.x please refer the [tf-1.x branch](https://github.com/onnx/onnx-tensorflow/tree/tf-1.x))
5452
- Run `git clone https://github.com/onnx/onnx-tensorflow.git && cd onnx-tensorflow`.
5553
- Run `pip install -e .`.

doc/IMPLEMENTING_NEW_OP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Customize op can also be implemented in similar way.
1616
* version is the number of since version, which can get from operator's specification
1717
```
1818
4. From within the `onnx_tf` directory, run `gen_opset.py`.
19-
5. From within the `onnx_tf` directory, run `gen_status.py -v master`.
19+
5. From within the `onnx_tf` directory, run `gen_status.py`.
2020
6. From within the `onnx_tf` directory, run `gen_doc.py` if there is any update to CLI or API.
2121
7. Verify the operator's test cases in `test/backend/test_onnx_backend.py` all pass.
2222
8. Add any additional test cases to `test/backend/test_node.py`.

onnx_tf/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from . import backend
2+
from .version import version as __version__

onnx_tf/gen_status.py

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,69 +13,61 @@
1313

1414
import tensorflow as tf
1515

16-
from onnx_tf import opset_version
16+
from onnx_tf import opset_version, __version__
1717

1818

1919
def main(docs_dir):
2020
base_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
2121
docs_dir = os.path.join(base_dir, 'doc')
22-
onnx_version = ''
22+
onnx_version = onnx.__version__
2323
onnx_tf_release_build = False
2424

2525
try:
26-
opts, args = getopt.getopt(sys.argv[1:], 'hv:r',
27-
['onnx_version=', 'onnx_tf_release_build'])
26+
opts, args = getopt.getopt(sys.argv[1:], 'h:mr',
27+
['onnx_master', 'onnx_tf_release_build'])
2828
except getopt.GetoptError:
2929
print('Usage:')
30-
print(' gen_status.py -v <onnx_version> [-r]')
30+
print(' gen_status.py [-m -r]')
3131
print(' gen_status.py -h')
3232
print('Description:')
33-
print(' -v, --onnx_version installed ONNX version')
34-
print(' -r, --onnx_tf_release_build create report for ONNX-TF release with version stated in the VERSION_NUMBER file')
35-
print(' when omitted, the report is for ONNX-TF master')
33+
print(' -m, --onnx_master installed ONNX is the latest master code')
34+
print(' if omitted, ONNX version is onnx.__version__')
35+
print(' -r, --onnx_tf_release_build create report for ONNX-TF release with version')
36+
print(' stated in the VERSION_NUMBER file')
37+
print(' if omitted, the report is for ONNX-TF master')
3638
print(' -h show this help message and exit')
37-
print('eg. generate support_status.md for onnx-tf master and onnx master')
38-
print(' gen_status.py -v master')
39-
print(' generate support_status_<onnx_tf_version>.md for onnx-tf ' +
40-
'version stated in the VERSION_NUMBER file and onnx v1.5.0 ')
41-
print(' gen_status.py -v v1.5.0 -r')
39+
print('eg. 1. generate support_status.md for ONNX-TF master and ONNX onnx.__version__')
40+
print(' gen_status.py')
41+
print(' 2. generate support_status.md for ONNX-TF master and ONNX master')
42+
print(' gen_status.py -m')
43+
print(' 3. generate support_status_<onnx_tf_version>.md for ONNX-TF version')
44+
print(' stated in the VERSION_NUMBER file and ONNX onnx.__version__ ')
45+
print(' gen_status.py -r')
4246
sys.exit(2)
4347
for opt, arg in opts:
4448
if opt == '-h':
4549
print('Usage:')
46-
print(' gen_status.py -v <onnx_version> [-r]')
50+
print(' gen_status.py [-m -r]')
4751
print(' gen_status.py -h')
4852
print('Description:')
49-
print(' -v, --onnx_version installed ONNX version')
50-
print(' -r, --onnx_tf_release_build create report for ONNX-TF release with version stated in the VERSION_NUMBER file')
51-
print(' when omitted, the report is for ONNX-TF master')
53+
print(' -m, --onnx_master installed ONNX is the latest master code')
54+
print(' if omitted, ONNX version is onnx.__version__')
55+
print(' -r, --onnx_tf_release_build create report for ONNX-TF release with version')
56+
print(' stated in the VERSION_NUMBER file')
57+
print(' if omitted, the report is for ONNX-TF master')
5258
print(' -h show this help message and exit')
53-
print('eg. generate support_status.md for onnx-tf master and onnx master')
54-
print(' gen_status.py -v master')
55-
print(' generate support_status_<onnx_tf_version>.md for onnx-tf ' +
56-
'version stated in the VERSION_NUMBER file and onnx v1.5.0')
57-
print(' gen_status.py -v v1.5.0 -r')
59+
print('eg. 1. generate support_status.md for ONNX-TF master and ONNX onnx.__version__')
60+
print(' gen_status.py')
61+
print(' 2. generate support_status.md for ONNX-TF master and ONNX master')
62+
print(' gen_status.py -m')
63+
print(' 3. generate support_status_<onnx_tf_version>.md for ONNX-TF version')
64+
print(' stated in the VERSION_NUMBER file and ONNX onnx.__version__ ')
65+
print(' gen_status.py -r')
5866
sys.exit()
59-
elif opt in ('-v', '--onnx_version'):
60-
onnx_version = arg
67+
elif opt in ('-m', '--onnx_master'):
68+
onnx_version = 'master'
6169
elif opt in ('-r', '--onnx_tf_release_build'):
6270
onnx_tf_release_build = True
63-
if onnx_version == '':
64-
print('Please provide the onnx_version.')
65-
print('Usage:')
66-
print(' gen_status.py -v <onnx_version> [-r]')
67-
print(' gen_status.py -h')
68-
print('Description:')
69-
print(' -v, --onnx_version installed ONNX version')
70-
print(' -r, --onnx_tf_release_build create report for ONNX-TF release with version stated in the VERSION_NUMBER file')
71-
print(' when omitted, the report is for ONNX-TF master')
72-
print(' -h show this help message and exit')
73-
print('eg. generate support_status.md for onnx-tf master and onnx master')
74-
print(' gen_status.py -v master')
75-
print(' generate support_status_<onnx_tf_version>.md for onnx-tf ' +
76-
'version stated in the VERSION_NUMBER file and onnx v1.5.0')
77-
print(' gen_status.py -v v1.5.0 -r')
78-
sys.exit(2)
7971

8072
gen_support_status(docs_dir, onnx_version, onnx_tf_release_build)
8173

@@ -84,12 +76,7 @@ def gen_support_status(docs_dir, onnx_version, onnx_tf_release_build):
8476

8577
# set filename
8678
if onnx_tf_release_build:
87-
# get onnx-tf version from VERSION_NUMBER file
88-
version_dir = os.path.dirname(
89-
os.path.dirname(os.path.realpath('VERSION_NUMBER')))
90-
version_file = os.path.join(version_dir, 'VERSION_NUMBER')
91-
onnx_tf_version = subprocess.check_output('cat ' + version_file, shell=True)
92-
onnx_tf_version = 'v' + onnx_tf_version.decode().strip('\n')
79+
onnx_tf_version = 'v' + __version__
9380
filename = 'support_status_' + onnx_tf_version.replace('.', '_') + '.md'
9481
else: # onnx-tf = master
9582
# get onnx-tf commit id
@@ -107,12 +94,7 @@ def gen_support_status(docs_dir, onnx_version, onnx_tf_release_build):
10794

10895
# get onnx commit id
10996
if onnx_version == 'master':
110-
onnx_path = os.path.dirname(
111-
os.path.dirname(os.path.realpath(onnx.__file__)))
112-
onnx_commit_id = subprocess.check_output('cd ' + onnx_path +
113-
'; git rev-parse HEAD',
114-
shell=True)
115-
onnx_commit_id = onnx_commit_id.decode().strip('\n')
97+
onnx_commit_id = onnx.version.git_version
11698
status_file.write(
11799
'|ONNX Version|Master ( commit id: {} )|\n'.format(onnx_commit_id))
118100
else:

setup.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import os
22
import setuptools
3+
import subprocess
4+
from textwrap import dedent
35

46
TOP_DIR = os.path.realpath(os.path.dirname(__file__))
7+
SRC_DIR = os.path.join(TOP_DIR, 'onnx_tf')
58

69
with open(os.path.join(TOP_DIR, 'VERSION_NUMBER')) as version_file:
710
version = version_file.read().strip()
@@ -15,6 +18,25 @@
1518
onnx_version = onnx_version_file.read().strip()
1619
onnx_dep = "onnx>=" + onnx_version
1720

21+
try:
22+
git_version = subprocess.check_output(['git', 'rev-parse', 'HEAD'],
23+
cwd=TOP_DIR).decode('ascii').strip()
24+
except (OSError, subprocess.CalledProcessError):
25+
git_version = None
26+
27+
with open(os.path.join(SRC_DIR, 'version.py'), 'w') as f:
28+
f.write(dedent('''\
29+
# This file is generated by setup.py. DO NOT EDIT!
30+
31+
from __future__ import absolute_import
32+
from __future__ import division
33+
from __future__ import print_function
34+
from __future__ import unicode_literals
35+
36+
version = '{}'
37+
git_version = '{}'
38+
'''.format(version, git_version)))
39+
1840
setuptools.setup(
1941
name='onnx-tf',
2042
version=version,

util/get_version.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
import onnx
88
import tensorflow
99
import onnx_tf
10-
import pkg_resources
1110

1211
print("Python version:")
1312
print(sys.version)
1413
print("ONNX version:")
1514
print(onnx.version.version)
1615
print("ONNX-TF version:")
17-
print(pkg_resources.get_distribution("onnx-tf").version)
16+
print(onnx_tf.__version__)
1817
print("Tensorflow version:")
19-
print(tensorflow.__version__)
18+
print(tensorflow.__version__)

0 commit comments

Comments
 (0)