summaryrefslogtreecommitdiff
path: root/lang/python310
diff options
context:
space:
mode:
authorCharlie Li <vishwin@FreeBSD.org>2023-02-15 15:57:06 -0500
committerCharlie Li <vishwin@FreeBSD.org>2023-02-15 16:35:07 -0500
commitc17ddfbf66e2801ec620d49979aca3d7077d7002 (patch)
tree7c8717b62de7a907b3f638cde512f62ca9697752 /lang/python310
parentmultimedia/mkvtoolnix: Update to upstream release 74.0.0 (diff)
lang/python: add bytecode trigger
Facilitates compiling, writing and removing bytecode files (.pyc) in site-packages after all pkg transactions have been completed. Technical details: https://wiki.freebsd.org/Python/CompiledPackages Fixes reports of Python port builds as root failing on filesystem violations due to bytecode file writes where the port did not include them in the package. For those ports/packages that currently package bytecode, some checksum mismatches on those files may occur. This is harmless and will be rectified, in large as part of a USE_PYTHON=distutils overhaul to reduce churn. While here, implement a long-standing todo item of letting lang/python ports use python.mk bits. Not only does this obviate duplicate variables in each Makefile, but SUB_LIST (also added) is used for these triggers. Co-authored by: tcberner Approved by: tcberner (mentor) Differential Revision: https://reviews.freebsd.org/D34739
Diffstat (limited to 'lang/python310')
-rw-r--r--lang/python310/Makefile11
-rw-r--r--lang/python310/files/python3.10.ucl.in40
2 files changed, 44 insertions, 7 deletions
diff --git a/lang/python310/Makefile b/lang/python310/Makefile
index 7e51ea43cce1..66974f6c5366 100644
--- a/lang/python310/Makefile
+++ b/lang/python310/Makefile
@@ -1,5 +1,6 @@
PORTNAME= python
DISTVERSION= ${PYTHON_DISTVERSION}
+PORTREVISION= 1
CATEGORIES= lang python
MASTER_SITES= PYTHON/ftp/python/${DISTVERSION:C/[a-z].*//}
PKGNAMESUFFIX= ${PYTHON_SUFFIX}
@@ -14,8 +15,8 @@ LICENSE= PSFL
LIB_DEPENDS= libffi.so:devel/libffi
-USES= compiler:c11 cpe ncurses pathfix pkgconfig readline \
- shebangfix ssl tar:xz
+USES= compiler:c11 cpe ncurses pathfix pkgconfig \
+ python:${PYTHON_DISTVERSION:R},env readline shebangfix ssl tar:xz trigger
PATHFIX_MAKEFILEIN= Makefile.pre.in
USE_LDCONFIG= yes
GNU_CONFIGURE= yes
@@ -24,11 +25,7 @@ SHEBANG_FILES= Lib/*.py Lib/*/*.py Lib/*/*/*.py Lib/*/*/*/*.py
SHEBANG_FILES+= Lib/test/ziptestdata/exe_with_z64 \
Lib/test/ziptestdata/exe_with_zip \
Lib/test/ziptestdata/header.sh
-
-# Duplicate python.mk variables. TODO: Let lang/python?? ports use python.mk bits.
-PYTHON_VER= ${PYTHON_DISTVERSION:R}
-PYTHON_VERSION= python${PYTHON_VER}
-PYTHON_SUFFIX= ${PYTHON_VER:S/.//g}
+TRIGGERS= ${PYTHON_VERSION}
DISABLED_EXTENSIONS= _sqlite3 _tkinter _gdbm
CONFIGURE_ARGS+= --enable-shared --without-ensurepip \
diff --git a/lang/python310/files/python3.10.ucl.in b/lang/python310/files/python3.10.ucl.in
new file mode 100644
index 000000000000..63d455839549
--- /dev/null
+++ b/lang/python310/files/python3.10.ucl.in
@@ -0,0 +1,40 @@
+path_glob: "%%PYTHON_SITELIBDIR%%/*"
+trigger: {
+ type: lua
+ sandbox: false
+ script: <<EOS
+function cleanup(directory)
+ for _,d in ipairs(pkg.readdir(directory)) do
+ local full_path = directory .. "/" .. d
+ local stat = pkg.stat(full_path)
+ if stat["type"] == "dir" then
+ if (d ~= "__pycache__") then
+ cleanup(full_path)
+ else
+ for _,bytecode_file in ipairs(pkg.readdir(full_path)) do
+ local file_origin = string.gsub(bytecode_file, "[.]cpython[-]%%PYTHON_SUFFIX%%[.].*pyc", ".py")
+ if file_origin then
+ local origin_path = directory .. "/" .. file_origin
+ if (not pkg.stat(origin_path)) then
+ --print(" >=> removed stale bytecode " .. bytecode_file)
+ os.remove(full_path .. "/" .. bytecode_file)
+ end
+ end
+ end
+ end
+ local res = pkg.readdir(full_path)
+ if #res == 0 then
+ --print(" >=> removed empty directory " .. full_path )
+ os.remove(full_path)
+ end
+ end
+ end
+end
+
+print(">=> Cleaning stale bytecode files...")
+cleanup("%%PYTHON_SITELIBDIR%%")
+
+print(">=> Byte-compiling Python source files...")
+pkg.exec({"%%PYTHON_VERSION%%", "-m", "compileall", "-q", "-o", "0", "-o", "1", "-o", "2", "%%PYTHON_SITELIBDIR%%"})
+EOS
+}