Bug 1818920 - %py3_install needs a -- separator before flags (undocumented)
Summary: %py3_install needs a -- separator before flags (undocumented)
Alias: None
Product: Fedora
Classification: Fedora
Component: python-rpm-macros
Version: 31
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Miro Hrončok
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2020-03-30 17:29 UTC by Robert Bost
Modified: 2020-04-29 12:50 UTC (History)
12 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2020-04-29 12:50:55 UTC
Type: Bug

Attachments (Terms of Use)

Description Robert Bost 2020-03-30 17:29:03 UTC
Description of problem:

I'm receiving the following error when building RPM:

  # rpmbuild -ba my.spec
  py3_install: invalid option -- '-'
  error: /code/my.spec: line 35: Unknown option - in py3_install()

Here's the %py_install line from my %install:

  %py3_install --install-scripts %{_libexecdir}

The only way I can make this work is by using:

  %py3_install -- --install-scripts %{_libexecdir}

Version-Release number of selected component (if applicable):
# rpm -qa rpm-build python3-devel

Expected results:

I wouldn't expect to have to use the `--` to delimit flags from %py3_install.

Comment 1 Panu Matilainen 2020-03-31 05:33:51 UTC
These are parametric macros (from python-rpm-macros), so rpm will treat anything starting with a dash as a *macro* option, unless separated with --.

Looking at these macros, they don't actually take any options so don't know why there are declared as such. Non-parametric might be better-suited to task at hand: these are just thinly veiled calls to python setup.py <foo>, and people expect arbitrary arguments to be passed on verbatim. As is the case here.

Comment 2 Miro Hrončok 2020-03-31 08:07:37 UTC
Panu, can non-parametric macros accept positional arguments? We do have %{?*} in there.

This is unlikely to change anyway. 1) The macros need to preserve backwards compatibility. 2) We are working on new macros instead: https://src.fedoraproject.org/rpms/pyproject-rpm-macros

Robert, using -- to separate the arguments is a known thing. We might want to say that in the guidelines thou, so I keep this open.

Comment 3 Panu Matilainen 2020-03-31 09:56:22 UTC
> Panu, can non-parametric macros accept positional arguments? We do have %{?*} in there.

Non-parametric macros don't *have* arguments, they're just ... text. So if you're just adding adding %{?*} at the end a parametric macro is little else than jumping through a whole bunch of hoops for nothing.

%py3_install() %{expand:\\\
  %{__python3} %{py_setup} %{?py_setup_args} install -O1 --skip-build --root %{buildroot} %{?*}

%py3_install %{expand:\\\
  %{__python3} %{py_setup} %{?py_setup_args} install -O1 --skip-build --root %{buildroot}

...for most practical purposes do the same exact thing, only the former means you can't pass arbitrary options to setup.py install without --. Which might be all well and good, "arbitrary" can be a double-edged sword. I'm not saying you *should* change these, but it's something you want to be aware of at least.

Comment 4 Miro Hrončok 2020-03-31 10:07:52 UTC
I see, thanks for the explanation. The biggest problem with that approach is that the arguments would be passed to rm:

%py3_install() %{expand:\\\
  %{__python3} %{py_setup} %{?py_setup_args} install -O1 --skip-build --root %{buildroot} %{?*}
   rm -rfv %{buildroot}%{_bindir}/__pycache__

Or to sleep:

%py2_build() %{expand:\\\
  sleep 1
  %{__python2} %{py_setup} %{?py_setup_args} build --executable="%{__python2} %{py2_shbang_opts}" %{?*}
  sleep 1

Etc. (the macros take arguments, so we can put them where we need them). We could possibly replace this with a clever shell function, but as said, we won't do this for the 2 listed reasons.

Comment 5 Panu Matilainen 2020-03-31 10:43:56 UTC
Yup, having control of arguments of course opens possibilities that don't exist otherwise. In these cases having to use -- might well be only a good thing.

Just FYI, there's a related upstream ticket requesting more control to macros over their options processing: https://github.com/rpm-software-management/rpm/issues/547

Comment 7 Miro Hrončok 2020-04-29 12:50:55 UTC
This is now documented in https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_macros

Note You need to log in before you can comment on or make changes to this bug.