From f00b617c238341d63bf2400e95710397697cb001 Mon Sep 17 00:00:00 2001 From: holga Date: Sat, 13 Jul 2019 18:44:44 +0200 Subject: [PATCH 1/3] try fix darwin --- python/src/deltachat/_build.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/python/src/deltachat/_build.py b/python/src/deltachat/_build.py index 7eb1eff63..ec597c8e8 100644 --- a/python/src/deltachat/_build.py +++ b/python/src/deltachat/_build.py @@ -2,6 +2,7 @@ import distutils.ccompiler import distutils.log import distutils.sysconfig import tempfile +import platform import os import cffi @@ -10,7 +11,18 @@ def ffibuilder(): projdir = os.environ.get('DCC_RS_DEV') target = os.environ.get('DCC_RS_TARGET', 'release') if projdir: - libs = ['rt', 'dl', 'm'] + if platform.system() == 'Darwin': + libs = ['resolv', 'dl'] + extra_link_args = [ + '-framework', 'CoreFoundation', + '-framework', 'CoreServices', + '-framework', 'Security', + ] + elif platform.system() == 'Linux': + libs = ['rt', 'dl', 'm'] + extra_link_args = [] + else: + raise NotImplementedError("Compilation not supported yet on Windows, can you help?") objs = [os.path.join(projdir, 'target', target, 'libdeltachat.a')] incs = [os.path.join(projdir, 'deltachat-ffi')] else: @@ -43,6 +55,7 @@ def ffibuilder(): include_dirs=incs, libraries=libs, extra_objects=objs, + extra_link_args=extra_link_args, ) builder.cdef(""" typedef int... time_t; @@ -53,15 +66,18 @@ def ffibuilder(): distutils.log.set_verbosity(distutils.log.INFO) cc = distutils.ccompiler.new_compiler(force=True) distutils.sysconfig.customize_compiler(cc) - with tempfile.NamedTemporaryFile(mode='w', suffix='.h') as src_fp: - src_fp.write('#include ') - src_fp.flush() - with tempfile.NamedTemporaryFile(mode='r') as dst_fp: - cc.preprocess(source=src_fp.name, - output_file=dst_fp.name, - include_dirs=incs, - macros=[('PY_CFFI', '1')]) + with tempfile.TemporaryDirectory() as tmpdir: + src_name = os.path.join(tmpdir, "prep.h") + dst_name = os.path.join(tmpdir, "prep2.c") + with open(src_name, "w") as src_fp: + src_fp.write('#include ') + cc.preprocess(source=src_name, + output_file=dst_name, + include_dirs=incs, + macros=[('PY_CFFI', '1')]) + with open(dst_name, "r") as dst_fp: builder.cdef(dst_fp.read()) + builder.cdef(""" extern "Python" uintptr_t py_dc_callback( dc_context_t* context, From aa8264439271d9c8b90e55744d345d110f3a009f Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 14 Jul 2019 09:16:51 +0200 Subject: [PATCH 2/3] fix py27 --- python/src/deltachat/_build.py | 6 +++++- python/tox.ini | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/python/src/deltachat/_build.py b/python/src/deltachat/_build.py index ec597c8e8..651d8edde 100644 --- a/python/src/deltachat/_build.py +++ b/python/src/deltachat/_build.py @@ -5,6 +5,7 @@ import tempfile import platform import os import cffi +import shutil def ffibuilder(): @@ -66,7 +67,8 @@ def ffibuilder(): distutils.log.set_verbosity(distutils.log.INFO) cc = distutils.ccompiler.new_compiler(force=True) distutils.sysconfig.customize_compiler(cc) - with tempfile.TemporaryDirectory() as tmpdir: + tmpdir = tempfile.mkdtemp() + try: src_name = os.path.join(tmpdir, "prep.h") dst_name = os.path.join(tmpdir, "prep2.c") with open(src_name, "w") as src_fp: @@ -77,6 +79,8 @@ def ffibuilder(): macros=[('PY_CFFI', '1')]) with open(dst_name, "r") as dst_fp: builder.cdef(dst_fp.read()) + finally: + shutil.rmtree(tmpdir) builder.cdef(""" extern "Python" uintptr_t py_dc_callback( diff --git a/python/tox.ini b/python/tox.ini index 8405deb4e..68167887f 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -27,7 +27,6 @@ commands = [testenv:lint] skipsdist = True usedevelop = True -basepython = python3.5 deps = flake8 # pygments required by rst-lint From 3e3403d3d71a7893d00a4bbc6370a7db18365783 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 14 Jul 2019 09:58:51 +0200 Subject: [PATCH 3/3] try using setuptools_scm for automatic versioning based on py-* tags (#187) * try using setuptools_scm for automatic versioning based on py-* tags * circument problem with pip-wheel isolation and setuptoosl_scm * always provide version, address @flub comment --- python/CHANGELOG | 7 +++++++ python/setup.py | 24 ++++++++---------------- python/src/deltachat/__init__.py | 7 ++++++- python/tests/package_wheels.py | 15 +++++++++++++++ python/tox.ini | 2 +- 5 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 python/tests/package_wheels.py diff --git a/python/CHANGELOG b/python/CHANGELOG index e906e5e1d..0dfffc4e1 100644 --- a/python/CHANGELOG +++ b/python/CHANGELOG @@ -1,3 +1,10 @@ +0.600.1 +--------- + +- introduce automatic versioning via setuptools_scm, + based on py-X.Y.Z tags + + 0.600.0 --------- diff --git a/python/setup.py b/python/setup.py index bd1919ad2..b0e94339d 100644 --- a/python/setup.py +++ b/python/setup.py @@ -4,14 +4,19 @@ import re def main(): - long_description, version = read_meta() + with open("README.rst") as f: + long_description = f.read() setuptools.setup( name='deltachat', - version=version, + setup_requires=['setuptools_scm', 'cffi>=1.0.0'], + use_scm_version = { + "root": "..", + "relative_to": __file__, + 'tag_regex': r'^(?Ppy-)?(?P[^\+]+)(?P.*)?$', + }, description='Python bindings for the Delta Chat Core library using CFFI against the Rust-implemented libdeltachat', long_description=long_description, author='holger krekel, Floris Bruynooghe, Bjoern Petersen and contributors', - setup_requires=['cffi>=1.0.0'], install_requires=['cffi>=1.0.0', 'attrs', 'six'], packages=setuptools.find_packages('src'), package_dir={'': 'src'}, @@ -27,18 +32,5 @@ def main(): ) -def read_meta(): - with open(os.path.join("src", "deltachat", "__init__.py")) as f: - for line in f: - m = re.match('__version__ = "(\S*).*"', line) - if m: - version, = m.groups() - break - - with open("README.rst") as f: - long_desc = f.read() - return long_desc, version - - if __name__ == "__main__": main() diff --git a/python/src/deltachat/__init__.py b/python/src/deltachat/__init__.py index 8bb855ca5..a8d338aba 100644 --- a/python/src/deltachat/__init__.py +++ b/python/src/deltachat/__init__.py @@ -2,7 +2,12 @@ from deltachat import capi, const from deltachat.capi import ffi from deltachat.account import Account # noqa -__version__ = "0.600.0" +from pkg_resources import get_distribution, DistributionNotFound +try: + __version__ = get_distribution(__name__).version +except DistributionNotFound: + # package is not installed + __version__ = "0.0.0.dev0-unknown" _DC_CALLBACK_MAP = {} diff --git a/python/tests/package_wheels.py b/python/tests/package_wheels.py new file mode 100644 index 000000000..1b67fdcb3 --- /dev/null +++ b/python/tests/package_wheels.py @@ -0,0 +1,15 @@ + +import os +import sys +import subprocess + + +if __name__ == "__main__": + assert len(sys.argv) == 2 + wheelhousedir = sys.argv[1] + # pip wheel will build in an isolated tmp dir that does not have git + # history so setuptools_scm can not automatically determine a + # version there. So pass in the version through an env var. + version = subprocess.check_output(["python", "setup.py", "--version"]).strip().split(b"\n")[-1] + os.environ["SETUPTOOLS_SCM_PRETEND_VERSION"] = version.decode("ascii") + subprocess.check_call(("pip wheel . -w %s" % wheelhousedir).split()) diff --git a/python/tox.ini b/python/tox.ini index 68167887f..ccac3dee6 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -9,7 +9,7 @@ envlist = [testenv] commands = pytest -rsXx {posargs:tests} - pip wheel . -w {toxworkdir}/wheelhouse + python tests/package_wheels.py {toxworkdir}/wheelhouse passenv = TRAVIS DCC_RS_DEV