mirror of
https://github.com/thelsing/knx.git
synced 2024-12-18 19:08:18 +01:00
add setup.py for publishing on pypi.
This commit is contained in:
parent
07a141965f
commit
954931abdc
3
.gitignore
vendored
3
.gitignore
vendored
@ -23,6 +23,9 @@ bld/
|
||||
[Ll]og/
|
||||
out
|
||||
flash.bin
|
||||
build
|
||||
dist
|
||||
*.egg-info
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
|
@ -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)
|
||||
|
15
knxPython/Manifest.in
Normal file
15
knxPython/Manifest.in
Normal file
@ -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
|
1
knxPython/VERSION
Normal file
1
knxPython/VERSION
Normal file
@ -0,0 +1 @@
|
||||
0.1.5
|
@ -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")
|
81
knxPython/setup.py
Normal file
81
knxPython/setup.py
Normal file
@ -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
|
||||
)
|
49
knxPython/write_version_info.py
Normal file
49
knxPython/write_version_info.py
Normal file
@ -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()))
|
||||
|
Loading…
Reference in New Issue
Block a user