mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-26 15:23:54 +01:00
py-defs.mk, py-mod.mk, python-tools.sh: Improve python module handling
- Fix superflous dots in module names - Generate PYTHONPATH in projects.py - Add support for __init__.py.tmpl Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
3ec49304a1
commit
55f9b50562
3 changed files with 35 additions and 19 deletions
|
|
@ -8,34 +8,41 @@ endif
|
||||||
|
|
||||||
PY_PREREQ_BUILD ?= $(shell $(proj_query_cmd) pkg-requires --subsections jw -d ' ' -p --no-version build $(PROJECT))
|
PY_PREREQ_BUILD ?= $(shell $(proj_query_cmd) pkg-requires --subsections jw -d ' ' -p --no-version build $(PROJECT))
|
||||||
PY_PREREQ_BUILD_DIRS ?= $(shell $(proj_query_cmd) proj-dir $(PY_PREREQ_BUILD))
|
PY_PREREQ_BUILD_DIRS ?= $(shell $(proj_query_cmd) proj-dir $(PY_PREREQ_BUILD))
|
||||||
PY_PROJ_MODULES_DIRS ?= $(wildcard $(foreach subdir,/tools/python /src/python,$(addsuffix $(subdir),$(PY_PREREQ_BUILD_DIRS))))
|
PY_PROJ_MODULE_DIRS ?= $(wildcard $(foreach subdir,/tools/python /src/python,$(addsuffix $(subdir),$(TOPDIR) $(PY_PREREQ_BUILD_DIRS))))
|
||||||
PY_MODULES_DIRS ?= $(PY_PROJ_MODULES_DIRS)
|
PY_MODULE_DIRS ?= $(PY_PROJ_MODULE_DIRS)
|
||||||
PY_PROJ_MODULES += $(dir $(wildcard $(PY_MODULES_DIRS)/*/__init__.py))
|
PY_PROJ_MODULES += $(dir $(wildcard $(PY_MODULE_DIRS)/*/__init__.py))
|
||||||
PY_MODULES ?= $(PY_PROJ_MODULES)
|
PY_MODULES ?= $(PY_PROJ_MODULES)
|
||||||
PY_INSTALL_MOD ?= $(shell pwd | sed 's%.*/python/%%; s%/.*%%')
|
|
||||||
PY_INSTALL_SUBMOD ?= $(shell pwd | sed "s%.*/$(PY_INSTALL_MOD)\(/\|$$\)%%")
|
|
||||||
PY_MOD ?= $(patsubst /,.,$(PY_INSTALL_MOD).$(PY_INSTALL_SUBMOD))
|
|
||||||
PY_SRC_PY = $(sort $(wildcard *.py) __init__.py)
|
PY_SRC_PY = $(sort $(wildcard *.py) __init__.py)
|
||||||
PY_PYC = $(patsubst %.py,%.pyc,$(PY_SRC_PY))
|
PY_PYC = $(patsubst %.py,%.pyc,$(PY_SRC_PY))
|
||||||
|
|
||||||
ifneq ($(PY_INSTALL_SUBMOD),)
|
PY_INSTALL_PKG_MOD ?= $(shell pwd | sed 's%.*/python/%%; s%/.*%%')
|
||||||
PY_INSTALL_DIR = $(ENV_PREFIX)$(PY_SITE_PACKAGES_PATH)/$(PY_INSTALL_MOD)/$(PY_INSTALL_SUBMOD)
|
PY_INSTALL_SUB_MOD ?= $(shell pwd | sed "s%.*/$(PY_INSTALL_PKG_MOD)\(/\|$$\)%%")
|
||||||
|
ifneq ($(PY_INSTALL_SUB_MOD),)
|
||||||
|
PY_INSTALL_MOD ?= $(PY_INSTALL_PKG_MOD)/$(PY_INSTALL_SUB_MOD)
|
||||||
else
|
else
|
||||||
PY_INSTALL_DIR = $(ENV_PREFIX)$(PY_SITE_PACKAGES_PATH)/$(PY_INSTALL_MOD)
|
PY_INSTALL_MOD ?= $(PY_INSTALL_PKG_MOD)
|
||||||
endif
|
endif
|
||||||
|
PY_MOD ?= $(subst /,.,$(PY_INSTALL_MOD))
|
||||||
|
PY_INSTALL_DIR = $(ENV_PREFIX)$(PY_SITE_PACKAGES_PATH)/$(patsubst .,/,$(PY_INSTALL_MOD))
|
||||||
PY_INSTALLED_REG = $(addprefix $(PY_INSTALL_DIR)/,$(PY_SRC_PY) $(PY_PYC))
|
PY_INSTALLED_REG = $(addprefix $(PY_INSTALL_DIR)/,$(PY_SRC_PY) $(PY_PYC))
|
||||||
|
|
||||||
PYTHONPATH = $(ENV_PYTHONPATH)$(foreach d,$(PY_MODULES_DIRS),:$(d))
|
empty :=
|
||||||
|
space := $(empty) $(empty)
|
||||||
|
PYTHONPATH ?= $(call proj_query, pythonpath $(PROJECT))
|
||||||
|
#PYTHONPATH = $(subst $(space),,$(ENV_PYTHONPATH)$(foreach d,$(PY_MODULE_DIRS),:$(d)))
|
||||||
export PYTHONPATH
|
export PYTHONPATH
|
||||||
|
|
||||||
all:
|
all:
|
||||||
echo-py:
|
echo-py:
|
||||||
@echo PROJECT = $(PROJECT)
|
@echo PROJECT = $(PROJECT)
|
||||||
@echo PY_PROJ_MODULES_DIRS = $(PY_PROJ_MODULES_DIRS)
|
@echo PY_PROJ_MODULE_DIRS = $(PY_PROJ_MODULE_DIRS)
|
||||||
@echo PY_MODULES_DIRS = $(PY_MODULES_DIRS)
|
@echo PY_MODULE_DIRS = $(PY_MODULE_DIRS)
|
||||||
@echo PY_SITE_PACKAGES_PATH = $(PY_SITE_PACKAGES_PATH)
|
@echo PY_SITE_PACKAGES_PATH = $(PY_SITE_PACKAGES_PATH)
|
||||||
@echo PY_MODULES = $(PY_MODULES)
|
@echo PY_MODULES = $(PY_MODULES)
|
||||||
@echo PYTHONPATH = $(PYTHONPATH)
|
@echo PYTHONPATH = $(PYTHONPATH)
|
||||||
@echo PY_INSTALL_MOD = $(PY_INSTALL_MOD)
|
@echo PY_INSTALL_MOD = $(PY_INSTALL_MOD)
|
||||||
@echo PY_INSTALL_SUBMOD = $(PY_INSTALL_SUBMOD)
|
@echo PY_INSTALL_SUB_MOD = $(PY_INSTALL_SUB_MOD)
|
||||||
|
|
||||||
|
libpath: py-libpath
|
||||||
|
py-libpath:
|
||||||
|
@echo export PYTHONPATH=$(PYTHONPATH)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ include $(MODDIR)/make/defs.mk
|
||||||
include $(MODDIR)/make/py-defs.mk
|
include $(MODDIR)/make/py-defs.mk
|
||||||
include $(MODDIR)/make/dirs.mk
|
include $(MODDIR)/make/dirs.mk
|
||||||
|
|
||||||
|
PY_INIT_TMPL = $(wildcard __init__.py.tmpl)
|
||||||
|
PY_SED_EXTRACT_EXPORT ?= /class ..*\# *export/ !d; s/class *//; s/[(:].*//
|
||||||
|
|
||||||
all: $(PY_PYC)
|
all: $(PY_PYC)
|
||||||
install: install-dirs.done install-reg.done
|
install: install-dirs.done install-reg.done
|
||||||
clean: py.clean
|
clean: py.clean
|
||||||
|
|
@ -27,6 +30,7 @@ $(PY_INSTALL_DIR)/%.py: %.py
|
||||||
$(PY_INSTALL_DIR)/%.pyc: %.pyc
|
$(PY_INSTALL_DIR)/%.pyc: %.pyc
|
||||||
$(INSTALL) -m $(PYMODMODE) -o $(PYMODOWNER) -g $(PYMODGROUP) $< $@
|
$(INSTALL) -m $(PYMODMODE) -o $(PYMODOWNER) -g $(PYMODGROUP) $< $@
|
||||||
|
|
||||||
__init__.py:
|
__init__.py: $(PY_INIT_TMPL) $(filter-out __init__.py,$(PY_SRC_PY))
|
||||||
/bin/bash +H $(MOD_SCRIPT_DIR)/python-tools.sh create-init -m $(PY_MOD) -e "$(PY_SED_EXTRACT_EXPORT)" *.py | tee $@.tmp
|
if [ "$(PY_INIT_TMPL)" ]; then cat "$(PY_INIT_TMPL)" > $@.tmp; else > $@.tmp; fi
|
||||||
|
/bin/bash +H $(MOD_SCRIPT_DIR)/python-tools.sh create-init -m $(PY_MOD) -e "$(PY_SED_EXTRACT_EXPORT)" *.py | tee -a $@.tmp
|
||||||
mv $@.tmp $@
|
mv $@.tmp $@
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,21 @@ usage()
|
||||||
|
|
||||||
cmd_create_init()
|
cmd_create_init()
|
||||||
{
|
{
|
||||||
local f files base extracted
|
local f files base extracted module_path
|
||||||
files="$*"
|
files="$*"
|
||||||
for f in $files; do
|
for f in $files; do
|
||||||
base=${f##*/}
|
base=${f##*/}
|
||||||
base=${base%.py}
|
base=${base%.py}
|
||||||
|
if [ "$module" ]; then
|
||||||
|
module_path=$module.$base
|
||||||
|
else
|
||||||
|
module_path=$base
|
||||||
|
fi
|
||||||
if [ "$sed_extract_command" ]; then
|
if [ "$sed_extract_command" ]; then
|
||||||
#echo running $sed_extract_command on $f
|
#echo running $sed_extract_command on $f
|
||||||
extracted=`sed "$sed_extract_command" $f`
|
extracted=`sed "$sed_extract_command" $f`
|
||||||
if [ "$extracted" ]; then
|
if [ "$extracted" ]; then
|
||||||
echo "from $module.$base import $extracted"
|
echo "from $module_path import $extracted"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
@ -35,7 +40,7 @@ eval set -- `getopt -o 'he:m:' "$@"`
|
||||||
while [ "$1" != -- ]; do
|
while [ "$1" != -- ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-e)
|
-e)
|
||||||
sed_extract_command=$2
|
sed_extract_command="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-m)
|
-m)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue