Hi,

I reworked on the diff to update python.port.mk to permit to have both Python 
2.x and 3.x working on OpenBSD.

How it works:
1) Python2 port
- all ports existing don't need to change, they still build with Python 2

2) Python2 and Python3 port
- if you know that a port (and its dependencies...) work with Python 3 && 
Python 2, you just need to add:
FLAVORS ?= python3
Be carefull to add ${MODPY_FLAVOR} to your dependencies (see examples at the 
end).
Next, to build your port you will need to precise the correct flavor: python3.

In this case, you must be very carreful with the conflict of the PLIST. If your 
port is a library, there is often no problems, but you will have problem with 
binaries/doc/examples/wub/...
So you will have to "play" with post-install, in moving files which are 
conflicting by suffixing it (see examples at the end).
FYI the port built with python3 will replace the prefix py- by py3-.

3) Python3 port
- if you know that a port (and its dependencies) work with Python 3 only, you 
just need to add:
MODPY_VERSION = ${MODPY_DEFAULT_VERSION3} and it will automatically build this 
port with Python 3.
FYI the port built with python3 follow the same logic that in python2, so if 
the port PKGNAME begins with py- it will automatically be replaced by py3-.


More details about modifications needed in the ports tree:
- remove the devel/py3-distribute, not used and useless to have py3 in the dir 
name (maybe a quirks thing to permit distribute -> py3-distribute? If not used 
actually, are modifications in quirks needed?)
- some people don't want to replace py-setuptools by py-distribute, so keep 
py-setuptools (Python 2 only).
- add the port devel/py-distribute, only used with Python3 ports (MODPY_VERSION 
= ${MODPY_DEFAULT_VERSION3}, will have the py3-distribute FULLPKGNAME.
- remove the MODPY_DISTRIBUTE, useless. Keep the MODPY_SETUPTOOLS only, easier 
to maintain, even if we used distribute or setuptools after, it's not the 
problem of the porters.


So, if your ports use:
1) Python 2 only
- nothing to change

2) Python 2 and Python 3:
- add FLAVORS ?= python3
- add to your *_DEPENDS : ${MODPY_FLAVOR}, without comma (example: 
BUILD_DEPENDS: devel/py-distribute${MODPY_FLAVOR}).
- make sure your PLIST will not be in conflict by adding special tasks in 
post-install. Example:
post-install:
.if defined(MODPY_DOC_PREFIX)
mv ${WRKINST}/${LOCALBASE}/share/doc/py-foo/ 
${WRKINST}/${LOCALBASE}/share/doc/py${MODPY_DOC_PREFIX}-foo/
.endif

If you use the default FLAVOR (Python 2), MODPY_BIN_SUFFIX is "", 
MODPY_DOC_PREFIX is "" so there is no modification for people who use the 
default.
If you use the FLAVOR Python 3, MODPY_BIN_SUFFIX = -3, MODPY_DOC_PREFIX = 3. 
Idea is to add a suffix to binary to be easier to find the command with 
auto-completion.
Add ${MODPY_BIN_SUFFIX} and ${MODPY_DOC_PREFIX} to your PLIST.

3) Python 3:
- add MODPY_VERSION = ${MODPY_DEFAULT_VERSION3}

Please test and give me your feedback.

Cheers,
-- 
Remi
Index: python.port.mk
===================================================================
RCS file: /cvs/ports/lang/python/python.port.mk,v
retrieving revision 1.48
diff -u -p -r1.48 python.port.mk
--- python.port.mk      29 Nov 2011 17:29:37 -0000      1.48
+++ python.port.mk      10 Dec 2011 06:39:23 -0000
@@ -7,25 +7,59 @@ SHARED_ONLY=          Yes
 
 CATEGORIES+=           lang/python
 
-MODPY_VERSION?=                2.7
+# define the default versions
+MODPY_DEFAULT_VERSION2 = 2.7
+MODPY_DEFAULT_VERSION3 = 3.2
 
-.if ${MODPY_VERSION} == "2.4" || ${MODPY_VERSION} == "2.5" || ${MODPY_VERSION} 
== "2.7" || ${MODPY_VERSION} == "3.2"
+.if !defined(MODPY_VERSION)
 
-.  if ${MODPY_VERSION} < 2.6
-MODPY_JSON =           devel/py-simplejson
-.  else
-MODPY_JSON =
-.  endif
+FLAVOR?=
 
-.  if ${MODPY_VERSION} < 3.2
-MODPY_WANTLIB =        python${MODPY_VERSION}
-MODPY_INCDIR = ${LOCALBASE}/include/python${MODPY_VERSION}
+.  if ${FLAVOR:L:Mpython3}
+# define default version 3
+MODPY_VERSION?=                ${MODPY_DEFAULT_VERSION3}
 .  else
-MODPY_WANTLIB = python${MODPY_VERSION}m
-MODPY_INCDIR = ${LOCALBASE}/include/python${MODPY_VERSION}m
+# without flavor, assume we use the default version 2
+MODPY_VERSION?=                ${MODPY_DEFAULT_VERSION2}
 .  endif
+
+# verify if MODPY_VERSION forced is correct
 .else
+.  if ${MODPY_VERSION} != "2.4" && \
+      ${MODPY_VERSION} != "2.5" && \
+      ${MODPY_VERSION} != "2.7" && \
+      ${MODPY_VERSION} != "3.2"
 ERRORS += "Fatal: unknown or unsupported MODPY_VERSION: ${MODPY_VERSION}"
+.  endif
+.endif
+
+_MODPY_MAJOR_VERSION = ${MODPY_VERSION:C/\.[1-9]*//g}
+
+.if ${_MODPY_MAJOR_VERSION} == 2
+MODPY_LIB_SUFFIX =
+MODPY_FLAVOR =
+MODPY_BIN_SUFFIX =
+MODPY_DOC_PREFIX =
+
+.elif ${_MODPY_MAJOR_VERSION} == 3
+MODPY_LIB_SUFFIX =     m
+# replace py- prefix by py3-
+FULLPKGNAME =  ${PKGNAME:S/^py-/py3-/}
+MODPY_FLAVOR = ,python3
+# use MODPY_SUFFIX for binaries to avoid conflict
+MODPY_BIN_SUFFIX =     -3
+# use MODPY_SUFFIX for directories share/doc/examples to avoid conflict
+MODPY_DOC_PREFIX =     3 
+.  else
+ERRORS += "Fatal: unknown or unsupported _MODPY_MAJOR_VERSION: 
${_MODPY_MAJOR_VERSION}"
+.endif
+
+MODPY_WANTLIB = python${MODPY_VERSION}${MODPY_LIB_SUFFIX}
+
+.if ${MODPY_VERSION} < 2.6
+MODPY_JSON =           devel/py-simplejson
+.else
+MODPY_JSON =
 .endif
 
 MODPY_RUN_DEPENDS=     lang/python/${MODPY_VERSION}
@@ -43,15 +77,15 @@ RUN_DEPENDS+=               ${MODPY_RUN_DEPENDS}
 .endif
 
 MODPY_PRE_BUILD_STEPS = @:
-.if (defined(MODPY_SETUPTOOLS) && ${MODPY_SETUPTOOLS:U} == YES) || \
-    (defined(MODPY_DISTRIBUTE) && ${MODPY_DISTRIBUTE:U} == YES)
+.if (defined(MODPY_SETUPTOOLS) && ${MODPY_SETUPTOOLS:U} == YES)
 # The setuptools module provides a package locator (site.py) that is
 # required at runtime for the pkg_resources stuff to work
-.if ${MODPY_SETUPTOOLS:U} == YES
+.  if ${_MODPY_MAJOR_VERSION} == 2
 MODPY_SETUPUTILS_DEPEND?=devel/py-setuptools
-.else
-MODPY_SETUPUTILS_DEPEND ?= devel/py3-distribute
-.endif
+.  elif ${_MODPY_MAJOR_VERSION} == 3
+MODPY_SETUPUTILS_DEPEND?=devel/py-distribute
+.  endif
+
 MODPY_RUN_DEPENDS+=    ${MODPY_SETUPUTILS_DEPEND}
 BUILD_DEPENDS+=                ${MODPY_SETUPUTILS_DEPEND}
 MODPY_SETUPUTILS =     Yes
@@ -67,8 +101,7 @@ MODPY_PRE_BUILD_STEPS +=     \
        ;mkdir -p ${_MODPY_SETUPUTILS_FAKE_DIR} \
        ;exec >${_MODPY_SETUPUTILS_FAKE_DIR}/__init__.py \
        ;echo 'def setup(*args, **kwargs):' \
-       ;echo '    msg = "OpenBSD ports: MODPY_SETUPTOOLS = Yes or\\n" \' \
-       ;echo '          "\\t\\t\\t  MODPY_DISTRIBUTE = Yes required"' \
+       ;echo '    msg = "OpenBSD ports: MODPY_SETUPTOOLS = Yes is required"' \
        ;echo '    raise Exception(msg)' \
        ;echo 'Extension = Feature = find_packages = setup'
 MODPY_SETUPUTILS =     No
@@ -80,6 +113,7 @@ MODPY_TKINTER_DEPENDS=       ${MODPY_RUN_DEPEN
 .endif
 
 MODPY_BIN=             ${LOCALBASE}/bin/python${MODPY_VERSION}
+MODPY_INCDIR=          
${LOCALBASE}/include/python${MODPY_VERSION}${MODPY_LIB_SUFFIX}
 MODPY_LIBDIR=          ${LOCALBASE}/lib/python${MODPY_VERSION}
 MODPY_SITEPKG=         ${MODPY_LIBDIR}/site-packages
 
@@ -111,7 +145,7 @@ CONFIGURE_ENV+=     PYTHON="${MODPY_BIN}"
 _MODPY_CMD=    @cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} \
                        ${MODPY_BIN} ./${MODPY_SETUP}
 
-SUBST_VARS:=   MODPY_BIN MODPY_EGG_VERSION MODPY_VERSION ${SUBST_VARS}
+SUBST_VARS:=   MODPY_BIN MODPY_EGG_VERSION MODPY_VERSION MODPY_BIN_SUFFIX 
MODPY_DOC_PREFIX ${SUBST_VARS}
 
 # set MODPY_BIN for executable scripts
 MODPY_BIN_ADJ= perl -pi \

Reply via email to