#20 Assure presence of workdir in RpmBuilder
Merged by otaylor. Opened by yselkowitz.
yselkowitz/flatpak-module-tools main  into  main

Download 20.patch

This avoids FileNotFoundError during build-container-local in the case that $arch/rpms exists but $arch/work does not (e.g. it was removed since the last build-rpms-local to save space).

 Finding dependencies of flatseal not in runtime ... 
Traceback (most recent call last):
  File "/home/yselkowi/.local/bin/flatpak-module", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yselkowi/.local/lib/python3.11/site-packages/flatpak_module_tools/cli.py", line 111, in build_container_local
    rpm_builder.check(include_localrepo=True, allow_outdated=allow_outdated)
  File "/home/yselkowi/.local/lib/python3.11/site-packages/flatpak_module_tools/rpm_builder.py", line 351, in check
    need_rebuild, _, wait_for_event = self._check_packages(
                                      ^^^^^^^^^^^^^^^^^^^^^
  File "/home/yselkowi/.local/lib/python3.11/site-packages/flatpak_module_tools/rpm_builder.py", line 160, in _check_packages
    details = self._resolve_packages(include_localrepo=include_localrepo)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yselkowi/.local/lib/python3.11/site-packages/flatpak_module_tools/rpm_builder.py", line 144, in _resolve_packages
    output = self._run_depchase(
             ^^^^^^^^^^^^^^^^^^^
  File "/home/yselkowi/.local/lib/python3.11/site-packages/flatpak_module_tools/rpm_builder.py", line 110, in _run_depchase
    with open(packages_file, "w") as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/yselkowi/src/fedora/flatpaks/flatseal/x86_64/work/flatpak-runtime-f39.packages'

The bug, in some sense, is that check() doesn't create the workdir in the same way as build_rpms() and build_rpms_local() does. It's basically fine to move creating the workdir to time of use, as you do here, but then the creation in build_rpms() and build_rpms_local() should be removed.

Alternatives:

  • Create it in the constructor. .I'm a bit allergic to constructors with file-system side effects.
  • Something like:

    @cached_property
    def workdir():
         workdir = Path.cwd() / self.arch.rpm / "work"
         workdir.mkdir(parents=True, exist_ok=True)
         return workdir
    
  • Drop workdir entirely and create the packages file with tempfile.NamedTemporaryFile

rebased onto 459a1d32bb8dbc46c83d3ec3746bda5c2f0d1427

rebased onto 9a4006ac166bd9c47c495a9d041efaa5ba943792

Pull-Request has been merged by otaylor

Metadata