From 954931abdc7fba3f6554dc2d1f9863b4d856134d Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Sat, 29 Jun 2019 22:43:52 +0200 Subject: [PATCH 1/2] add setup.py for publishing on pypi. --- .gitignore | 3 ++ knxPython/CMakeLists.txt | 70 ++++++++++++++-------------- knxPython/Manifest.in | 15 ++++++ knxPython/VERSION | 1 + knxPython/main.py | 35 -------------- knxPython/setup.py | 81 +++++++++++++++++++++++++++++++++ knxPython/write_version_info.py | 49 ++++++++++++++++++++ 7 files changed, 186 insertions(+), 68 deletions(-) create mode 100644 knxPython/Manifest.in create mode 100644 knxPython/VERSION delete mode 100644 knxPython/main.py create mode 100644 knxPython/setup.py create mode 100644 knxPython/write_version_info.py diff --git a/.gitignore b/.gitignore index da20bfa..e269708 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,9 @@ bld/ [Ll]og/ out flash.bin +build +dist +*.egg-info # Visual Studio 2015 cache/options directory .vs/ diff --git a/knxPython/CMakeLists.txt b/knxPython/CMakeLists.txt index 272ee00..33b304a 100644 --- a/knxPython/CMakeLists.txt +++ b/knxPython/CMakeLists.txt @@ -2,41 +2,45 @@ #Note: VisualGDB will automatically update this file when you add new sources to the project. cmake_minimum_required(VERSION 2.7) -project(knx) +#project(knx) add_subdirectory(pybind11) pybind11_add_module(knx knxmodule.cpp - ../src/knx/address_table_object.cpp - ../src/knx/apdu.cpp - ../src/knx/application_layer.cpp - ../src/knx/application_program_object.cpp - ../src/knx/association_table_object.cpp - ../src/knx/bau.cpp - ../src/knx/bau07B0.cpp - ../src/knx/bau57B0.cpp - ../src/knx/bau_systemB.cpp - ../src/knx/bits.cpp - ../src/knx/cemi_frame.cpp - ../src/knx/data_link_layer.cpp - ../src/knx/device_object.cpp - ../src/knx/group_object.cpp - ../src/knx/group_object_table_object.cpp - ../src/knx/interface_object.cpp - ../src/knx/ip_data_link_layer.cpp - ../src/knx/ip_parameter_object.cpp - ../src/knx/memory.cpp - ../src/knx/network_layer.cpp - ../src/knx/npdu.cpp - ../src/knx/table_object.cpp - ../src/knx/tpdu.cpp - ../src/knx/tpuart_data_link_layer.cpp - ../src/knx/transport_layer.cpp - ../src/knx/platform.cpp - ../src/linux_platform.cpp - ../src/knx_facade.cpp - ../src/knx/dptconvert.cpp - ../src/knx/knx_value.cpp - ../src/knx/dpt.cpp) -include_directories(../src pybind11/include) + src/knx/address_table_object.cpp + src/knx/apdu.cpp + src/knx/application_layer.cpp + src/knx/application_program_object.cpp + src/knx/association_table_object.cpp + src/knx/bau.cpp + src/knx/bau07B0.cpp + src/knx/bau57B0.cpp + src/knx/bau_systemB.cpp + src/knx/bits.cpp + src/knx/cemi_frame.cpp + src/knx/data_link_layer.cpp + src/knx/device_object.cpp + src/knx/group_object.cpp + src/knx/group_object_table_object.cpp + src/knx/interface_object.cpp + src/knx/ip_data_link_layer.cpp + src/knx/ip_parameter_object.cpp + src/knx/memory.cpp + src/knx/network_layer.cpp + src/knx/npdu.cpp + src/knx/table_object.cpp + src/knx/tpdu.cpp + src/knx/tpuart_data_link_layer.cpp + src/knx/transport_layer.cpp + src/knx/platform.cpp + src/linux_platform.cpp + src/knx_facade.cpp + src/knx/dptconvert.cpp + src/knx/knx_value.cpp + src/knx/dpt.cpp) +include_directories(src pybind11/include) + +set(outdir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) +set_target_properties(knx PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${outdir}) +set_target_properties(knx PROPERTIES OUTPUT_NAME knx) diff --git a/knxPython/Manifest.in b/knxPython/Manifest.in new file mode 100644 index 0000000..98bb358 --- /dev/null +++ b/knxPython/Manifest.in @@ -0,0 +1,15 @@ + + +recursive-include external * +include ./*.py +include ./VERSION +include ./*.cmake +include ./*.cpp +include ./CMakeLists.txt +include README.md + +global-exclude .git + +graft pybind11/include +graft +graft src diff --git a/knxPython/VERSION b/knxPython/VERSION new file mode 100644 index 0000000..9faa1b7 --- /dev/null +++ b/knxPython/VERSION @@ -0,0 +1 @@ +0.1.5 diff --git a/knxPython/main.py b/knxPython/main.py deleted file mode 100644 index 07b859a..0000000 --- a/knxPython/main.py +++ /dev/null @@ -1,35 +0,0 @@ -import knx -import time -import sys - -def updated(g1): - print(g1.value) - -print("start") -gos = knx.GroupObjectList() -gos.append(knx.GroupObject(2)) -gos.append(knx.GroupObject(2)) -gos.append(knx.GroupObject(2)) -gos.append(knx.GroupObject(1)) -curr = gos[0] -min = gos[1] -max = gos[2] -reset = gos[3] -reset.callBack(updated) - -knx.RegisterGroupObjects(gos) -knx.Start() -while True: - time.sleep(1) - cmd = sys.stdin.read(1) - if cmd == 'q': - break - elif cmd == 'p': - currentMode = knx.ProgramMode(not knx.ProgramMode()) - print("set programming mode to " + str(currentMode)) - elif cmd == 'w': - cmd = sys.stdin.read(4) - value = float(cmd) - curr.objectWrite(value) - print("wrote " + str(value) + " to curr") -print("end") \ No newline at end of file diff --git a/knxPython/setup.py b/knxPython/setup.py new file mode 100644 index 0000000..a01387a --- /dev/null +++ b/knxPython/setup.py @@ -0,0 +1,81 @@ +import os +import re +import sys +import platform +import subprocess + +from setuptools import setup, Extension, find_packages +from setuptools.command.build_ext import build_ext +from distutils.version import LooseVersion + +from write_version_info import get_version_info + +class CMakeExtension(Extension): + def __init__(self, name, sourcedir=''): + Extension.__init__(self, name, sources=[]) + self.sourcedir = os.path.abspath(sourcedir) + + +class CMakeBuild(build_ext): + def run(self): + try: + out = subprocess.check_output(['cmake', '--version']) + except OSError: + raise RuntimeError("CMake must be installed to build the following extensions: " + + ", ".join(e.name for e in self.extensions)) + + cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.decode()).group(1)) + if cmake_version < LooseVersion('3.5.0'): + raise RuntimeError("CMake >= 3.5.0 is required") + + for ext in self.extensions: + self.build_extension(ext) + + def build_extension(self, ext): + extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) + cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, + '-DPYTHON_EXECUTABLE=' + sys.executable] + + build_type = os.environ.get("BUILD_TYPE", "Release") + build_args = ['--config', build_type] + + # Pile all .so in one place and use $ORIGIN as RPATH + cmake_args += ["-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"] + cmake_args += ["-DCMAKE_INSTALL_RPATH={}".format("$ORIGIN")] + + if platform.system() == "Windows": + cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(build_type.upper(), extdir)] + if sys.maxsize > 2**32: + cmake_args += ['-A', 'x64'] + build_args += ['--', '/m'] + else: + cmake_args += ['-DCMAKE_BUILD_TYPE=' + build_type] + build_args += ['--', '-j4'] + + env = os.environ.copy() + env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''), + self.distribution.get_version()) + if not os.path.exists(self.build_temp): + os.makedirs(self.build_temp) + subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) + subprocess.check_call(['cmake', + '--build', '.', + '--target', ext.name + ] + build_args, + cwd=self.build_temp) + +setup( + name='knxPython', + version=get_version_info()[3], + author='Thomas Kunze', + author_email='thomas.kunze@gmx.com', + description='Lib to implement knx-devices', + long_description_content_type="text/markdown", + long_description=open("README.md").read(), + ext_modules=[CMakeExtension('knx')], + packages=find_packages(), + license="GPL3", + cmdclass=dict(build_ext=CMakeBuild), + url="https://github.com/thelsing/knx", + zip_safe=False +) \ No newline at end of file diff --git a/knxPython/write_version_info.py b/knxPython/write_version_info.py new file mode 100644 index 0000000..cd8e254 --- /dev/null +++ b/knxPython/write_version_info.py @@ -0,0 +1,49 @@ +import subprocess +import time +import sys +import socket + +def get_version_info(): + + try: + git_revision = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("utf-8") .split("\n")[0] + git_branch = subprocess.check_output(["git", "rev-parse","--abbrev-ref", "HEAD"]).decode("utf-8").split("\n")[0] + except (subprocess.CalledProcessError, OSError): + git_revision = "" + git_branch = "non-git" + + def read_version(): + with open("VERSION") as f: + return f.readline().strip() + + build_datetime = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) + version_number = read_version() + + hostname = socket.gethostname() + + return git_revision, git_branch, build_datetime, version_number, hostname + +def print_version_number(): + sys.stdout.write(get_version_info()[3]) + +if __name__ =="__main__": + + output_file = sys.argv[1] + with open(output_file, "w") as fout: + fout.write("""#pragma once + +namespace knx{{ +namespace version{{ + +auto constexpr git_revision = u8"{0}"; +auto constexpr git_branch = u8"{1}"; +auto constexpr build_datetime = u8"{2}"; +auto constexpr version_number = u8"{3}"; +auto constexpr build_hostname = u8"{4}"; + + +}} +}} + +""".format(*get_version_info())) + From d232fcd9340ec9dfcecf56fa88b0c8bf14d64186 Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Sat, 29 Jun 2019 22:45:02 +0200 Subject: [PATCH 2/2] . --- knxPython/Manifest.in | 1 - 1 file changed, 1 deletion(-) diff --git a/knxPython/Manifest.in b/knxPython/Manifest.in index 98bb358..a1f2447 100644 --- a/knxPython/Manifest.in +++ b/knxPython/Manifest.in @@ -11,5 +11,4 @@ include README.md global-exclude .git graft pybind11/include -graft graft src