#73 preprocessing spec file support
Opened 3 years ago by clime. Modified 3 years ago
clime/rpmdevtools master  into  master

No commits found

Hello,

this adds support for spec file preprocessing (per https://fedoraproject.org/wiki/Changes/Enable_Spec_File_Preprocessing)

Requires preproc-rpmspec 1.2, which is now waiting to get into stable repos (https://bodhi.fedoraproject.org/updates/FEDORA-2020-091d3f026a)

I haven't found a place to add requirements...perhaps they are specified only downstream?

Maybe also the original perl version should be patched but it no longer exists in the repo.

NOTES from the commit:
uses preproc-rpmspec utility
spec file is only preprocessed if allowed by rpkg.conf placed
in git repo or spec's directory context (in case the target
spec file is not placed in a git repo, only the second option
remains), otherwise the original text is simply returned.

1 new commit added

  • add note about possibility of input spec file being a template into HELP_TEXT
3 years ago

Added one more commit regarding the help text.

Also, the patch assumes python3. If it should be run under python2 too, let me know, special care needs to be taken when writing to a file (regarding encoding).

Some comments:

  1. You didn't update the complete_spec_paths function. without that, shell completion won't work for templated files.
  2. Why did you remove mess with the code for specifying additional --define values? With the current diff, it just will crash, since the temp variable no longer defined in that code path.
  3. Am I reading this correctly that the spec preprocessor is run unconditionally? That doesn't sound like a good idea. Making this conditional on the extension of the input filename would be better.
  4. If you wanted to add a documentation comment to the preprocess function, those are delimited with triple quotes (""") in Python.
  5. Since we're assuming Python 3 anyway, please use subprocess.run instead of subprocess.Popen, and then you can use the .check_returncode() method on the return value of subprocess.run instead of doing this manually.
  6. You also don't need to specify utf-8 encoding, it's the default for .encode() and .decode() calls.

Some comments:

  1. You didn't update the complete_spec_paths function. without that, shell completion won't work for templated files.

Thanks, fixed!

  1. Why did you remove mess with the code for specifying additional --define values? With the current diff, it just will crash, since the temp variable no longer defined in that code path.

It shouldn't crash, the temp variable is now defined before the if args["define"]: line :).

  1. Am I reading this correctly that the spec preprocessor is run unconditionally? That doesn't sound like a good idea. Making this conditional on the extension of the input filename would be better.

Yes, by my proposal, the extension shouldn't play a role for tooling (it still plays a role for humans). It's the rpkg.preprocess_spec boolean read from rpkg.conf file that switches the preprocessing on and off. preproc-rpmspec already has the support for reading the rpkg configuration if present so I thought it would be better to let preproc-rpmspec do it instead of implementing the same decisioning directly in spectool. Nevertheless, if rpkg configuration doesn't enable preprocessing, the content of the input file will be simply copied to stdout without any change so the result will be exactly the same as if the input spec file content was read directly by spectool.

  1. If you wanted to add a documentation comment to the preprocess function, those are delimited with triple quotes (""") in Python.

Yes, the comment looks better as a docstring.

  1. Since we're assuming Python 3 anyway, please use subprocess.run instead of subprocess.Popen, and then you can use the .check_returncode() method on the return value of subprocess.run instead of doing this manually.

Done. Thanks!

  1. You also don't need to specify utf-8 encoding, it's the default for .encode() and .decode() calls.

Done.

3 new commits added

  • better error message formatting in preprocess
  • use subprocess.run in preprocess, improve comment style
  • fix completion for spec templates (i.e. files with .spec.rpkg extension)
3 years ago
Metadata