You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2024/04/17 22:08:39 UTC
(qpid-proton) 01/02: NO-JIRA: [Python] Some small refactorings to clean package build
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit cafa64a19ecefad319050b41a47dd112b46eee44
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Tue Apr 16 11:30:31 2024 -0400
NO-JIRA: [Python] Some small refactorings to clean package build
---
.appveyor.yml | 2 +-
.github/workflows/build.yml | 3 +-
azure-pipelines/steps.yml | 2 +-
python/CMakeLists.txt | 1 +
python/MANIFEST.in | 1 +
python/{requirements.txt => ci_requirements.txt} | 1 +
python/cproton_ext.c | 103 +++++++++++++++++++++++
python/ext_build.py | 100 +++-------------------
8 files changed, 120 insertions(+), 93 deletions(-)
diff --git a/.appveyor.yml b/.appveyor.yml
index 3de159312..ab07c58bf 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -29,7 +29,7 @@ install:
- vcpkg integrate install
# https://pythonhosted.org/CodeChat/appveyor.yml.html
- "%PYTHON%\\python.exe -m pip install --user --upgrade pip"
-- "%PYTHON%\\python.exe -m pip install --user --upgrade setuptools wheel tox flake8"
+- "%PYTHON%\\python.exe -m pip install --user --upgrade -r python/ci_requirements.txt"
cache:
- C:\ProgramData\chocolatey\bin -> .appveyor.yml
- C:\ProgramData\chocolatey\lib -> .appveyor.yml
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index fbbbb6d90..0633585bf 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -32,12 +32,13 @@ jobs:
- name: Setup python
uses: actions/setup-python@v5
with:
+ cache-dependency-path: python/ci_requirements.txt
python-version: 3.9
architecture: x64
cache: 'pip'
- name: Install python dependencies
run: |
- python -m pip install --upgrade -r python/requirements.txt
+ python -m pip install --upgrade -r python/ci_requirements.txt
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
diff --git a/azure-pipelines/steps.yml b/azure-pipelines/steps.yml
index 821f85ddf..4ec0efae5 100644
--- a/azure-pipelines/steps.yml
+++ b/azure-pipelines/steps.yml
@@ -6,7 +6,7 @@ steps:
architecture: $(PythonArch)
- script: |
python -m pip install --user --upgrade pip
- python -m pip install --user --upgrade setuptools wheel tox flake8
+ python -m pip install --user --upgrade -r python/ci_requirements.txt
name: InstallPythonModules
- task: CMake@1
name: CMakeConfigure
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index deb74a8c6..8978c0b73 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -55,6 +55,7 @@ set(py_dist_files
MANIFEST.in
ext_build.py
cproton.h
+ cproton_ext.c
cproton.py
docs/conf.py
docs/index.rst
diff --git a/python/MANIFEST.in b/python/MANIFEST.in
index b99a0e8dc..2c2e5af0b 100644
--- a/python/MANIFEST.in
+++ b/python/MANIFEST.in
@@ -1,6 +1,7 @@
include VERSION.txt
include ext_build.py
include cproton.h
+include cproton_ext.c
include cproton.py
graft docs
graft src
diff --git a/python/requirements.txt b/python/ci_requirements.txt
similarity index 89%
rename from python/requirements.txt
rename to python/ci_requirements.txt
index 7f92aa2bd..9b0ec6a7f 100644
--- a/python/requirements.txt
+++ b/python/ci_requirements.txt
@@ -1,4 +1,5 @@
pip
+build
setuptools
wheel
flake8
diff --git a/python/cproton_ext.c b/python/cproton_ext.c
new file mode 100644
index 000000000..a80ecc688
--- /dev/null
+++ b/python/cproton_ext.c
@@ -0,0 +1,103 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "proton/version.h"
+#include "proton/types.h"
+#include "proton/object.h"
+#include "proton/error.h"
+#include "proton/condition.h"
+#include "proton/connection.h"
+#include "proton/session.h"
+#include "proton/link.h"
+#include "proton/terminus.h"
+#include "proton/delivery.h"
+#include "proton/disposition.h"
+#include "proton/transport.h"
+#include "proton/event.h"
+#include "proton/message.h"
+#include "proton/sasl.h"
+#include "proton/ssl.h"
+#include "proton/codec.h"
+#include "proton/connection_driver.h"
+#include "proton/cid.h"
+
+static void pn_pyref_incref(void *object);
+static void pn_pyref_decref(void *object);
+
+static int pn_pyref_refcount(void *object) {
+ return 1;
+}
+
+pn_connection_t *pn_cast_pn_connection(void *x) { return (pn_connection_t *) x; }
+pn_session_t *pn_cast_pn_session(void *x) { return (pn_session_t *) x; }
+pn_link_t *pn_cast_pn_link(void *x) { return (pn_link_t *) x; }
+pn_delivery_t *pn_cast_pn_delivery(void *x) { return (pn_delivery_t *) x; }
+pn_transport_t *pn_cast_pn_transport(void *x) { return (pn_transport_t *) x; }
+
+static pn_class_t* PN_PYREF;
+PN_HANDLE(PN_PYCTX);
+
+static pn_class_t* pn_create_pyref() {
+ return pn_class_create("pn_pyref", NULL, NULL, pn_pyref_incref, pn_pyref_decref, pn_pyref_refcount);
+}
+
+pn_event_t *pn_collector_put_py(pn_collector_t *collector, void *context, pn_event_type_t type) {
+ return pn_collector_put(collector, PN_PYREF, context, type);
+}
+
+void pn_record_def_py(pn_record_t *record) {
+ pn_record_def(record, PN_PYCTX, PN_PYREF);
+}
+
+void *pn_record_get_py(pn_record_t *record) {
+ return pn_record_get(record, PN_PYCTX);
+}
+
+void pn_record_set_py(pn_record_t *record, void *value) {
+ pn_record_set(record, PN_PYCTX, value);
+}
+
+ssize_t pn_message_encode_py(pn_message_t *msg, char *bytes, size_t size) {
+ int err = pn_message_encode(msg, bytes, &size);
+ if (err == 0) return size;
+ else return err;
+}
+
+ssize_t pn_data_format_py(pn_data_t *data, char *bytes, size_t size) {
+ int err = pn_data_format(data, bytes, &size);
+ if (err == 0) return size;
+ else return err;
+}
+
+int pn_ssl_get_peer_hostname_py(pn_ssl_t *ssl, char *hostname, size_t size) {
+ return pn_ssl_get_peer_hostname(ssl, hostname, &size);
+}
+
+const char *pn_event_class_name_py(pn_event_t *event) {
+ const pn_class_t *class = pn_event_class(event);
+ return class ? pn_class_name(class) : 0;
+}
+
+void init() {
+ PN_PYREF = pn_create_pyref();
+}
+
+
diff --git a/python/ext_build.py b/python/ext_build.py
index b1b39048c..fa53e7de0 100644
--- a/python/ext_build.py
+++ b/python/ext_build.py
@@ -32,14 +32,16 @@ ffibuilder = FFI()
cdefs = open('cproton.h').read()
ffibuilder.cdef(cdefs)
+sources = []
+extra = []
+libraries = []
+pkgconfig = []
+
proton_base = '.'
proton_c_src = os.path.join(proton_base, 'src')
proton_core_src = os.path.join(proton_c_src, 'core')
proton_c_include = os.path.join(proton_base, 'include')
-sources = []
-extra = []
-libraries = []
for root, dirs, files in os.walk(proton_core_src):
dirs.sort() # needed for os.walk to process directories in deterministic order
files.sort()
@@ -60,13 +62,13 @@ elif os.name == 'posix':
sources.append(os.path.join(proton_c_src, 'sasl', 'sasl.c'))
sources.append(os.path.join(proton_c_src, 'sasl', 'default_sasl.c'))
-pkgconfig = []
if os.name == 'nt':
libraries += ['crypt32', 'secur32']
sources.append(os.path.join(proton_c_src, 'ssl', 'schannel.cpp'))
else:
try:
- ssl_pkgcfg = cffi.pkgconfig.flags_from_pkgconfig(['openssl'])
+ # This is just used to test if pkgconfig finds openssl, if not it will throw
+ cffi.pkgconfig.flags_from_pkgconfig(['openssl'])
sources.append(os.path.join(proton_c_src, 'ssl', 'openssl.c'))
pkgconfig.append('openssl')
except cffi.pkgconfig.PkgConfigError:
@@ -75,7 +77,8 @@ else:
# Stub sasl
try:
- sasl_pkgcfg = cffi.pkgconfig.flags_from_pkgconfig(['libsasl2'])
+ # This is just used to test if pkgconfig finds cyrus sasl, if not it will throw
+ cffi.pkgconfig.flags_from_pkgconfig(['libsasl2'])
sources.append(os.path.join(proton_c_src, 'sasl', 'cyrus_sasl.c'))
pkgconfig.append('libsasl2')
except cffi.pkgconfig.PkgConfigError:
@@ -84,90 +87,7 @@ except cffi.pkgconfig.PkgConfigError:
include_dirs = [proton_c_include, proton_c_src]
macros = [('PROTON_DECLARE_STATIC', None)]
-c_code = r"""
-#include "proton/version.h"
-#include "proton/types.h"
-#include "proton/object.h"
-#include "proton/error.h"
-#include "proton/condition.h"
-#include "proton/connection.h"
-#include "proton/session.h"
-#include "proton/link.h"
-#include "proton/terminus.h"
-#include "proton/delivery.h"
-#include "proton/disposition.h"
-#include "proton/transport.h"
-#include "proton/event.h"
-#include "proton/message.h"
-#include "proton/sasl.h"
-#include "proton/ssl.h"
-#include "proton/codec.h"
-#include "proton/connection_driver.h"
-#include "proton/cid.h"
-
-static void pn_pyref_incref(void *object);
-static void pn_pyref_decref(void *object);
-
-static int pn_pyref_refcount(void *object) {
- return 1;
-}
-
-pn_connection_t *pn_cast_pn_connection(void *x) { return (pn_connection_t *) x; }
-pn_session_t *pn_cast_pn_session(void *x) { return (pn_session_t *) x; }
-pn_link_t *pn_cast_pn_link(void *x) { return (pn_link_t *) x; }
-pn_delivery_t *pn_cast_pn_delivery(void *x) { return (pn_delivery_t *) x; }
-pn_transport_t *pn_cast_pn_transport(void *x) { return (pn_transport_t *) x; }
-
-static pn_class_t* PN_PYREF;
-PN_HANDLE(PN_PYCTX);
-
-static pn_class_t* pn_create_pyref() {
- return pn_class_create("pn_pyref", NULL, NULL, pn_pyref_incref, pn_pyref_decref, pn_pyref_refcount);
-}
-
-pn_event_t *pn_collector_put_py(pn_collector_t *collector, void *context, pn_event_type_t type) {
- return pn_collector_put(collector, PN_PYREF, context, type);
-}
-
-void pn_record_def_py(pn_record_t *record) {
- pn_record_def(record, PN_PYCTX, PN_PYREF);
-}
-
-void *pn_record_get_py(pn_record_t *record) {
- return pn_record_get(record, PN_PYCTX);
-}
-
-void pn_record_set_py(pn_record_t *record, void *value) {
- pn_record_set(record, PN_PYCTX, value);
-}
-
-ssize_t pn_message_encode_py(pn_message_t *msg, char *bytes, size_t size) {
- int err = pn_message_encode(msg, bytes, &size);
- if (err == 0) return size;
- else return err;
-}
-
-ssize_t pn_data_format_py(pn_data_t *data, char *bytes, size_t size) {
- int err = pn_data_format(data, bytes, &size);
- if (err == 0) return size;
- else return err;
-}
-
-int pn_ssl_get_peer_hostname_py(pn_ssl_t *ssl, char *hostname, size_t size) {
- return pn_ssl_get_peer_hostname(ssl, hostname, &size);
-}
-
-const char *pn_event_class_name_py(pn_event_t *event) {
- const pn_class_t *class = pn_event_class(event);
- return class ? pn_class_name(class) : 0;
-}
-
-void init() {
- PN_PYREF = pn_create_pyref();
-}
-
-
-"""
+c_code = open('cproton_ext.c').read()
if len(pkgconfig) == 0:
ffibuilder.set_source(
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org