+2024-05-02 Collin Funk <collin.funk1@gmail.com>
+
+ gnulib-tool.py: Don't leave temporary directories on exit.
+ * pygnulib/main.py (main_with_exception_handling): Use
+ tempfile.TemporaryDirectory as a context manager so it is removed before
+ the program exits.
+ (main): Expect a temporary directory to be passed as an argument.
+ * pygnulib/GLConfig.py (GLConfig.__init__): Accept an optional temporary
+ directory parameter instead of creating one.
+ * pygnulib/GLImport.py (GLImport.__init__): Don't remove the cache's
+ temporary directory since it doesn't create one anymore.
+ (GLImport.execute): Don't remove the temporary directory explicitly. It
+ is handled by the usage of a context manager.
+ * pygnulib/GLTestDir.py (GLTestDir.execute, GLMegaTestDir.execute):
+ Likewise.
+
2024-05-01 Collin Funk <collin.funk1@gmail.com>
gnulib-tool.py: Quote file names passed to 'patch'.
#===============================================================================
import os
import copy
-import tempfile
from typing import Any
from .constants import (
MODES,
table: dict[str, Any]
def __init__(self,
+ tempdir: str | None = None,
destdir: str | None = None,
localpath: list[str] | None = None,
auxdir: str | None = None,
errors: bool | None = None) -> None:
'''Create new GLConfig instance.'''
self.table = dict()
- self.table['tempdir'] = tempfile.mkdtemp(prefix='glpy')
+ self.table['tempdir'] = tempdir
# Check and store the attributes.
# Remove trailing slashes from the directory names. This is necessary
# for m4base (to avoid an error in func_import) and optional for the
# self.cache is the configuration extracted from some files on the
# file system: configure.{ac,in}, gnulib-cache.m4, gnulib-comp.m4.
self.cache = GLConfig()
- os.rmdir(self.cache['tempdir'])
# Read configure.{ac,in}.
with open(self.config.getAutoconfFile(), mode='r', newline='\n', encoding='utf-8') as file:
position_early_after = 'AC_PROG_CC'
print(' - invoke %s_EARLY in %s, right after %s,' % (macro_prefix, configure_ac, position_early_after))
print(' - invoke %s_INIT in %s.' % (macro_prefix, configure_ac))
- rmtree(self.config['tempdir'])
if os.path.isfile(joinpath('build-aux', 'test-driver')):
_patch_test_driver()
os.chdir(DIRS['cwd'])
- rmtree(self.config['tempdir'])
#===============================================================================
if os.path.isfile(joinpath('build-aux', 'test-driver')):
_patch_test_driver()
os.chdir(DIRS['cwd'])
- rmtree(self.config['tempdir'])
import argparse
import subprocess as sp
import shlex
-from tempfile import mktemp
+import tempfile
from pygnulib.constants import (
APP,
DIRS,
#===============================================================================
# Define main part
#===============================================================================
-def main() -> None:
+def main(temp_directory: str) -> None:
info = GLInfo()
parser = argparse.ArgumentParser(
prog=APP['name'],
# Create pygnulib configuration.
config = GLConfig(
+ tempdir=temp_directory,
destdir=destdir,
localpath=localpath,
m4base=m4base,
modulesystem = GLModuleSystem(config)
listing = modulesystem.list()
result = lines_to_multiline(listing)
- os.rmdir(config['tempdir'])
print(result, end='')
elif mode == 'find':
def main_with_exception_handling() -> None:
try: # Try to execute
- main()
+ with tempfile.TemporaryDirectory() as temporary_directory:
+ main(temporary_directory)
except GLError as error:
errmode = 0 # gnulib-style errors
errno = error.errno