Skip to content

Commit 7239e25

Browse files
author
Michael Sieberer
committed
fix versions
1 parent 19268d0 commit 7239e25

File tree

5 files changed

+81
-21
lines changed

5 files changed

+81
-21
lines changed

.github/workflows/pythonpublish.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ jobs:
1919
shell: bash
2020
run: |
2121
ver=$(echo ${{ github.event.release.tag_name }} | sed 's/[^0-9]//')
22-
printf "__version__ = '%s'" "$ver" > CryMOS/version.py
22+
echo "package version is" "$ver"
23+
printf "::set-output name=version::%s" "$ver"
2324
- name: Set up Python
2425
uses: actions/setup-python@v1
2526
with:
@@ -40,7 +41,8 @@ jobs:
4041
python setup.py download_boost
4142
export BOOST_ROOT="$PWD/build/boost_1_72_0"
4243
fi
43-
python setup.py sdist bdist_wheel
44+
export PM_MOS_VERSION=${{ steps.set_version.outputs.version }}
45+
python setup.py bdist_wheel
4446
cd dist
4547
printf "::set-output name=whl_file::%s" *.whl
4648
# twine upload dist/*
@@ -51,7 +53,7 @@ jobs:
5153
env:
5254
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5355
with:
54-
upload_url: ${{ github.event.release.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
56+
upload_url: ${{ github.event.release.upload_url }}
5557
asset_path: dist/${{ steps.build.outputs.whl_file }}
5658
asset_name: ${{ steps.build.outputs.whl_file }}
5759
asset_content_type: application/x-wheel+zip

CryMOS/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
The copyright (c) is with Infineon Technologies Austria AG, 2020.
1111
See the LICENSE file for the licensing terms. """
1212

13-
__version__ = '0.1'
14-
13+
from .version import __version__
1514
from .Bulk import BulkModel, BulkModelFD, BulkModelTails
1615
from .QV import *
1716
from .IV import *

CryMOS/cpp/build.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,32 @@ def __str__(self):
2020
return pybind11.get_include(self.user)
2121

2222

23-
def get_boost_include(builddir='build'):
24-
import os
23+
class get_boost_include:
24+
""" get boost include, this is quite hacky """
2525

26-
root = None
26+
def __init__(self, builddir='build'):
27+
self.builddir = builddir
2728

28-
if 'BOOST_ROOT' in os.environ:
29-
root = os.environ['BOOST_ROOT']
30-
else:
31-
path = [builddir, '.', '~', os.path.dirname(__file__) + '/../../build']
29+
def __str__(self):
30+
import os
31+
32+
root = None
3233

33-
for p in path:
34-
root = os.path.expanduser(p + '/boost_1_72_0')
35-
if os.path.exists(root):
36-
break
34+
if 'BOOST_ROOT' in os.environ:
35+
root = os.environ['BOOST_ROOT']
36+
else:
37+
path = [self.builddir, '.', '~', os.path.dirname(__file__) + '/../../build']
3738

38-
if root is None or not os.path.exists(root + '/boost'):
39-
from warnings import warn
40-
warn("boost libraries could not be found, you might want to set `BOOST_ROOT`")
39+
for p in path:
40+
root = os.path.expanduser(p + '/boost_1_72_0')
41+
if os.path.exists(root):
42+
break
43+
44+
if root is None or not os.path.exists(root + '/boost'):
45+
from warnings import warn
46+
warn("boost libraries could not be found, you might want to set `BOOST_ROOT`")
4147

42-
return root
48+
return root
4349

4450

4551
class BuildExt(build_ext):

CryMOS/version.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
__version__ = None
2+
3+
try: # try to get version from git
4+
from subprocess import run
5+
from os.path import dirname
6+
dir = dirname(__file__)
7+
8+
proc = run('git tag -l --sort=-v:refname',
9+
capture_output=True, shell=True, check=True, text=True, cwd=dir)
10+
tags = [t for t in proc.stdout.split() if t.startswith('v')]
11+
ver = tags[0].replace('v', '')
12+
13+
proc = run('git log --abbrev-commit --format=%h -1',
14+
capture_output=True, shell=True, check=True, text=True, cwd=dir)
15+
hash = proc.stdout.strip()
16+
17+
__version__ = ver + '.dev0+git.' + hash
18+
except:
19+
pass

setup.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
from setuptools import setup
22
import distutils.cmd
3+
from distutils.command.build_py import build_py
34

45
# don't import CryMOS!
56
build_cpp = {'__file__': 'CryMOS/cpp/build.py'}
67
with open('CryMOS/cpp/build.py') as f:
78
exec(f.read(), build_cpp)
89

10+
ver_file = {'__file__': 'CryMOS/version.py'}
11+
with open('CryMOS/version.py') as f:
12+
exec(f.read(), ver_file)
13+
14+
import os
15+
if 'PM_MOS_VERSION' in os.environ:
16+
version = os.environ['PM_MOS_VERSION']
17+
else:
18+
version = ver_file['__version__']
19+
920

1021
class DwnlBoostCommand(distutils.cmd.Command):
1122
"""A custom command to run Pylint on all Python source files."""
@@ -79,10 +90,32 @@ def download_boost_archive(self):
7990

8091
return contents
8192

93+
class BuildPyFixVersion(build_py):
94+
""" fix version when building"""
95+
96+
user_options = build_py.user_options + [
97+
('version=', None, 'Version Name')
98+
]
99+
100+
def initialize_options(self):
101+
super().initialize_options()
102+
self.version = version
103+
104+
def run(self):
105+
super().run()
106+
self.fix_version()
107+
108+
def fix_version(self):
109+
print("version is", self.version)
110+
111+
file = self.build_lib + "/CryMOS/version.py"
112+
with open(file, 'w') as f:
113+
f.write(f"__version__ = '{self.version}'\n")
114+
82115

83116
setup(
84117
name='pm-mos-model',
85-
version='0.1',
118+
version=version,
86119
packages=['CryMOS', 'CryMOS.cpp'],
87120
url='https://github.com/michi7x7/pm-mos-model',
88121
license='Apache License 2.0',
@@ -96,5 +129,6 @@ def download_boost_archive(self):
96129
cmdclass={
97130
'download_boost': DwnlBoostCommand,
98131
'build_ext': build_cpp['BuildExt'],
132+
'build_py': BuildPyFixVersion,
99133
}
100134
)

0 commit comments

Comments
 (0)