From 6a409c63da8e84c89da43338fe709ef7cd5a6a0f Mon Sep 17 00:00:00 2001 From: heck Date: Mon, 11 Jan 2021 23:50:14 +0100 Subject: [PATCH] pEpACIDgen Make example extension (synth_shed) a complete py-project --- gen/examples/Makefile | 9 +- gen/examples/ext/synth_shed/Makefile | 106 +++++++++++++----- gen/examples/ext/synth_shed/Makefile.conf | 35 +++--- gen/examples/ext/synth_shed/gen/Makefile | 19 ---- gen/examples/ext/synth_shed/pyproject.toml | 16 +++ gen/examples/ext/synth_shed/requirements.txt | 1 + gen/examples/ext/synth_shed/setup.cfg | 42 +++++++ gen/examples/ext/synth_shed/setup.py | 26 +++++ .../ext/synth_shed/synth_shed/Makefile | 46 ++++++++ .../ext/synth_shed/synth_shed/Makefile.conf | 12 ++ .../ext/synth_shed/synth_shed/gen/Makefile | 25 +++++ .../{ => synth_shed}/gen/config.json | 2 +- .../synth_shed/{ => synth_shed}/synth_shed.cc | 2 +- .../ext/synth_shed/tests/test_synth_shed.py | 9 ++ gen/examples/lib/lib_synth_shed/synth_shed.c | 2 +- 15 files changed, 282 insertions(+), 70 deletions(-) delete mode 100644 gen/examples/ext/synth_shed/gen/Makefile create mode 100644 gen/examples/ext/synth_shed/pyproject.toml create mode 100644 gen/examples/ext/synth_shed/requirements.txt create mode 100755 gen/examples/ext/synth_shed/setup.cfg create mode 100755 gen/examples/ext/synth_shed/setup.py create mode 100644 gen/examples/ext/synth_shed/synth_shed/Makefile create mode 100644 gen/examples/ext/synth_shed/synth_shed/Makefile.conf create mode 100644 gen/examples/ext/synth_shed/synth_shed/gen/Makefile rename gen/examples/ext/synth_shed/{ => synth_shed}/gen/config.json (80%) rename gen/examples/ext/synth_shed/{ => synth_shed}/synth_shed.cc (83%) create mode 100644 gen/examples/ext/synth_shed/tests/test_synth_shed.py diff --git a/gen/examples/Makefile b/gen/examples/Makefile index d475ee9..ffb7640 100644 --- a/gen/examples/Makefile +++ b/gen/examples/Makefile @@ -3,9 +3,14 @@ all: $(MAKE) -C lib/lib_test/ $(MAKE) -C lib/lib_synth_shed/ - $(MAKE) -C ext/synth_shed/ + $(MAKE) -C ext/synth_shed/synth_shed/ clean: $(MAKE) -C lib/lib_test/ clean $(MAKE) -C lib/lib_synth_shed/ clean - $(MAKE) -C ext/synth_shed/ clean + $(MAKE) -C ext/synth_shed/synth_shed/ clean + +clean-all: + $(MAKE) -C lib/lib_test/ clean + $(MAKE) -C lib/lib_synth_shed/ clean + $(MAKE) -C ext/synth_shed/synth_shed/ clean diff --git a/gen/examples/ext/synth_shed/Makefile b/gen/examples/ext/synth_shed/Makefile index bb0bc83..76dd31f 100644 --- a/gen/examples/ext/synth_shed/Makefile +++ b/gen/examples/ext/synth_shed/Makefile @@ -1,44 +1,96 @@ include Makefile.conf -TARGET=synth_shed.so +.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 -TARGET_MODULE_DYN=$(TARGET) -TARGET_MODULE_STATIC=$(TARGET) +all: install -CXX=clang -CXXFLAGS+=-std=c++11 -g +# Install pEpACIDgen from this repo, not from pypi +install-pepacidgen: + pip3 install -r requirements.txt --find-links ../../../dist/ -SRCS+=$(wildcard *.cc) -OBJS+=$(SRCS:.cc=.o) +# Build +# ===== +gen: install-pepacidgen + $(MAKE) -C synth_shed gen -CXXFLAGS+=$(INCLUDES) -I$(PREFIX)/include -LDFLAGS_DYN+=-undefined dynamic_lookup $(LIBS_PATH) $(LIBS) -LDFLAGS_STATIC+=-undefined dynamic_lookup +compile: gen + python3 setup.py build_ext $(DEBUG_OPT) $(PREFIX_OPT) -$(info -----BUILD INFO----) -$(info SRCS $(SRCS)) -$(info OBJS $(OBJS)) +compile-inplace: gen + python3 setup.py build_ext $(DEBUG_OPT) $(PREFIX_OPT) --inplace -.PHONY: all gen module_dyn module_static clean +# Packaging +# ========= +# create wheel and egg package in dist/ +dist: dist-whl dist-egg -static: gen module_static +# create wheel package in dist/ +dist-whl: compile + python3 setup.py bdist_wheel -dyn: gen module_dyn +# create egg package in dist/ +dist-egg: compile + python3 setup.py bdist_egg -gen: - $(MAKE) -C gen -module_dyn: $(TARGET_MODULE_DYN) +# Installation +# ============ +# installs the package system wide +install: compile + pip3 install . -$(TARGET_MODULE_DYN) : $(OBJS) - $(CXX) $(LDFLAGS_DYN) -o $@ $^ +# installs the package into your user home +install-user: compile + pip3 install . --user -module_static: $(TARGET_MODULE_STATIC) -$(TARGET_MODULE_STATIC) : $(OBJS) $(LIBS_STATIC) - $(CXX) $(LDFLAGS_STATIC) -o $@ $^ +# 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_synth_shed/ \ + DYLD_LIBRARY_PATH=../../lib/lib_synth_shed/ \ + bash --rcfile $(VENV_DIR)/bin/activate + +# Tests if the current environment is able to load the pEp module +envtest: + python3 -c 'import synth_shed' + +# 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 gen clean - rm -f $(TARGET) - rm -f $(OBJS) + rm -rf $(BUILD_DIR) + rm -rf $(DIST_DIR) + rm -rf $(PYTHON_ARTIFACTS) + rm -rf $(VERSION_FILE) + rm -rf $(BUILD_INPLACE) + + +# Makefile based build of C++ parts only +# ====================================== +makefile-build: + $(MAKE) -C synth_shed/ + +makefile-clean: + $(MAKE) -C synth_shed/ clean diff --git a/gen/examples/ext/synth_shed/Makefile.conf b/gen/examples/ext/synth_shed/Makefile.conf index 0ec5cd1..14612ac 100644 --- a/gen/examples/ext/synth_shed/Makefile.conf +++ b/gen/examples/ext/synth_shed/Makefile.conf @@ -1,23 +1,20 @@ -# pyBind11 -PREFIX=/Users/heck/local-default +HERE:=$(dir $(lastword $(MAKEFILE_LIST))) -# YML2 -YML2_PATH=$(HOME)/src/pepbase/default/yml2 -YML2_PROC=$(YML2_PATH)/yml2proc $(YML2_OPTS) -YML2_OPTS=--encoding=utf8 +# Constants +BUILD_DIR = ./build +DIST_DIR = ./dist +BUILD_INPLACE = ./src/synth_shed/syth_shed.cpython-38-darwin.so +PYTHON_ARTIFACTS += ./.eggs +PYTHON_ARTIFACTS += ./src/syth_shed.egg-info +PYTHON_ARTIFACTS += ./.pytest_cache +VENV_DIR = ./venv -# pEpACIDgen -pEpACIDgen_ROOT=../../../../ +# Build config Defaults +PREFIX= -# C Python headers -INCLUDES+=-I/opt/local/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 +######### Overrides ######### +-include $(HERE)local.conf -# example lib -INCLUDES+=-I../../lib/lib_synth_shed - -# static lib (.a) -LIBS_STATIC+=../../lib/lib_synth_shed/libsynth_shed.a - -# dynamic lib (.so) -LIBS+=-lsynth_shed -LIBS_PATH+=-L../../lib/lib_synth_shed/ +ifneq ($(PREFIX),) + PREFIX_OPT += --prefix=$(PREFIX) +endif diff --git a/gen/examples/ext/synth_shed/gen/Makefile b/gen/examples/ext/synth_shed/gen/Makefile deleted file mode 100644 index 7fc1c43..0000000 --- a/gen/examples/ext/synth_shed/gen/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -include ../Makefile.conf - -YML2_FILE=py_module.yml2 -CC_FILE=py_module.cc - -.PHONY = yml cc - -all: yml cc - -yml: - $(pEpACIDgen_ROOT)/bin/pEp_acid_gen $(abspath config.json) - -cc : $(YML2_FILE) - $(YML2_PROC) -y $(pEpACIDgen_ROOT)/pEpACIDgen/gen_backend/gen_cc.ysl2 $(YML2_FILE) - -clean: - rm -f $(YML2_FILE) - rm -f $(CC_FILE) - diff --git a/gen/examples/ext/synth_shed/pyproject.toml b/gen/examples/ext/synth_shed/pyproject.toml new file mode 100644 index 0000000..650382a --- /dev/null +++ b/gen/examples/ext/synth_shed/pyproject.toml @@ -0,0 +1,16 @@ + +[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", +] diff --git a/gen/examples/ext/synth_shed/requirements.txt b/gen/examples/ext/synth_shed/requirements.txt new file mode 100644 index 0000000..c24a2e1 --- /dev/null +++ b/gen/examples/ext/synth_shed/requirements.txt @@ -0,0 +1 @@ +pEpACIDgen diff --git a/gen/examples/ext/synth_shed/setup.cfg b/gen/examples/ext/synth_shed/setup.cfg new file mode 100755 index 0000000..55d5eb4 --- /dev/null +++ b/gen/examples/ext/synth_shed/setup.cfg @@ -0,0 +1,42 @@ +[metadata] +name = synth_shed +url = https://pep.foundation +download_url = +ext_package = synth_shed +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 + diff --git a/gen/examples/ext/synth_shed/setup.py b/gen/examples/ext/synth_shed/setup.py new file mode 100755 index 0000000..9dff39e --- /dev/null +++ b/gen/examples/ext/synth_shed/setup.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# This file is under GNU Affero General Public License 3.0 +# see LICENSE.txt + +from setuptools import setup, Extension + +# import pybind11.setup_helpers + + +ext_modules = [ + Extension( + "synth_shed", + ["synth_shed/synth_shed.cc"], + include_dirs=['../../lib/lib_synth_shed', + '/opt/local/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8', + '/Users/heck/src/adapter/pEpPythonAdapter-new/gen/examples/ext/synth_shed/venv/lib/python3.8/site-packages/pybind11/include'], + extra_compile_args=['-std=c++11'], + libraries=['synth_shed'], + library_dirs=['../../lib/lib_synth_shed/'] + ) +] + +setup( + packages=['synth_shed'], + ext_modules=ext_modules +) diff --git a/gen/examples/ext/synth_shed/synth_shed/Makefile b/gen/examples/ext/synth_shed/synth_shed/Makefile new file mode 100644 index 0000000..f3e2717 --- /dev/null +++ b/gen/examples/ext/synth_shed/synth_shed/Makefile @@ -0,0 +1,46 @@ +include Makefile.conf + +TARGET=synth_shed.so + +TARGET_MODULE_DYN=$(TARGET) +TARGET_MODULE_STATIC=$(TARGET) + +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 module_dyn module_static clean + +all: static + +static: gen module_static + +dyn: gen module_dyn + +gen: + $(MAKE) -C gen + +module_dyn: $(TARGET_MODULE_DYN) + +$(TARGET_MODULE_DYN) : $(OBJS) + $(CXX) $(LDFLAGS_DYN) -o $@ $^ + +module_static: $(TARGET_MODULE_STATIC) + +$(TARGET_MODULE_STATIC) : $(OBJS) $(LIBS_STATIC) + $(CXX) $(LDFLAGS_STATIC) -o $@ $^ + +clean: + $(MAKE) -C gen clean + rm -f $(TARGET) + rm -f $(OBJS) diff --git a/gen/examples/ext/synth_shed/synth_shed/Makefile.conf b/gen/examples/ext/synth_shed/synth_shed/Makefile.conf new file mode 100644 index 0000000..697bb5b --- /dev/null +++ b/gen/examples/ext/synth_shed/synth_shed/Makefile.conf @@ -0,0 +1,12 @@ +# pyBind11 and python headers +INCLUDES+=$(shell pybind11-config --includes) + +# example lib +INCLUDES+=-I../../../lib/lib_synth_shed + +# static lib (.a) +LIBS_STATIC+=../../../lib/lib_synth_shed/libsynth_shed.a + +# dynamic lib (.so) +LIBS+=-lsynth_shed +LIBS_PATH+=-L../../../lib/lib_synth_shed/ diff --git a/gen/examples/ext/synth_shed/synth_shed/gen/Makefile b/gen/examples/ext/synth_shed/synth_shed/gen/Makefile new file mode 100644 index 0000000..af62435 --- /dev/null +++ b/gen/examples/ext/synth_shed/synth_shed/gen/Makefile @@ -0,0 +1,25 @@ +include ../Makefile.conf + +YML2_FILE=py_module.yml2 +YSL2_FILE=$(shell pEp_acid_gen-config) +PYBIND11_FILE=py_module.pybind11 + +$(info -----SYNTH_SHED GEN----) +$(info YML2_FILE $(YML2_FILE)) +$(info YSL2_FILE $(YSL2_FILE)) +$(info CC_FILE $(PYBIND11_FILE)) + +.PHONY = yml pybind11 + +all: $(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) + diff --git a/gen/examples/ext/synth_shed/gen/config.json b/gen/examples/ext/synth_shed/synth_shed/gen/config.json similarity index 80% rename from gen/examples/ext/synth_shed/gen/config.json rename to gen/examples/ext/synth_shed/synth_shed/gen/config.json index 022b5d1..155ae77 100644 --- a/gen/examples/ext/synth_shed/gen/config.json +++ b/gen/examples/ext/synth_shed/synth_shed/gen/config.json @@ -1,6 +1,6 @@ { "module_name": "synth_shed", - "header_filename": "../../../../examples/lib/lib_synth_shed/synth_shed.h", + "header_filename": "../../../../../examples/lib/lib_synth_shed/synth_shed.h", "libclang_path": "/opt/local/libexec/llvm-9.0/lib/libclang.dylib", "variables": [ ], diff --git a/gen/examples/ext/synth_shed/synth_shed.cc b/gen/examples/ext/synth_shed/synth_shed/synth_shed.cc similarity index 83% rename from gen/examples/ext/synth_shed/synth_shed.cc rename to gen/examples/ext/synth_shed/synth_shed/synth_shed.cc index 640f72c..bf4dede 100644 --- a/gen/examples/ext/synth_shed/synth_shed.cc +++ b/gen/examples/ext/synth_shed/synth_shed/synth_shed.cc @@ -7,7 +7,7 @@ using namespace std; PYBIND11_MODULE(synth_shed, m) { - #include "gen/py_module.cc" + #include "gen/py_module.pybind11" } diff --git a/gen/examples/ext/synth_shed/tests/test_synth_shed.py b/gen/examples/ext/synth_shed/tests/test_synth_shed.py new file mode 100644 index 0000000..d3be8f2 --- /dev/null +++ b/gen/examples/ext/synth_shed/tests/test_synth_shed.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# This file is under GNU Affero General Public License 3.0 +# see LICENSE.txt + +import synth_shed + +def test_synth_shed(): + synth_shed diff --git a/gen/examples/lib/lib_synth_shed/synth_shed.c b/gen/examples/lib/lib_synth_shed/synth_shed.c index 4f8f8a6..766fe74 100644 --- a/gen/examples/lib/lib_synth_shed/synth_shed.c +++ b/gen/examples/lib/lib_synth_shed/synth_shed.c @@ -12,7 +12,7 @@ synth_t* synth_create(const char* name) { synth_t* new = (synth_t*) malloc(sizeof(synth_t)); assert(new); if (new != NULL) { - new->model_name = name; + new->model_name = "TESTNAME"; new->osc_count = 1; new->technolgy = ANALOG; new->filter.technology = ANALOG;