Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F131458740
D34739.id118877.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
15 KB
Referenced Files
None
Subscribers
None
D34739.id118877.diff
View Options
Index: Mk/Uses/trigger.mk
===================================================================
--- Mk/Uses/trigger.mk
+++ Mk/Uses/trigger.mk
@@ -10,20 +10,21 @@
.if !defined(_INCLUDE_USES_TRIGGER_MK)
_INCLUDE_USES_TRIGGER_MK= yes
-. if !empty(trigger_ARGS)
-IGNORE= Incorrect 'USES+= trigger:${trigger_ARGS}' trigger takes no arguments
+_flavored= #
+. if !empty(trigger_ARGS:Mflavored)
+_flavored= -${FLAVOR}
. endif
TRIGGERS?= ${PORTNAME}
. for t in ${TRIGGERS}
SUB_FILES+= ${t}.ucl
-PLIST_FILES+= ${LOCALBASE}/share/pkg/triggers/$t.ucl
+PLIST_FILES+= ${LOCALBASE}/share/pkg/triggers/$t${_flavored}.ucl
. endfor
_USES_install+= 601:trigger-post-install
trigger-post-install:
${MKDIR} ${STAGEDIR}${LOCALBASE}/share/pkg/triggers
. for t in ${TRIGGERS}
- ${INSTALL_DATA} ${WRKDIR}/$t.ucl ${STAGEDIR}${LOCALBASE}/share/pkg/triggers/
+ ${INSTALL_DATA} ${WRKDIR}/$t.ucl ${STAGEDIR}${LOCALBASE}/share/pkg/triggers/$t${_flavored}.ucl
. endfor
.endif
Index: lang/Makefile
===================================================================
--- lang/Makefile
+++ lang/Makefile
@@ -285,6 +285,7 @@
SUBDIR += python-doc-pdf-letter
SUBDIR += python-doc-text
SUBDIR += python-mode.el
+ SUBDIR += python-pycache
SUBDIR += python-tools
SUBDIR += python2
SUBDIR += python27
Index: lang/python-pycache/Makefile
===================================================================
--- /dev/null
+++ lang/python-pycache/Makefile
@@ -0,0 +1,26 @@
+PORTNAME= python-pycache
+PORTVERSION= 0.0.1
+PKGNAMESUFFIX= ${PYTHON_PKGNAMESUFFIX}
+
+CATEGORIES= lang
+
+MAINTAINER= portmgr@FreeBSD.org
+COMMENT= Trigger to recreate python precompiled bytecode
+
+USES= metaport trigger:flavored python:env
+USE_PYTHON= flavors
+TRIGGERS= python-update-cache
+
+
+SUB_LIST= PYTHON_CMD=${PYTHON_CMD} \
+ NEW_CACHE_CMD=${_NEW_CACHE_CMD}
+
+.include <bsd.port.pre.mk>
+
+.if ${PYTHON_VER:M3.7} || ${PYTHON_VER:M3.8}
+_NEW_CACHE_CMD= false
+.else
+_NEW_CACHE_CMD= yes
+.endif
+
+.include <bsd.port.post.mk>
Index: lang/python-pycache/files/python-update-cache.ucl.in
===================================================================
--- /dev/null
+++ lang/python-pycache/files/python-update-cache.ucl.in
@@ -0,0 +1,93 @@
+path_glob: "%%PYTHON_SITELIBDIR%%/*"
+
+trigger: {
+ type: lua
+ sandbox: false
+ script: <<EOS
+function cleanup(directory)
+ if not pkg.stat(directory) then
+ return
+ end
+ for _,d in ipairs(pkg.readdir(directory)) do
+ local full_path = directory .. "/" .. d
+ local stat = pkg.stat(full_path)
+ if stat and stat["type"] == "dir" then
+ if (not (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[-]%d%d[.].*py[oc]", ".py")
+ if file_origin then
+ local origin_path = directory .. "/" .. file_origin
+ if (not pkg.stat(origin_path)) then
+ os.remove(full_path .. "/" .. bytecode_file)
+ end
+ end
+ end
+ local res = pkg.readdir(full_path)
+ if res and #res == 0 then
+ os.remove(full_path)
+ end
+ end
+ end
+ end
+ -- check wheter the directory itself has become stale
+ local items = pkg.readdir(directory)
+ if items and #items == 0 then
+ os.remove(directory)
+ end
+end
+
+function create(directory)
+ if %%NEW_CACHE_CMD%% then
+ pkg.exec({"%%PYTHON_CMD%%", "-m", "compileall", "-q", "-o", "0", "-o", "1", "-o", "2", "%%PYTHON_SITELIBDIR%%"})
+ else
+ pkg.exec({"%%PYTHON_CMD%%", "-m", "compileall", "-q", "%%PYTHON_SITELIBDIR%%"})
+ pkg.exec({"%%PYTHON_CMD%%", "-O", "-m", "compileall", "-q", "%%PYTHON_SITELIBDIR%%"})
+ pkg.exec({"%%PYTHON_CMD%%", "-OO", "-m", "compileall", "-q", "%%PYTHON_SITELIBDIR%%"})
+ end
+end
+
+function top_level(directory)
+ local filename_idx = string.find(directory, "/[^/]*$")
+ local filename = string.sub(directory, filename_idx, #directory)
+ local check = "%%PYTHON_SITELIBDIR%%" .. filename
+
+ return check == directory
+end
+
+function has_cache(directory)
+ local path = directory .. "/" .. "__pycache__"
+ local stat = pkg.stat(path)
+
+ return stat and stat["type"] == "dir"
+end
+
+if arg then
+ local to_clean = {}
+ local to_create = {}
+ -- filter the files passed by pkg to decide which paths to clean and to re-cache
+ for _, path in ipairs(arg) do
+ local stat = pkg.stat(path)
+ if stat then
+ if stat["type"] == "dir" then
+ table.insert(to_clean, path)
+ if top_level(path) and (not has_cache(path)) then
+ table.insert(to_create, path)
+ end
+ end
+ end
+ end
+ -- cleanup stale cache files
+ print("Cleaning Python bytecode files...")
+ for _, path in ipairs(to_clean) do
+ cleanup(path)
+ end
+ -- re-create cache
+ print("Creating Python bytecode files...")
+ for _, path in ipairs(to_create) do
+ create(path)
+ end
+end
+EOS
+}
Index: lang/python-pycache/pkg-descr
===================================================================
--- /dev/null
+++ lang/python-pycache/pkg-descr
@@ -0,0 +1 @@
+Recreates pycache on pkg registration.
Index: lang/python310/Makefile
===================================================================
--- lang/python310/Makefile
+++ lang/python310/Makefile
@@ -1,6 +1,6 @@
PORTNAME= python
DISTVERSION= ${PYTHON_DISTVERSION}
-PORTREVISION= 2
+PORTREVISION= 4
CATEGORIES= lang python
MASTER_SITES= PYTHON/ftp/python/${DISTVERSION:C/[a-z].*//}
PKGNAMESUFFIX= ${PYTHON_SUFFIX}
@@ -14,6 +14,7 @@
LICENSE= PSFL
LIB_DEPENDS= libffi.so:devel/libffi
+RUN_DEPENDS= python-pycache${PYTHON_PKGNAMESUFFIX}>=0:lang/python-pycache@${PY_FLAVOR}
USES= compiler:c11 cpe ncurses pathfix pkgconfig \
python:${PYTHON_DISTVERSION:R},env readline shebangfix ssl tar:xz
Index: lang/python310/files/python3.10.ucl.in
===================================================================
--- /dev/null
+++ lang/python310/files/python3.10.ucl.in
@@ -0,0 +1,62 @@
+path_glob: "%%PYTHON_SITELIBDIR%%/*"
+cleanup: {
+ 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
+ cleanup(full_path)
+ end
+ os.remove(full_path)
+ end
+ os.remove(directory)
+end
+
+cleanup("%%PYTHON_LIBDIR%%")
+EOS
+}
+
+trigger: {
+ type: lua
+ sandbox: false
+ script: <<EOS
+function cleanup(directory)
+ local entries = pkg.readdir(directory)
+ if entries == nil then
+ return
+ end
+ for _,d in ipairs(entries) 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
+ os.remove(full_path .. "/" .. bytecode_file)
+ end
+ end
+ end
+ end
+ local res = pkg.readdir(full_path)
+ if res and #res == 0 then
+ 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
+}
Index: lang/python311/Makefile
===================================================================
--- lang/python311/Makefile
+++ lang/python311/Makefile
@@ -1,6 +1,6 @@
PORTNAME= python
DISTVERSION= ${PYTHON_DISTVERSION}
-PORTREVISION= 2
+PORTREVISION= 4
CATEGORIES= lang python
MASTER_SITES= PYTHON/ftp/python/${DISTVERSION:C/[a-z].*//}
PKGNAMESUFFIX= ${PYTHON_SUFFIX}
@@ -14,6 +14,7 @@
LICENSE= PSFL
LIB_DEPENDS= libffi.so:devel/libffi
+RUN_DEPENDS= python-pycache${PYTHON_PKGNAMESUFFIX}>=0:lang/python-pycache@${PY_FLAVOR}
USES= compiler:c11 cpe ncurses pathfix pkgconfig \
python:${PYTHON_DISTVERSION:R},env readline shebangfix ssl tar:xz
Index: lang/python311/files/python3.11.ucl.in
===================================================================
--- /dev/null
+++ lang/python311/files/python3.11.ucl.in
@@ -0,0 +1,62 @@
+path_glob: "%%PYTHON_SITELIBDIR%%/*"
+cleanup: {
+ 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
+ cleanup(full_path)
+ end
+ os.remove(full_path)
+ end
+ os.remove(directory)
+end
+
+cleanup("%%PYTHON_LIBDIR%%")
+EOS
+}
+
+trigger: {
+ type: lua
+ sandbox: false
+ script: <<EOS
+function cleanup(directory)
+ local entries = pkg.readdir(directory)
+ if entries == nil then
+ return
+ end
+ for _,d in ipairs(entries) 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
+ os.remove(full_path .. "/" .. bytecode_file)
+ end
+ end
+ end
+ end
+ local res = pkg.readdir(full_path)
+ if res and #res == 0 then
+ 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
+}
Index: lang/python37/Makefile
===================================================================
--- lang/python37/Makefile
+++ lang/python37/Makefile
@@ -1,6 +1,6 @@
PORTNAME= python
DISTVERSION= ${PYTHON_DISTVERSION}
-PORTREVISION= 2
+PORTREVISION= 3
CATEGORIES= lang python
MASTER_SITES= PYTHON/ftp/python/${DISTVERSION}
PKGNAMESUFFIX= ${PYTHON_SUFFIX}
@@ -18,6 +18,7 @@
LIB_DEPENDS= libffi.so:devel/libffi \
libmpdec.so:math/mpdecimal
+RUN_DEPENDS= python-pycache${PYTHON_PKGNAMESUFFIX}>=0:lang/python-pycache@${PY_FLAVOR}
USES= cpe ncurses pathfix pkgconfig python:${PYTHON_DISTVERSION:R},env readline \
shebangfix ssl tar:xz
Index: lang/python37/files/python3.7.ucl.in
===================================================================
--- /dev/null
+++ lang/python37/files/python3.7.ucl.in
@@ -0,0 +1,64 @@
+path_glob: "%%PYTHON_SITELIBDIR%%/*"
+cleanup: {
+ 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
+ cleanup(full_path)
+ end
+ os.remove(full_path)
+ end
+ os.remove(directory)
+end
+
+cleanup("%%PYTHON_LIBDIR%%")
+EOS
+}
+
+trigger: {
+ type: lua
+ sandbox: false
+ script: <<EOS
+function cleanup(directory)
+ local entries = pkg.readdir(directory)
+ if entries == nil then
+ return
+ end
+ for _,d in ipairs(entries) 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
+ os.remove(full_path .. "/" .. bytecode_file)
+ end
+ end
+ end
+ end
+ local res = pkg.readdir(full_path)
+ if res and #res == 0 then
+ 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", "%%PYTHON_SITELIBDIR%%"})
+pkg.exec({"%%PYTHON_VERSION%%", "-O", "-m", "compileall", "-q", "%%PYTHON_SITELIBDIR%%"})
+pkg.exec({"%%PYTHON_VERSION%%", "-OO", "-m", "compileall", "-q", "%%PYTHON_SITELIBDIR%%"})
+EOS
+}
Index: lang/python38/Makefile
===================================================================
--- lang/python38/Makefile
+++ lang/python38/Makefile
@@ -1,6 +1,6 @@
PORTNAME= python
DISTVERSION= ${PYTHON_DISTVERSION}
-PORTREVISION= 2
+PORTREVISION= 4
CATEGORIES= lang python
MASTER_SITES= PYTHON/ftp/python/${DISTVERSION}
PKGNAMESUFFIX= ${PYTHON_SUFFIX}
@@ -14,6 +14,7 @@
LICENSE= PSFL
LIB_DEPENDS= libffi.so:devel/libffi
+RUN_DEPENDS= python-pycache${PYTHON_PKGNAMESUFFIX}>=0:lang/python-pycache@${PY_FLAVOR}
USES= cpe ncurses pathfix pkgconfig python:${PYTHON_DISTVERSION:R},env readline \
shebangfix ssl tar:xz
Index: lang/python38/files/python3.8.ucl.in
===================================================================
--- /dev/null
+++ lang/python38/files/python3.8.ucl.in
@@ -0,0 +1,64 @@
+path_glob: "%%PYTHON_SITELIBDIR%%/*"
+cleanup: {
+ 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
+ cleanup(full_path)
+ end
+ os.remove(full_path)
+ end
+ os.remove(directory)
+end
+
+cleanup("%%PYTHON_LIBDIR%%")
+EOS
+}
+
+trigger: {
+ type: lua
+ sandbox: false
+ script: <<EOS
+function cleanup(directory)
+ local entries = pkg.readdir(directory)
+ if entries == nil then
+ return
+ end
+ for _,d in ipairs(entries) 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
+ os.remove(full_path .. "/" .. bytecode_file)
+ end
+ end
+ end
+ end
+ local res = pkg.readdir(full_path)
+ if res and #res == 0 then
+ 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", "%%PYTHON_SITELIBDIR%%"})
+pkg.exec({"%%PYTHON_VERSION%%", "-O", "-m", "compileall", "-q", "%%PYTHON_SITELIBDIR%%"})
+pkg.exec({"%%PYTHON_VERSION%%", "-OO", "-m", "compileall", "-q", "%%PYTHON_SITELIBDIR%%"})
+EOS
+}
Index: lang/python39/Makefile
===================================================================
--- lang/python39/Makefile
+++ lang/python39/Makefile
@@ -1,6 +1,6 @@
PORTNAME= python
DISTVERSION= ${PYTHON_DISTVERSION}
-PORTREVISION= 2
+PORTREVISION= 4
CATEGORIES= lang python
MASTER_SITES= PYTHON/ftp/python/${DISTVERSION}
PKGNAMESUFFIX= ${PYTHON_SUFFIX}
@@ -14,6 +14,7 @@
LICENSE= PSFL
LIB_DEPENDS= libffi.so:devel/libffi
+RUN_DEPENDS= python-pycache${PYTHON_PKGNAMESUFFIX}>=0:lang/python-pycache@${PY_FLAVOR}
USES= compiler:c11 cpe ncurses pathfix pkgconfig \
python:${PYTHON_DISTVERSION:R},env readline shebangfix ssl tar:xz
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 9, 6:41 AM (10 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
23487295
Default Alt Text
D34739.id118877.diff (15 KB)
Attached To
Mode
D34739: lang/python: add bytecode trigger
Attached
Detach File
Event Timeline
Log In to Comment