From 4b4f53c30126d29b48cbe9a0dc76349dd9db965f Mon Sep 17 00:00:00 2001 From: gorloffslava Date: Thu, 7 Nov 2024 19:25:04 +0500 Subject: [PATCH 1/3] Added meson-based build system --- meson.build | 57 ++++++++++++++++++++++++++++ pyproject.toml | 54 ++++++++++++++++++++++++++ setup.py | 100 ------------------------------------------------- 3 files changed, 111 insertions(+), 100 deletions(-) create mode 100644 meson.build create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..e95e44b --- /dev/null +++ b/meson.build @@ -0,0 +1,57 @@ +# === @begin: General === +project( + 'awslambdaric', + 'c', 'cpp', + version: '3.0.0.dev0', + default_options: [ + 'c_std=gnu17', + 'cpp_std=gnu++23', + 'buildtype=release', + ], + meson_version: '>=1.3.0' +) +# === @end: General === + + +# === @begin: Meson modules imports === +fs = import('fs') +py = import('python').find_installation(pure: false) +# === @end: Meson modules imports === + + +# === @begin: Dependencies === +libcurl = dependency('CURL', modules: ['CURL::libcurl']) +aws_lambda_cpp = dependency('aws-lambda-runtime', method: 'cmake', modules: ['AWS::aws-lambda-runtime']) +# === @end: Dependencies === + + +# === @begin: Compilable Python modules === +py.extension_module( + 'runtime_client', + + ['awslambdaric/runtime_client.cpp'], + + install: true, + subdir: 'awslambdaric/', + dependencies: [ + # Eugo-managed + libcurl, + aws_lambda_cpp, + ] +) +# === @end: Compilable Python modules === + + +# === @begin: Pure Python modules === +install_subdir( + 'awslambdaric/', + install_dir: py.get_install_dir(), + install_tag: 'python-runtime', + + follow_symlinks: true, + + exclude_files: [ + 'runtime_client.cpp' + ] +) +# === @end: Pure Python modules === diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ed19924 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,54 @@ +[build-system] +build-backend = 'mesonpy' + +requires = [ + 'meson', + 'meson-python' +] + + +[project] +name = 'awslambdaric' +version = '3.0.0.dev0' +readme = 'README.md' +requires-python = '>=3.6' +license = {file = 'LICENSE'} +author = 'Amazon Web Services' +description = 'AWS Lambda Runtime Interface Client for Python' + +classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'Natural Language :: English', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'License :: OSI Approved :: Apache Software License', + 'Operating System :: OS Independent', +] + +dependencies = [ + 'simplejson>=3.18.4', +] + +[project.optional-dependencies] +dev = [ + 'coverage>=4.4.0', + 'flake8>=3.3.0', + 'tox>=2.2.1', + 'pytest_cov>=2.4.0', + 'pylint>=1.7.2', + 'black>=20.8b0', + 'bandit>=1.6.2' +] + +test = [ + 'pytest>=3.0.7', + 'mock>=2.0.0', + 'parameterized>=0.9.0' +] diff --git a/setup.py b/setup.py deleted file mode 100644 index 2544b21..0000000 --- a/setup.py +++ /dev/null @@ -1,100 +0,0 @@ -""" -Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. -""" - -import io -import os -import platform -from subprocess import check_call, check_output -from setuptools import Extension, find_packages, setup -from awslambdaric import __version__ - - -def get_curl_extra_linker_flags(): - # We do not want to build the dependencies during packaging - if platform.system() != "Linux" or os.getenv("BUILD") == "true": - return [] - - # Build the dependencies - check_call(["./scripts/preinstall.sh"]) - - # call curl-config to get the required linker flags - cmd = ["./deps/artifacts/bin/curl-config", "--static-libs"] - curl_config = check_output(cmd).decode("utf-8").replace("\n", "") - - # It is expected that the result of the curl-config call is similar to - # "/tmp/pip-req-build-g9dlug7g/deps/artifacts/lib/libcurl.a -lidn2" - # we want to return just the extra flags - flags = curl_config.split(" ")[1:] - - return flags - - -def get_runtime_client_extension(): - if platform.system() != "Linux" and os.getenv("BUILD") != "true": - print( - "The native runtime_client only builds on Linux. Skipping its compilation." - ) - return [] - - runtime_client = Extension( - "runtime_client", - ["awslambdaric/runtime_client.cpp"], - extra_compile_args=["--std=c++11"], - library_dirs=["deps/artifacts/lib", "deps/artifacts/lib64"], - libraries=["aws-lambda-runtime", "curl"], - extra_link_args=get_curl_extra_linker_flags(), - include_dirs=["deps/artifacts/include"], - ) - - return [runtime_client] - - -def read(*filenames, **kwargs): - encoding = kwargs.get("encoding", "utf-8") - sep = kwargs.get("sep", os.linesep) - buf = [] - for filename in filenames: - with io.open(filename, encoding=encoding) as f: - buf.append(f.read()) - return sep.join(buf) - - -def read_requirements(req="base.txt"): - content = read(os.path.join("requirements", req)) - return [ - line for line in content.split(os.linesep) if not line.strip().startswith("#") - ] - - -setup( - name="awslambdaric", - version=__version__, - author="Amazon Web Services", - description="AWS Lambda Runtime Interface Client for Python", - long_description=read("README.md"), - long_description_content_type="text/markdown", - url="https://github.com/aws/aws-lambda-python-runtime-interface-client", - packages=find_packages( - exclude=("tests", "tests.*", "docs", "examples", "versions") - ), - install_requires=read_requirements("base.txt"), - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "Natural Language :: English", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "License :: OSI Approved :: Apache Software License", - "Operating System :: OS Independent", - ], - python_requires=">=3.6", - ext_modules=get_runtime_client_extension(), - test_suite="tests", -) From d013ceda81d4d7c5a3c68cc9415a7dbdb57cd838 Mon Sep 17 00:00:00 2001 From: gorloffslava <31761951+gorloffslava@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:30:16 +0500 Subject: [PATCH 2/3] Update meson.build --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index e95e44b..0118b5f 100644 --- a/meson.build +++ b/meson.build @@ -32,7 +32,7 @@ py.extension_module( ['awslambdaric/runtime_client.cpp'], install: true, - subdir: 'awslambdaric/', + # subdir: 'awslambdaric/', # They install that into site_packages root, that is really prone to collisions with other packages as `runtime_client` is quite common noun. dependencies: [ # Eugo-managed libcurl, From 7c53e3408d5f2a51e02825ddd3c974c4c1668f6b Mon Sep 17 00:00:00 2001 From: Benjamin Leff Date: Mon, 1 Sep 2025 20:35:19 -0500 Subject: [PATCH 3/3] feat: add upstream compatibility --- meson.build | 18 +++++++++++------- pyproject.toml | 12 ++++++++---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/meson.build b/meson.build index 0118b5f..110d362 100644 --- a/meson.build +++ b/meson.build @@ -2,13 +2,17 @@ project( 'awslambdaric', 'c', 'cpp', - version: '3.0.0.dev0', default_options: [ 'c_std=gnu17', 'cpp_std=gnu++23', 'buildtype=release', ], - meson_version: '>=1.3.0' + meson_version: '>=1.3.0', + version: run_command([ + 'sed', '-n', + 's/__version__\\s*=\\s*[\'"]\\([^\'\"]*\\)[\'\"]/\\1/p', + meson.project_source_root() / 'awslambdaric' / '__init__.py' + ], check: true).stdout().strip() ) # === @end: General === @@ -31,13 +35,13 @@ py.extension_module( ['awslambdaric/runtime_client.cpp'], - install: true, - # subdir: 'awslambdaric/', # They install that into site_packages root, that is really prone to collisions with other packages as `runtime_client` is quite common noun. dependencies: [ # Eugo-managed libcurl, aws_lambda_cpp, - ] + ], + install: true, + subdir: 'awslambdaric/' # Originally, they installed that into site_packages root, that is really prone to collisions with other packages as `runtime_client` is quite common noun. ) # === @end: Compilable Python modules === @@ -45,13 +49,13 @@ py.extension_module( # === @begin: Pure Python modules === install_subdir( 'awslambdaric/', - install_dir: py.get_install_dir(), + install_dir: py.get_install_dir() / 'awslambdaric', install_tag: 'python-runtime', follow_symlinks: true, exclude_files: [ 'runtime_client.cpp' - ] + ], ) # === @end: Pure Python modules === diff --git a/pyproject.toml b/pyproject.toml index ed19924..b295c14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,21 +1,25 @@ [build-system] build-backend = 'mesonpy' - requires = [ 'meson', - 'meson-python' + 'meson_python' ] [project] name = 'awslambdaric' -version = '3.0.0.dev0' +dynamic = ["version"] readme = 'README.md' requires-python = '>=3.6' license = {file = 'LICENSE'} -author = 'Amazon Web Services' +authors = [ + {name = "Eugo, Inc."}, + {name = "Amazon Web Services"}, +] + description = 'AWS Lambda Runtime Interface Client for Python' + classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers',