Index | Thread | Search

From:
Stuart Henderson <stu@spacehopper.org>
Subject:
Re: archivers/py-zstandard: improve tests
To:
OpenBSD ports <ports@openbsd.org>, Klemens Nanni <kn@openbsd.org>
Date:
Mon, 23 Sep 2024 17:08:46 +0100

Download raw body.

Thread
On 2024/09/23 17:43, Kirill A. Korinsky wrote:
> On Tue, 03 Sep 2024 18:31:56 +0200,
> Kirill A. Korinsky <kirill@korins.ky> wrote:
> > 
> > I had dig into archivers/py-zstandard (a couple moths ago) and if I recall
> > right the cause of issue was inside zstandard/__init__.py it uses:
> > 
> >   from .backend_c import *
> > 
> > which is a root cause for this issue because . means check the current
> > package, and don't use PYTHONPATH if I recall right.
> > 
> 
> Here a cleaner approach which can be reused on different places. I have no
> idea about good namig for variable, any suggestion?

Ah nice, that generally seems a better approach.

Perhaps MODPY_PYTEST_LINK_SO (or MODPY_TEST_LINK_SO if it's useful for
more than just things using pytest)?

> Index: archivers/py-zstandard/Makefile
> ===================================================================
> RCS file: /cvs/ports/archivers/py-zstandard/Makefile,v
> retrieving revision 1.2
> diff -u -p -r1.2 Makefile
> --- archivers/py-zstandard/Makefile	28 Aug 2024 11:49:24 -0000	1.2
> +++ archivers/py-zstandard/Makefile	23 Sep 2024 15:41:21 -0000
> @@ -17,11 +17,6 @@ BUILD_DEPENDS =		devel/py-cffi${MODPY_FL
>  FLAVORS =		python3
>  FLAVOR =		python3
>  
> -MODPY_PYTEST_ARGS =	tests/
> -MODPY_TEST_DIR =	${WRKDIR}
> -
> -pre-test:
> -	@rm -rf ${WRKDIR}/tests
> -	@cp -r ${WRKSRC}/tests ${WRKDIR}/
> +MODPY_RELEATIVE_IMPORT_CFFI =	Yes
>  
>  .include <bsd.port.mk>
> Index: lang/python/python.port.mk
> ===================================================================
> RCS file: /cvs/ports/lang/python/python.port.mk,v
> retrieving revision 1.192
> diff -u -p -r1.192 python.port.mk
> --- lang/python/python.port.mk	25 Jul 2024 15:42:03 -0000	1.192
> +++ lang/python/python.port.mk	23 Sep 2024 15:41:21 -0000
> @@ -124,6 +124,8 @@ RUN_DEPENDS +=		${MODPY_RUN_DEPENDS}
>  TEST_DEPENDS +=		${MODPY_TEST_DEPENDS}
>  .endif
>  
> +MODPY_RELEATIVE_IMPORT_CFFI ?=	No
> +
>  _MODPY_PRE_BUILD_STEPS = :
>  
>  .if ${MODPY_PYBUILD:L} == "no"
> @@ -356,6 +358,12 @@ do-install:
>  .  if !target(do-test) && \
>        (${MODPY_SETUPUTILS:L} == "yes" || ${MODPY_PYTEST:L} == "yes")
>  do-test:
> +.    if ${MODPY_RELEATIVE_IMPORT_CFFI:L} == "yes"
> +	cd ${WRKSRC}/build/lib.openbsd-${OSREV}-${ARCH}-cpython-${MODPY_MAJORMINOR} && \

This should prepend to MODPY_TEST_TARGET rather than go into do-test
directly. (Some ports have their own do-test target which refers to
${MODPY_TEST_TARGET} or similar, so should work there too).

> +	find . \
> +		-name '*.so' -type f \
> +	 	-exec ln -sf ${WRKSRC}/build/lib.openbsd-${OSREV}-${ARCH}-cpython-${MODPY_MAJORMINOR}/{} ${WRKSRC}/{} \;
> +.    endif
>  	@${MODPY_TEST_TARGET}

IIRC the build/lib.openbsd-${OSREV}-... format is just for setuptools,
so it may be better to define a new variable containing the directory
name and set it as appropriate for each MODPY_PYBUILD backend.
(They don't need to be done all at once, just error out if someone
tries to use the new option and the dir isn't set - I can help with
looking for other ports which could use this later, but too busy right
now).

>  .  endif
>  
> 
> 
> -- 
> wbr, Kirill
>