diff --git a/.devcontainer/activate-venv.sh b/.devcontainer/activate-venv.sh new file mode 100755 index 00000000..1cb498d5 --- /dev/null +++ b/.devcontainer/activate-venv.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Auto-activate Python virtual environment for devcontainer +# This script is idempotent and safe to source multiple times +VENV_PATH="/workspaces/python-mercuryapi/.venv" + +# Only activate if venv exists and not already activated +if [ -d "$VENV_PATH" ] && [ -f "$VENV_PATH/bin/activate" ]; then + if [ -z "$VIRTUAL_ENV" ] || [ "$VIRTUAL_ENV" != "$VENV_PATH" ]; then + source "$VENV_PATH/bin/activate" + fi +fi + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..ec0a0a52 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,10 @@ +{ + "name": "Python Mercury API", + "image": "mcr.microsoft.com/devcontainers/python:3.12", + "postCreateCommand": "chmod +x .devcontainer/activate-venv.sh && python3 -m venv /workspaces/python-mercuryapi/.venv && /workspaces/python-mercuryapi/.venv/bin/pip install --upgrade pip && if [ -f requirements.txt ]; then /workspaces/python-mercuryapi/.venv/bin/pip install -r requirements.txt; fi && echo 'source /workspaces/python-mercuryapi/.devcontainer/activate-venv.sh' >> ~/.bashrc && echo 'source /workspaces/python-mercuryapi/.devcontainer/activate-venv.sh' >> ~/.profile", + "remoteEnv": { + "VIRTUAL_ENV": "/workspaces/python-mercuryapi/.venv", + "PATH": "/workspaces/python-mercuryapi/.venv/bin:${containerEnv:PATH}" + }, + "remoteUser": "vscode" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index ba80e17f..71be6373 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ .vs build dist +mercuryapi-*/ +!_vendor/ *.egg-info -mercuryapi-* Examples/ Tests/ +.venv/ \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index eb0b21cc..3369d75a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,3 +4,4 @@ include mercuryapi_osx.patch include README.md include long_description.txt include LICENSE +recursive-include _vendor * diff --git a/Makefile b/Makefile index 01cde64e..f78283bd 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -APIZIP ?= mercuryapi-AHAB-1.35.2.72-1.zip -APIVER ?= 1.35.2.72 +APIZIP ?= _vendor/mercuryapi-$(APIVER).zip +APIVER ?= 1.37.4.8 PYTHON ?= $(shell { command -v python3 || command -v python; } 2>/dev/null) .PHONY: all mercuryapi install @@ -11,7 +11,7 @@ install: mercuryapi $(PYTHON) setup.py install mercuryapi: mercuryapi-$(APIVER)/.done - make -C mercuryapi-$(APIVER)/c/src/api + make -C mercuryapi-$(APIVER)/c/src/api SKIP_SAMPLES=1 mkdir -p build/mercuryapi/include find mercuryapi-*/c/src/api -type f -name '*.h' ! -name '*_imp.h' ! -path '*ltkc_win32*' -exec cp {} build/mercuryapi/include/ \; @@ -20,9 +20,6 @@ mercuryapi: mercuryapi-$(APIVER)/.done find mercuryapi-*/c/src/api -type f \( -name '*.a' -or -name '*.so.1' \) -exec cp {} build/mercuryapi/lib/ \; mercuryapi-$(APIVER)/.done: $(APIZIP) - unzip $(APIZIP) + unzip -o $(APIZIP) -x "*/cs/*" "*/java/*" patch -p0 -d mercuryapi-$(APIVER) < mercuryapi.patch touch mercuryapi-$(APIVER)/.done - -$(APIZIP): - curl https://www.jadaktech.com/wp-content/uploads/2022/08/$(APIZIP) -o $(APIZIP) diff --git a/_vendor/mercuryapi-1.37.4.8.zip b/_vendor/mercuryapi-1.37.4.8.zip new file mode 100644 index 00000000..d0ce6c4b Binary files /dev/null and b/_vendor/mercuryapi-1.37.4.8.zip differ diff --git a/mercury.c b/mercury.c index 77d67eb5..77cd7390 100644 --- a/mercury.c +++ b/mercury.c @@ -439,7 +439,7 @@ parse_gen2filter(TMR_TagFilter *tag_filter, PyObject *arg, TMR_GEN2_Select_actio { if (obj == Py_None) tag_filter->u.gen2Select.action = defaction; - else if ((tag_filter->u.gen2Select.action = str2action(object2str(obj))) == -1) + else if ((tag_filter->u.gen2Select.action = str2action(object2str(obj))) == (TMR_GEN2_Select_action)-1) return 0; } else @@ -1004,7 +1004,7 @@ Reader_write_tag_mem(Reader *self, PyObject *args, PyObject *kwds) if(!parse_multifilter(&tag_filter, epc_target)) return NULL; - ret = TMR_writeTagMemBytes(&self->reader, tag_filter, bank, address, PyByteArray_Size(data), (uint8_t *)PyByteArray_AsString(data)); + ret = TMR_writeTagMemBytes(&self->reader, tag_filter, bank, address, PyByteArray_Size(data), (uint8_t *)PyByteArray_AsString(data), NULL); reset_filter(&tag_filter); if (ret == TMR_ERROR_NO_TAGS_FOUND) Py_RETURN_FALSE; @@ -2360,7 +2360,9 @@ initmercury(void) { #endif PyObject* m; +#if PY_VERSION_HEX < 0x03070000 PyEval_InitThreads(); +#endif if (PyType_Ready(&ReaderType) < 0 || PyType_Ready(&TagDataType) < 0 diff --git a/mercuryapi.patch b/mercuryapi.patch index 1f5ce82b..6505e2cb 100644 --- a/mercuryapi.patch +++ b/mercuryapi.patch @@ -2,10 +2,88 @@ +++ c/src/api/Makefile 2016-07-30 02:44:13.854834003 -0700 @@ -68,7 +68,7 @@ HEADERS += tmr_utils.h - + DBG ?= -g -CWARN = -Werror -Wall +CWARN = -Wall # Add -Wextra to chase down warnings that might appear on build server, but not dev machines #CWARN += -Wextra ifneq ($(TMR_ENABLE_SERIAL_READER_ONLY), 1) +diff -auNr mercuryapi-1.31.2.orig/c/src/api/Makefile mercuryapi-1.31.2/c/src/api/Makefile +--- c/src/api/Makefile 2018-10-02 18:53:16.000000000 +1000 ++++ c/src/api/Makefile 2019-07-23 23:24:44.000000000 +1000 +@@ -138,7 +138,7 @@ + endif + + ifneq ($(SERIAL_READER_ONLY), 1) +-all: $(LTKC_LIB) $(STATIC_LIB) $(SHARED_LIB) $(PROGS) ++all: $(LTKC_LIB) $(STATIC_LIB) $(PROGS) + + $(OBJS): $(LTKC_LIB) $(LTKC_TM_IB) + +@@ -153,7 +153,7 @@ + find lib/LTK/LTKC/Library -name '*.h' -exec cp -p {} ltkc_win32/inc/ \; + find lib/LTK/LTKC/Library -name '*.c' -exec cp -p {} ltkc_win32/src/ \; + else +-all: $(STATIC_LIB) $(SHARED_LIB) $(PROGS) ++all: $(STATIC_LIB) $(PROGS) + + $(OBJS): + endif +diff -auNr mercuryapi-1.31.2.orig/c/src/api/lib/install_LTKC.sh mercuryapi-1.31.2/c/src/api/lib/install_LTKC.sh +--- c/src/api/lib/install_LTKC.sh 2018-11-21 19:39:14.000000000 +1000 ++++ c/src/api/lib/install_LTKC.sh 2019-07-23 23:23:53.000000000 +1000 +@@ -45,6 +45,7 @@ + patch -p0 -d ${INSTALL_DIR} < ${PATCH_DIR}/llrp_ltk_shared_libs.patch + #Apply patch that provides specific error messages related to read function. This doesnt cover any additional functionality. + #patch -p0 -d ${INSTALL_DIR} < ${PATCH_DIR}/llrp_ltkc_read_specific_errors.patch ++patch -p0 -l -d ${INSTALL_DIR} < ${PATCH_DIR}/llrp_ltk_osx.patch + + #This is to avoid multiple includes of out_ltkc_ header files. + echo '#ifndef __OUT_LTKC_WRAPPER_H' > ${INSTALL_DIR}/LTK/LTKC/Library/out_ltkc_wrapper.h +diff -auNr mercuryapi-1.31.2.orig/c/src/api/lib/llrp_ltk_osx.patch mercuryapi-1.31.2/c/src/api/lib/llrp_ltk_osx.patch +--- c/src/api/lib/llrp_ltk_osx.patch 1970-01-01 10:00:00.000000000 +1000 ++++ c/src/api/lib/llrp_ltk_osx.patch 2019-07-23 23:22:53.000000000 +1000 +@@ -0,0 +1,42 @@ ++diff -auNr LTK.orig/LTKC/Library/LLRP.org/Makefile LTK/LTKC/Library/LLRP.org/Makefile ++--- LTK.orig/LTKC/Library/LLRP.org/Makefile 2019-07-23 23:17:20.000000000 +1000 +++++ LTK/LTKC/Library/LLRP.org/Makefile 2019-07-23 23:20:17.000000000 +1000 ++@@ -49,7 +49,7 @@ ++ TM_LTKC_SONAME = $(TM_LTKC_LIB:.a=.so.1) ++ TM_LTKC_SHARED_LIB = $(TM_LTKC_SONAME) ++ ++-all: $(TM_LTKC_LIB) $(TM_LTKC_SHARED_LIB) +++all: $(TM_LTKC_LIB) ++ ++ $(TM_LTKC_LIB) : $(TM_LTKC_OBJS) ++ $(AR) crv $(TM_LTKC_LIB) $(TM_LTKC_OBJS) ++diff -auNr LTK.orig/LTKC/Library/Makefile LTK/LTKC/Library/Makefile ++--- LTK.orig/LTKC/Library/Makefile 2019-07-23 23:17:20.000000000 +1000 +++++ LTK/LTKC/Library/Makefile 2019-07-23 23:19:45.000000000 +1000 ++@@ -60,7 +60,7 @@ ++ LTKC_SONAME = $(LTKC_LIB:.a=.so.1) ++ LTKC_SHARED_LIB = libltkc.so.1 ++ ++-all: $(LTKC_LIB) $(LTKC_SHARED_LIB) +++all: $(LTKC_LIB) ++ cd LLRP.org; make all ++ ++ everything: ++diff -auNr LTK.orig/LTKC/Library/ltkc_platform.h LTK/LTKC/Library/ltkc_platform.h ++--- LTK.orig/LTKC/Library/ltkc_platform.h 2011-03-04 16:56:16.000000000 +1000 +++++ LTK/LTKC/Library/ltkc_platform.h 2019-07-23 23:18:30.000000000 +1000 ++@@ -39,8 +39,6 @@ ++ * good to go. ++ */ ++ ++-#ifdef _STDINT_H ++- ++ typedef uint8_t llrp_u8_t; ++ typedef int8_t llrp_s8_t; ++ typedef uint16_t llrp_u16_t; ++@@ -54,5 +52,3 @@ ++ typedef uint8_t llrp_utf8_t; ++ typedef int llrp_bool_t; ++ typedef uint8_t llrp_byte_t; ++- ++-#endif /* _STDINT_H */ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..e3f07421 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +# Build dependencies for python-mercuryapi +setuptools>=65.0.0 +wheel>=0.38.0 +