Browse Source

new example extension "lib_test"

master
heck 4 years ago
parent
commit
5a5e748f17
  1. 96
      examples/ext/lib_test/Makefile
  2. 10
      examples/ext/lib_test/Makefile.conf
  3. 47
      examples/ext/lib_test/lib_test/Makefile
  4. 12
      examples/ext/lib_test/lib_test/Makefile.conf
  5. 35
      examples/ext/lib_test/lib_test/gen/Makefile
  6. 13
      examples/ext/lib_test/lib_test/gen/config.json
  7. 14
      examples/ext/lib_test/lib_test/lib_test.cc
  8. 15
      examples/ext/lib_test/pyproject.toml
  9. 2
      examples/ext/lib_test/requirements.txt
  10. 42
      examples/ext/lib_test/setup.cfg
  11. 22
      examples/ext/lib_test/setup.py
  12. 6
      examples/ext/lib_test/tests/test_lib_test.py

96
examples/ext/lib_test/Makefile

@ -0,0 +1,96 @@
include Makefile.conf
.PHONY: all install-pepacidgen gen compile compile-inplace dist dist-egg dist-whl install install-user \
venv envtest install-test test develop docs clean clean-all clean-docs
all: install
# Install pEpACIDgen from this repo, not from pypi
install-pepacidgen:
pip3 install -r requirements.txt --find-links ../../../dist/
# Build
# =====
gen: install-pepacidgen
$(MAKE) -C lib_test gen
compile: gen
python3 setup.py build_ext $(DEBUG_OPT) $(PREFIX_OPT)
compile-inplace: gen
python3 setup.py build_ext $(DEBUG_OPT) $(PREFIX_OPT) --inplace
# Packaging
# =========
# create wheel and egg package in dist/
dist: dist-whl dist-egg
# create wheel package in dist/
dist-whl: compile
python3 setup.py bdist_wheel
# create egg package in dist/
dist-egg: compile
python3 setup.py bdist_egg
# Installation
# ============
# installs the package system wide
install: compile
pip3 install .
# installs the package into your user home
install-user: compile
pip3 install . --user
# Envrionment
# ===========
# Creates and activates a new venv that has the LD_LIBRARY_PATH/DYLD_LIBRARY_PATH
# already set for the prefix specified in local.conf
# Only activates venv if already existing
venv:
python3 -m venv $(VENV_DIR)
LD_LIBRARY_PATH=../../lib/lib_test/ \
DYLD_LIBRARY_PATH=../../lib/lib_test/ \
bash --rcfile $(VENV_DIR)/bin/activate
# Tests if the current environment is able to load the pEp module
envtest:
python3 -c 'import lib_test'
# Test
# ====
# Use these targets only in venv created with 'make venv'
install-test: compile
pip3 install .[test]
test:
pytest
# Development
develop: compile
pip install -e .
# Housekeeping
# ============
clean-all: clean
rm -rf $(VENV_DIR)
clean:
$(MAKE) -C lib_test/ clean
rm -rf $(BUILD_DIR)
rm -rf $(DIST_DIR)
rm -rf $(PYTHON_ARTIFACTS)
rm -rf $(BUILD_INPLACE)
# Makefile based build of C++ parts only
# ======================================
makefile-build:
$(MAKE) -C lib_test/
makefile-clean:
$(MAKE) -C lib_test/ clean

10
examples/ext/lib_test/Makefile.conf

@ -0,0 +1,10 @@
HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
# Constants
BUILD_DIR = ./build
DIST_DIR = ./dist
BUILD_INPLACE = ./lib_test/lib_test.cpython-38-darwin.so
PYTHON_ARTIFACTS += ./.eggs
PYTHON_ARTIFACTS += ./lib_test.egg-info
PYTHON_ARTIFACTS += ./.pytest_cache
VENV_DIR = ./venv

47
examples/ext/lib_test/lib_test/Makefile

@ -0,0 +1,47 @@
include Makefile.conf
TARGET=lib_test.so
# Swap here, for static vs dyn linking
TARGET_MODULE_DYN=$(TARGET)
TARGET_MODULE_STATIC=
CXX=clang
CXXFLAGS+=-std=c++11 -g
SRCS+=$(wildcard *.cc)
OBJS+=$(SRCS:.cc=.o)
CXXFLAGS+=$(INCLUDES)
LDFLAGS_DYN+=-undefined dynamic_lookup $(LIBS_PATH) $(LIBS)
LDFLAGS_STATIC+=-undefined dynamic_lookup
$(info -----BUILD INFO----)
$(info SRCS $(SRCS))
$(info OBJS $(OBJS))
.PHONY: all gen gen-pybind module_dyn module_static clean
all: gen compile
gen:
$(MAKE) -C gen
gen-pybind:
$(MAKE) -C gen pybind
compile: $(TARGET)
$(TARGET_MODULE_DYN) : $(OBJS)
$(CXX) $(LDFLAGS_DYN) -o $@ $^
$(TARGET_MODULE_STATIC) : $(OBJS) $(LIBS_STATIC)
$(CXX) $(LDFLAGS_STATIC) -o $@ $^
clean:
rm -f $(TARGET)
rm -f $(OBJS)
clean-all: clean
$(MAKE) -C gen clean

12
examples/ext/lib_test/lib_test/Makefile.conf

@ -0,0 +1,12 @@
# pyBind11 and python headers
INCLUDES+=$(shell pybind11-config --includes)
# example lib
INCLUDES+=-I../../../lib/lib_test
# static lib (.a)
LIBS_STATIC+=../../../lib/lib_test/liblib_test.a
# dynamic lib (.so)
LIBS+=-llib_test
LIBS_PATH+=-L../../../lib/lib_test/

35
examples/ext/lib_test/lib_test/gen/Makefile

@ -0,0 +1,35 @@
include ../Makefile.conf
YML2_FILE=py_module.yml2
YSL2_FILE=$(shell pEp_acid_gen-config)
PYBIND11_FILE=py_module.pybind11
DEBUG_AST_FILE=lib_test.h.ast.json
DEBUG_ACID_FILE=lib_test.h.acid.json
DEBUG_YML_FILE=lib_test.h.acid.yml
$(info -----LIB_TEST GEN----)
$(info YML2_FILE $(YML2_FILE))
$(info YSL2_FILE $(YSL2_FILE))
$(info CC_FILE $(PYBIND11_FILE))
.PHONY = all yml pybind11
all: pybind
yml: $(YML2_FILE)
pybind: $(PYBIND11_FILE)
$(YML2_FILE): config.json
pEp_acid_gen $^
$(PYBIND11_FILE) : $(YML2_FILE)
yml2proc --encoding=utf8 -y $(YSL2_FILE) $(YML2_FILE)
clean:
rm -f $(YML2_FILE)
rm -f $(PYBIND11_FILE)
rm -f $(DEBUG_AST_FILE)
rm -f $(DEBUG_ACID_FILE)
rm -f $(DEBUG_YML_FILE)

13
examples/ext/lib_test/lib_test/gen/config.json

@ -0,0 +1,13 @@
{
"module_name": "lib_test",
"header_filename": "../../../../../examples/lib/lib_test/lib_test.h",
"libclang_path": "/opt/local/libexec/llvm-9.0/lib/libclang.dylib",
"variables": [
],
"functions": [
"filtertype_to_string"
],
"debug_ast" : "True",
"debug_acid" : "True",
"debug_yml" : "True"
}

14
examples/ext/lib_test/lib_test/lib_test.cc

@ -0,0 +1,14 @@
#include <string>
#include <iostream>
#include <pybind11/pybind11.h>
#include <pybind11/detail/common.h>
#include "lib_test.h"
using namespace std;
PYBIND11_MODULE(lib_test, m) {
#include "gen/py_module.pybind11"
}

15
examples/ext/lib_test/pyproject.toml

@ -0,0 +1,15 @@
[build-system]
# Preparing for PEP-517/PEP-518, but not in effect yet.
# These requires are not effective yet, setup.cfg is.
requires = [
"setuptools >=39.2.0",
"wheel >= 0.35.1", ]
build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-rP"
testpaths = [
"tests",
]

2
examples/ext/lib_test/requirements.txt

@ -0,0 +1,2 @@
pEpACIDgen
pyBind11

42
examples/ext/lib_test/setup.cfg

@ -0,0 +1,42 @@
[metadata]
name = lib_test
url = https://pep.foundation
download_url =
ext_package = lib_test
author = heck
author_email = heck@pep-project.org
maintainer = heck
maintainer_email = heck@pep.foundation
description = pEpACIDgen example extension module
long_description = file: README.md
keywords = pEpACIDgen
license = GNU Affero General Public License
license_files = LICENSE.txt
platforms = linux, macOs
classifiers =
Intended Audience :: Developers
Topic :: Utilities
License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
Natural Language :: English
Operating System :: OS Independent
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Development Status :: 3 - Alpha
[options]
zip_safe = false
include_package_data = true
python_requires = >= 3.6
test_suite = tests
install_requires =
# setup_requires is deprecated/redundant with pyproject.toml, but lets keep both ways around for now
setup_requires =
setuptools >=39.2.0
wheel >= 0.35.1
[options.extras_require]
# To install these dependencies, run pip install .[test]
test =
pytest

22
examples/ext/lib_test/setup.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# This file is under GNU Affero General Public License 3.0
# see LICENSE.txt
from setuptools import setup, Extension
ext_modules = [
Extension(
"lib_test",
["lib_test/lib_test.cc"],
include_dirs=['../../lib/lib_test',
'/opt/local/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8',
'venv/lib/python3.8/site-packages/pybind11/include'],
extra_compile_args=['-std=c++11'],
libraries=['lib_test'],
library_dirs=['../../lib/lib_test/']
)
]
setup(
packages=['lib_test'],
ext_modules=ext_modules
)

6
examples/ext/lib_test/tests/test_lib_test.py

@ -0,0 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This file is under GNU Affero General Public License 3.0
# see LICENSE.txt
import pytest
Loading…
Cancel
Save