π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
improve setup packaging and build manywheel script (#543)
Edgar Riba9cfce638c983
diff --git a/packaging/build_wheel.sh b/packaging/build_wheel.shnew file mode 100755index 000000000..2aa8ecff8--- /dev/null+++ b/packaging/build_wheel.sh@@ -0,0 +1,22 @@+#!/bin/bash -ex++## NOTE: define KORNIA_BUILD_VERSION each release+## KORNIA_BUILD_VERSION=0.1.4++export OUT_DIR="/tmp/remote"++# move to project root and create the wheel+cd /tmp+rm -rf kornia/+git clone https://github.com/kornia/kornia.git++cd /tmp/kornia+python3 setup.py clean+python3 setup.py bdist_wheel++mkdir -p $OUT_DIR+cp dist/*.whl $OUT_DIR/++## upload+## NOTE: to upload install twine+## Example: python3 -m twine upload dist/*diff --git a/scripts/build_wheel.sh b/scripts/build_wheel.shdeleted file mode 100755index ae5cc39cb..000000000--- a/scripts/build_wheel.sh+++ /dev/null@@ -1,15 +0,0 @@-#!/bin/bash -ex--## NOTE: change this each release-export KORNIA_BUILD_VERSION=0.1.4-export KORNIA_BUILD_NUMBER=1 # use 1 for final release, otherwise will be post2, post3, postN--# move to project root and create the wheel--cd ..-python3 setup.py sdist bdist_wheel--# upload--python3 -m twine upload dist/*-diff --git a/setup.py b/setup.pyindex a677f7907..5f586e222 100644--- a/setup.py+++ b/setup.py@@ -1,46 +1,47 @@# Welcome to the Kornia setup.py.#-from __future__ import print_function+import osfrom setuptools import setup, find_packagesimport subprocess-import os+import distutils.command.clean+++################+# The variables below define the current version under+# development and the current pytorch supported verions.+# WARNING: Becareful and do not touch those variables,+# unless you are a maintainer. Otherwise, could brake+# the package backward compatibility.+# NOTE(maintainers): modify this variable each time you do a release++version = '0.2.3'+pytorch = 'torch>=1.0.0, <=1.4.0'+############################++sha = 'Unknown'+package_name = 'kornia'-# Constant known variables used throughout this filecwd = os.path.dirname(os.path.abspath(__file__))+try:+ sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip()+except Exception:+ pass-################################################################################-# Version, create_version_file, and package_name-#-# Example for release (0.1.2):-# KORNIA_BUILD_VERSION=0.1.2 \-# KORNIA_BUILD_NUMBER=1 python setup.py install-################################################################################-package_name = os.getenv('KORNIA_PACKAGE_NAME', 'kornia')-version = '0.2.1' # NOTE: modify this variable each time we do a releaseif os.getenv('KORNIA_BUILD_VERSION'):- assert os.getenv('KORNIA_BUILD_NUMBER') is not None- build_number = int(os.getenv('KORNIA_BUILD_NUMBER'))version = os.getenv('KORNIA_BUILD_VERSION')- if build_number > 1:- version += '.post' + str(build_number)-else:- try:- sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip()- version += '+' + sha[:7]- except Exception:- pass+elif sha != 'Unknown':+ version += '+' + sha[:7]print("Building wheel {}-{}".format(package_name, version))-# all the work we need to do _before_ setup runs-def build_deps():- print('-- Building version ' + version)+def write_version_file():version_path = os.path.join(cwd, 'kornia', 'version.py')with open(version_path, 'w') as f:f.write("__version__ = '{}'\n".format(version))+ f.write("git_version = {}\n".format(repr(sha)))def read(*names, **kwargs):@@ -56,13 +57,25 @@ readme = open('README.rst').read()long_description = '\n'.join(readme.split('\n')[7:])-requirements = [- 'torch>=1.0.0',-]+class clean(distutils.command.clean.clean):+ def run(self):+ with open('.gitignore', 'r') as f:+ ignores = f.read()+ for wildcard in filter(None, ignores.split('\n')):+ for filename in glob.glob(wildcard):+ try:+ os.remove(filename)+ except OSError:+ shutil.rmtree(filename, ignore_errors=True)++ # It's an old-style class in Python 2.7...+ distutils.command.clean.clean.run(self)+ # remove compiled and temporary files+ subprocess.call(['rm -rf dist/ build/ kornia.egg*'], shell=True)if __name__ == '__main__':- build_deps()+ write_version_file()setup(# Metadataname=package_name,@@ -83,7 +96,9 @@ if __name__ == '__main__':packages=find_packages(exclude=('docs', 'test', 'examples',)),zip_safe=True,- install_requires=requirements,+ install_requires=[+ pytorch,+ ],classifiers=['Intended Audience :: Developers','Intended Audience :: Education',