texlive[74766] Master/texmf-dist: latex2pydata (27mar25)

commits+karl at tug.org commits+karl at tug.org
Thu Mar 27 20:07:09 CET 2025


Revision: 74766
          https://tug.org/svn/texlive?view=revision&revision=74766
Author:   karl
Date:     2025-03-27 20:07:09 +0100 (Thu, 27 Mar 2025)
Log Message:
-----------
latex2pydata (27mar25)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/latex2pydata/CHANGELOG.md
    trunk/Master/texmf-dist/doc/latex/latex2pydata/latex2pydata.pdf
    trunk/Master/texmf-dist/source/latex/latex2pydata/latex2pydata.dtx
    trunk/Master/texmf-dist/tex/latex/latex2pydata/latex2pydata.sty

Modified: trunk/Master/texmf-dist/doc/latex/latex2pydata/CHANGELOG.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/latex2pydata/CHANGELOG.md	2025-03-27 19:06:59 UTC (rev 74765)
+++ trunk/Master/texmf-dist/doc/latex/latex2pydata/CHANGELOG.md	2025-03-27 19:07:09 UTC (rev 74766)
@@ -1,6 +1,16 @@
 # Changelog — latex2pydata LaTeX package
 
 
+## v0.6.0 (2025/03/26)
+
+*  `\pydatasetfilename` now automatically reuses file handles when files are
+   closed, so that the total number of file handles created is never more than
+   the maximum number of files open simultaneously.  This minimizes the
+   potential for "`No more room for a new \write`" errors.  Previously, one
+   file handle was created per file (#2).
+
+
+
 ## v0.5.0 (2025/03/03)
 
 *  Renamed schema missing setting `rawstr` to `verbatim`.

Modified: trunk/Master/texmf-dist/doc/latex/latex2pydata/latex2pydata.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/latex2pydata/latex2pydata.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/latex2pydata/latex2pydata.dtx	2025-03-27 19:06:59 UTC (rev 74765)
+++ trunk/Master/texmf-dist/source/latex/latex2pydata/latex2pydata.dtx	2025-03-27 19:07:09 UTC (rev 74766)
@@ -27,7 +27,7 @@
 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
 %<package>\ProvidesPackage{latex2pydata}
 %<*package>
-    [2025/03/03 v0.5.0 latex2pydata - write data to file in Python literal format]
+    [2025/03/26 v0.6.0 latex2pydata - write data to file in Python literal format]
 %</package>
 %
 %<*driver>
@@ -382,6 +382,8 @@
 %
 % |\pydatasetfilename| sets the filename globally.
 %
+% Implementation note:  This automatically creates the necessary file handles with |\newwrite|.  File handles are automatically reused when files are closed, so that the total number of file handles created is never more than the maximum number of files open simultaneously.  This minimizes the potential for ``\Verb[breaklines]{No more room for a new \write}'' errors.
+%
 % \DescMacro{\pydataclosefilename\marg{filename}}
 % Close a file previously opened with |\pydatasetfilename|.  Also perform basic checking for incomplete or malformed data written to file.
 %
@@ -782,29 +784,71 @@
 % \end{macro}
 %
 % \begin{macro}{\pydatasetfilename, \pydataclosefilename}
-% Shortcut for creating a |\newwrite| and then passing the file handle to |\pydatasetfilehandle|.  File handles are global.  If the close macro is not invoked, then basic data checking on the \LaTeX\ side will not be performed.  However, \TeX\ will \href{https://tex.stackexchange.com/a/337291}{automatically close open writes at the end of the compile}.
+% Shortcut for invoking |\newwrite| and then passing the file handle to |\pydatasetfilehandle|.  File handles are global.  If the close macro is not invoked, then basic data checking on the \LaTeX\ side will not be performed.  However, \TeX\ will \href{https://tex.stackexchange.com/a/337291}{automatically close open writes at the end of the compile}.
+%
+% File handles created by |\newwrite| are collected in a file handle ``pool'' and then reused when possible to minimize the potential for ``\Verb[breaklines]{No more room for a new \write}'' errors.
 %    \begin{macrocode}
+\def\pydata at fhpoolsize{0}
 \def\pydatasetfilename#1{%
   \if\relax\detokenize{#1}\relax
     \pydata at error{Missing filename}%
   \fi
-  \ifcsname pydata at fh@#1\endcsname
+  \ifcsname pydata at filenamefh@#1\endcsname
+    \expandafter\let\expandafter\pydata at fhtmp
+      \csname pydata at filenamefh@#1\endcsname
+    \expandafter\let\expandafter\pydata at fhpoolindextmp
+      \csname pydata at filenamefhpoolindex@#1\endcsname
   \else
-    \expandafter\newwrite\csname pydata at fh@#1\endcsname
+    \def\pydata at fhpoolindex{0}%
+    \loop\unless\ifnum\pydata at fhpoolindex=\pydata at fhpoolsize\relax
+      \ifbool{pydata at fileisopen@\pydata at fhpoolindex}%
+       {}%
+       {\expandafter\let\expandafter\pydata at fhtmp
+          \csname pydata at fh@\pydata at fhpoolindex\endcsname
+        \let\pydata at fhpoolindextmp\pydata at fhpoolindex
+        \expandafter\global\expandafter
+          \let\csname pydata at filenamefh@#1\endcsname\pydata at fhtmp
+        \expandafter\global\expandafter
+          \let\csname pydata at filenamefhpoolindex@#1\endcsname\pydata at fhpoolindextmp
+        \let\pydata at fhpoolindex\pydata at fhpoolsize}%
+    \repeat
+    \let\pydata at fhpoolindex\pydata at undefined
+    \ifcsname pydata at filenamefh@#1\endcsname
+    \else
+      \expandafter\newwrite\csname pydata at fh@\pydata at fhpoolsize\endcsname
+      \pydata at newglobalbool{pydata at fileisopen@\pydata at fhpoolsize}%
+      \expandafter\let\expandafter\pydata at fhtmp
+        \csname pydata at fh@\pydata at fhpoolsize\endcsname
+      \expandafter\global\expandafter
+        \let\csname pydata at filenamefh@#1\endcsname\pydata at fhtmp
+      \let\pydata at fhpoolindextmp\pydata at fhpoolsize
+      \expandafter\global\expandafter
+        \let\csname pydata at filenamefhpoolindex@#1\endcsname\pydata at fhpoolindextmp
+      \xdef\pydata at fhpoolsize{\the\numexpr\pydata at fhpoolsize+1\relax}%
+    \fi
   \fi
-  \pydata at provideglobalbool{pydata at fileisopen@#1}%
-  \ifbool{pydata at fileisopen@#1}%
+  \ifbool{pydata at fileisopen@\pydata at fhpoolindextmp}%
    {}%
-   {\expandafter\immediate\expandafter\openout\csname pydata at fh@#1\endcsname=#1\relax
-    \booltrue{pydata at fileisopen@#1}}%
-  \expandafter\pydatasetfilehandle\expandafter{\csname pydata at fh@#1\endcsname}}
+   {\immediate\openout\pydata at fhtmp=#1\relax
+    \booltrue{pydata at fileisopen@\pydata at fhpoolindextmp}}%
+  \pydatasetfilehandle{\pydata at fhtmp}%
+  \let\pydata at fhtmp\pydata at undefined
+  \let\pydata at fhpoolindextmp\pydata at undefined}
 \def\pydataclosefilename#1{%
-  \ifcsname pydata at fh@#1\endcsname
-    \ifbool{pydata at fileisopen@#1}%
-     {\expandafter\pydatareleasefilehandle\expandafter{\csname pydata at fh@#1\endcsname}%
-      \expandafter\immediate\expandafter\closeout\csname pydata at fh@#1\endcsname
-      \boolfalse{pydata at fileisopen@#1}}%
-     {}%
+  \ifcsname pydata at filenamefh@#1\endcsname
+    \expandafter\let\expandafter\pydata at fhtmp
+      \csname pydata at filenamefh@#1\endcsname
+    \expandafter\let\expandafter\pydata at fhpoolindextmp
+      \csname pydata at filenamefhpoolindex@#1\endcsname
+    \pydatareleasefilehandle{\pydata at fhtmp}%
+    \immediate\closeout\pydata at fhtmp
+    \boolfalse{pydata at fileisopen@\pydata at fhpoolindextmp}%
+    \expandafter\global\expandafter
+      \let\csname pydata at filenamefh@#1\endcsname\pydata at undefined
+    \expandafter\global\expandafter
+      \let\csname pydata at filenamefhpoolindex@#1\endcsname\pydata at undefined
+    \let\pydata at fhtmp\pydata at undefined
+    \let\pydata at fhpoolindextmp\pydata at undefined
   \else
     \pydata at error{Unknown file name "#1"}%
   \fi}

Modified: trunk/Master/texmf-dist/tex/latex/latex2pydata/latex2pydata.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/latex2pydata/latex2pydata.sty	2025-03-27 19:06:59 UTC (rev 74765)
+++ trunk/Master/texmf-dist/tex/latex/latex2pydata/latex2pydata.sty	2025-03-27 19:07:09 UTC (rev 74766)
@@ -20,7 +20,7 @@
 %% 
 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
 \ProvidesPackage{latex2pydata}
-    [2025/03/03 v0.5.0 latex2pydata - write data to file in Python literal format]
+    [2025/03/26 v0.6.0 latex2pydata - write data to file in Python literal format]
 \def\pydata at error#1{%
   \PackageError{latex2pydata}{#1}{}%
   \batchmode\read -1 to \pydata at exitnow}
@@ -131,27 +131,67 @@
    {}%
   \pydata at fhresetstate{#1}%
   \booltrue{pydata at fhisreleased@\number#1}}
+\def\pydata at fhpoolsize{0}
 \def\pydatasetfilename#1{%
   \if\relax\detokenize{#1}\relax
     \pydata at error{Missing filename}%
   \fi
-  \ifcsname pydata at fh@#1\endcsname
+  \ifcsname pydata at filenamefh@#1\endcsname
+    \expandafter\let\expandafter\pydata at fhtmp
+      \csname pydata at filenamefh@#1\endcsname
+    \expandafter\let\expandafter\pydata at fhpoolindextmp
+      \csname pydata at filenamefhpoolindex@#1\endcsname
   \else
-    \expandafter\newwrite\csname pydata at fh@#1\endcsname
+    \def\pydata at fhpoolindex{0}%
+    \loop\unless\ifnum\pydata at fhpoolindex=\pydata at fhpoolsize\relax
+      \ifbool{pydata at fileisopen@\pydata at fhpoolindex}%
+       {}%
+       {\expandafter\let\expandafter\pydata at fhtmp
+          \csname pydata at fh@\pydata at fhpoolindex\endcsname
+        \let\pydata at fhpoolindextmp\pydata at fhpoolindex
+        \expandafter\global\expandafter
+          \let\csname pydata at filenamefh@#1\endcsname\pydata at fhtmp
+        \expandafter\global\expandafter
+          \let\csname pydata at filenamefhpoolindex@#1\endcsname\pydata at fhpoolindextmp
+        \let\pydata at fhpoolindex\pydata at fhpoolsize}%
+    \repeat
+    \let\pydata at fhpoolindex\pydata at undefined
+    \ifcsname pydata at filenamefh@#1\endcsname
+    \else
+      \expandafter\newwrite\csname pydata at fh@\pydata at fhpoolsize\endcsname
+      \pydata at newglobalbool{pydata at fileisopen@\pydata at fhpoolsize}%
+      \expandafter\let\expandafter\pydata at fhtmp
+        \csname pydata at fh@\pydata at fhpoolsize\endcsname
+      \expandafter\global\expandafter
+        \let\csname pydata at filenamefh@#1\endcsname\pydata at fhtmp
+      \let\pydata at fhpoolindextmp\pydata at fhpoolsize
+      \expandafter\global\expandafter
+        \let\csname pydata at filenamefhpoolindex@#1\endcsname\pydata at fhpoolindextmp
+      \xdef\pydata at fhpoolsize{\the\numexpr\pydata at fhpoolsize+1\relax}%
+    \fi
   \fi
-  \pydata at provideglobalbool{pydata at fileisopen@#1}%
-  \ifbool{pydata at fileisopen@#1}%
+  \ifbool{pydata at fileisopen@\pydata at fhpoolindextmp}%
    {}%
-   {\expandafter\immediate\expandafter\openout\csname pydata at fh@#1\endcsname=#1\relax
-    \booltrue{pydata at fileisopen@#1}}%
-  \expandafter\pydatasetfilehandle\expandafter{\csname pydata at fh@#1\endcsname}}
+   {\immediate\openout\pydata at fhtmp=#1\relax
+    \booltrue{pydata at fileisopen@\pydata at fhpoolindextmp}}%
+  \pydatasetfilehandle{\pydata at fhtmp}%
+  \let\pydata at fhtmp\pydata at undefined
+  \let\pydata at fhpoolindextmp\pydata at undefined}
 \def\pydataclosefilename#1{%
-  \ifcsname pydata at fh@#1\endcsname
-    \ifbool{pydata at fileisopen@#1}%
-     {\expandafter\pydatareleasefilehandle\expandafter{\csname pydata at fh@#1\endcsname}%
-      \expandafter\immediate\expandafter\closeout\csname pydata at fh@#1\endcsname
-      \boolfalse{pydata at fileisopen@#1}}%
-     {}%
+  \ifcsname pydata at filenamefh@#1\endcsname
+    \expandafter\let\expandafter\pydata at fhtmp
+      \csname pydata at filenamefh@#1\endcsname
+    \expandafter\let\expandafter\pydata at fhpoolindextmp
+      \csname pydata at filenamefhpoolindex@#1\endcsname
+    \pydatareleasefilehandle{\pydata at fhtmp}%
+    \immediate\closeout\pydata at fhtmp
+    \boolfalse{pydata at fileisopen@\pydata at fhpoolindextmp}%
+    \expandafter\global\expandafter
+      \let\csname pydata at filenamefh@#1\endcsname\pydata at undefined
+    \expandafter\global\expandafter
+      \let\csname pydata at filenamefhpoolindex@#1\endcsname\pydata at undefined
+    \let\pydata at fhtmp\pydata at undefined
+    \let\pydata at fhpoolindextmp\pydata at undefined
   \else
     \pydata at error{Unknown file name "#1"}%
   \fi}



More information about the tex-live-commits mailing list.