Open MikeFalowski opened 1 year ago
Ok, I removed functools.cache
for test purposes (I have no idea what does it do here) and then I got this error:
[user@localhost localhost]$ pysrpm
Traceback (most recent call last):
File "/home/user/.local/bin/pysrpm", line 8, in <module>
sys.exit(cli())
File "/home/user/.local/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
File "/home/user/.local/lib/python3.9/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/home/user/.local/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/user/.local/lib/python3.9/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/home/user/.local/lib/python3.9/site-packages/pysrpm/__main__.py", line 68, in cli
with RPM(source, **options, cli_templates=templates) as rpm_builder:
File "/home/user/.local/lib/python3.9/site-packages/pysrpm/rpm.py", line 52, in __init__
with self.preset_configs() as config_lists:
File "/usr/lib64/python3.9/contextlib.py", line 119, in __enter__
return next(self.gen)
File "/home/user/.local/lib/python3.9/site-packages/pysrpm/rpm.py", line 69, in preset_configs
with importlib_resources.path('pysrpm', 'presets') as defaults_path:
File "/usr/lib64/python3.9/contextlib.py", line 119, in __enter__
return next(self.gen)
File "/usr/lib64/python3.9/importlib/resources.py", line 175, in _path_from_reader
opener_reader = reader.open_resource(norm_resource)
File "<frozen importlib._bootstrap_external>", line 1055, in open_resource
IsADirectoryError: [Errno 21] Is a directory: '/home/user/.local/lib/python3.9/site-packages/pysrpm/presets'
[
So, I've changed preset_configs
to:
@staticmethod
@contextlib.contextmanager
def preset_configs():
""" Context manager that ensures the preset configurations are in a directory, and yields the sorted list """
with importlib_resources.files('pysrpm').joinpath("presets") as defaults_path:
# with importlib_resources.path('pysrpm', 'presets') as defaults_path:
yield sorted(defaults_path.glob('*.conf'))
and I got this error:
[user@localhost localhost]$ pysrpm dist/dev-solaris-mlworker-0.0.0.tar.gz
/home/user/.local/lib/python3.9/site-packages/pysrpm/presets
Traceback (most recent call last):
File "/home/user/.local/lib/python3.9/site-packages/pysrpm/rpm.py", line 377, in _format_lines
successful_lines.append(line.format(**kwargs))
KeyError: 'author'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/user/.local/bin/pysrpm", line 8, in <module>
sys.exit(cli())
File "/home/user/.local/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
File "/home/user/.local/lib/python3.9/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/home/user/.local/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/user/.local/lib/python3.9/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/home/user/.local/lib/python3.9/site-packages/pysrpm/__main__.py", line 69, in cli
rpm_builder.run()
File "/home/user/.local/lib/python3.9/site-packages/pysrpm/rpm.py", line 460, in run
spec = self.make_spec(pkg_info)
File "/home/user/.local/lib/python3.9/site-packages/pysrpm/rpm.py", line 395, in make_spec
spec = self._format_lines(self.templates['preamble'].lstrip('\n'), **pkg_info)
File "/home/user/.local/lib/python3.9/site-packages/pysrpm/rpm.py", line 380, in _format_lines
raise KeyError(f'Missing template key(s) {", ".join(err.args)}') from err
KeyError: 'Missing template key(s) author'
I'm stuck here for now. In pyproject.toml
there is authors
field, not author
.
It looks like the first error is related to this https://github.com/cython/cython/issues/1434 When I left cache but removed staticmethod it also worked.
I’m afraid this project isn’t that well maintained anymore, as it turns out there’s a lot more differences between various rpm specs that I suspected so I’m not regularly using it anymore.
To answer your questions:
functools.cache
caches a function result so it only has to be computed once, but maybe it doesn’t play nice with the staticmethod
as you found out.importlib.resources
has had changes over recent releases of python so your changes seem appropriatemetadata
before the return of load_source_metadata()
to handle the case I hadn’t foreseen. Something like (ref):
if 'author' not in metadata and 'authors' in metadata:
metadata['author'] = ', '.join(f'{author["name"]} <{author["email"]}>' for author in metadata['authors'])
though it probably shoud also handle when only name or only email are present, and fail gracefully for invalid entries.
I try to build rpm from tar.gz package but unfortunately I got this error:
For additional info, I'm using pyproject.toml and
python3 -m build
.