Monday, June 24, 2019

WIP: Auto PKGNAME logic in python.port.mk

Almost every python port has a line similar to:
PKGNAME = py-${DISTNAME}

Some have:
PKGNAME = ${DISTNAME:S/^python-/py-/}

They are all very similar. Very boilerplate.

So I looked at getting rid of some more boilerplate. This one is a bit
trickier. After a bit of investigation and iteration I came up with the
following:

PKGNAME ?= py-${DISTNAME:L:C/^py(thon)?-?//:C/-py(thon)?[-_]/-/}

This little line works on between 80 and 90% of the python ports.

Of those that it doesn't work for, a chunk of them start with py, like
pyro, so it mangles them into py-ro. Most of the remaining cases have
capitalization. There are a number that just completely change the name.

A handful of them count on the default PKGNAME behavior for all ports.

This is just a WIP. Since I'm looking at doing it with "?=", this could go
in place and not break things... most of the time. Those ports that don't
define PKGNAME would break. So *if* I was to go forward on this, I would
identify all those ports and slap in a line to disable this new behavior.

If folks are really into this, I could come up with a massive diff (or
diffs) to convert all the lang/python ports to using this.

Regardless, if a port explicitly set PKGNAME, it wouldn't get touched.

This WIP diff has four possible values for MODPY_PKGNAME:

Yes
No
StartsWith
KeepCase

No makes python.port.mk not try to touch PKGNAME at all.

"StartsWith" is to handle those ports whose distfile starts with "py" and
shouldn't have it trimmed off and adjusted.

"KeepCase" does what the default magic does without making the whole thing
lowercase.

I'd like input on this. If folks are interested, I can carry it through.
If not, I may just see about putting the name mangling into the pypi portgen
module so we have more sane default names for new ports.

--Kurt

Index: python.port.mk
===================================================================
RCS file: /cvs/ports/lang/python/python.port.mk,v
retrieving revision 1.114
diff -u -p -r1.114 python.port.mk
--- python.port.mk 24 Jun 2019 14:25:54 -0000 1.114
+++ python.port.mk 25 Jun 2019 00:36:01 -0000
@@ -11,6 +11,20 @@ MODPY_DEFAULT_VERSION_3 = 3.7

.if !defined(MODPY_VERSION)

+# OK to set default PKGNAME
+MODPY_PKGNAME ?= Yes
+
+.if ${MODPY_PKGNAME:L} == "yes"
+# Default lang/python PKGNAME
+PKGNAME ?= py-${DISTNAME:L:C/^py(thon)?-?//:C/-py(thon)?[-_]/-/}
+.elif ${MODPY_PKGNAME:L} == "startswith"
+# DISTFILE starts with py and we should keep it (e.g. pyro)
+PKGNAME ?= py-${DISTNAME:L:C/-py(thon)?[-_]/-/}
+.elif ${MODPY_PKGNAME:L} == "keepcase"
+# Don't lowercase the DISTNAME
+PKGNAME ?= py-${DISTNAME:C/^py(thon)?-?//:C/-py(thon)?[-_]/-/}
+.endif
+
FLAVOR ?=

. if ${FLAVOR:Mpython3}

No comments:

Post a Comment