#3 [BLOCKED] Move cargo-inspector (also) to rust-packaging
Closed 3 months ago by decathorpe. Opened 3 months ago by churchyard.
rpms/ churchyard/rust-packaging dont_pull_requests_jinja_tqdm  into  rawhide

file modified
+22 -10
@@ -21,11 +21,12 @@ 

  

  # gawk is needed for stripping dev-deps in macro

  Requires:       gawk

- Requires:       python3-rust2rpm = %{?epoch:%{epoch}:}%{version}-%{release}

  Requires:       rust-srpm-macros = %{version}

  Requires:       rust

  Requires:       cargo >= 1.41

  

+ Recommends:     python3-rust2rpm

+ 

  %description

  The package provides RPM macros for building Rust projects.

  
@@ -35,14 +36,13 @@ 

  %package     -n python3-rust2rpm

  Summary:        Generate RPM spec files for Rust packages

  BuildRequires:  python3-devel

- BuildRequires:  python3-setuptools

  %if %{with check}

  BuildRequires:  python3-pytest

  BuildRequires:  cargo

  %endif

  Requires:       cargo

  Provides:       rust2rpm = %{version}-%{release}

- %{?python_provide:%python_provide python3-rust2rpm}

+ Requires:       (rust-packaging = %{?epoch:%{epoch}:}%{version}-%{release} if rust-packaging)

  

  %description -n python3-rust2rpm

  %{summary}.
@@ -50,17 +50,21 @@ 

  %prep

  %autosetup -n rust2rpm-v%{version} -p1

  

+ %generate_buildrequires

+ %pyproject_buildrequires

+ 

  %build

- %py3_build

+ %pyproject_wheel

  

  %install

- %py3_install

+ %pyproject_install

+ %pyproject_save_files rust2rpm

  install -D -p -m 0644 -t %{buildroot}%{_rpmmacrodir} data/macros.rust data/macros.cargo

  install -D -p -m 0644 -t %{buildroot}%{_fileattrsdir} data/cargo.attr

  

  %if %{with check}

  %check

- py.test-%{python3_version} -vv test.py

+ %pytest -vv test.py

  %endif

  

  %files
@@ -68,14 +72,22 @@ 

  %{_rpmmacrodir}/macros.rust

  %{_rpmmacrodir}/macros.cargo

  %{_fileattrsdir}/cargo.attr

+ # the following Python files are co-owned with the full-blown python3-rust2rpm package

+ # they are needed for cargo.attr

+ %{_bindir}/cargo-inspector

+ %dir %{python3_sitelib}/rust2rpm

+ %pycached %{python3_sitelib}/rust2rpm/__init__.py

+ %pycached %{python3_sitelib}/rust2rpm/inspector.py

+ %pycached %{python3_sitelib}/rust2rpm/licensing.py

+ %pycached %{python3_sitelib}/rust2rpm/metadata.py

+ %{python3_sitelib}/rust2rpm/spdx_to_fedora.csv
  • %{python3_sitelib}/rust2rpm/spdx_to_fedora.csv

This looks iffy. It should only be required when generating new specs, and in fact it's not used anymore in git tip.

  

- %files -n python3-rust2rpm

- %license LICENSE

+ 

+ %files -n python3-rust2rpm -f %{pyproject_files}

  %doc NEWS

  %{_bindir}/rust2rpm

  %{_bindir}/cargo-inspector

- %{python3_sitelib}/rust2rpm-*.egg-info/

- %{python3_sitelib}/rust2rpm/

+ 

  

  %changelog

  %autochangelog

This avoids pulling the following to every Rust package buildroot:

  • python-jinja2
  • python-requests
  • python-tqdm

Thsi currently fails with:

<mock-chroot> sh-5.1$ cargo-inspector 
Traceback (most recent call last):
  File "/usr/bin/cargo-inspector", line 5, in <module>
    from rust2rpm.inspector import main
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/rust2rpm/inspector.py", line 8, in <module>
    from .__main__ import exit_on_common_errors
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'rust2rpm.__main__'

I believe importing from __main__ is a very bad thing to do. Do you have power to change that upstream? The exit_on_common_errors context manager is probably an overkill for cargo-inspector.

I've sent an email about this to the rust list.

Yeah, refactoring this so that the dependency generator only depends on python itself and python-toml has been on my to-do list. toml is available in the default buildroot, I think? But the other three listed (requests, jinja2, tqdm) should be droppable. I'll look into it.

Oh, I have not noticed toml. Should be doable to use tomllib from the standard library on Python 3.11+

I might misremember the toml dependency 😅

I believe importing from __main__ is a very bad thing to do. Do you have power to change that upstream? The exit_on_common_errors context manager is probably an overkill for cargo-inspector.

We are the upstream. We can easily refactor the code if appropriate.

I assumed upstream is Igor and hence dead.

  • %{python3_sitelib}/rust2rpm/spdx_to_fedora.csv

This looks iffy. It should only be required when generating new specs, and in fact it's not used anymore in git tip.

spdx_to_fedora.csv was added because __init__.py imports licensing.

That import could be try-expected, as the inspector module does not seem to need it.

I said I'll look into it. No need to hurry out a patch just to beat me to it ...

The just-hot-off-the-presses v22 of rust2rpm and this PR should address this issue:
https://src.fedoraproject.org/rpms/rust-packaging/pull-request/4

TL;DR: cargo-inspector was moved to a new python3-rust2rpm-core package that has zero dependencies on Python packages except for python3 itself.

Pull-Request has been closed by decathorpe

3 months ago

Looks like the v22 update and the package split had the intended effect:
https://koschei.fedoraproject.org/build/13287076

All these packages were dropped from the Rust buildroot:

  • python3-charset-normalize
  • python3-idna
  • python3-jinja2
  • python3-markupsafe
  • python3-pysocks
  • python3-requests
  • python3-rust2rpm
  • python3-six
  • python3-tqdm
  • python3-urllib3

And only one package was added:

  • python3-rust2rpm-core
Metadata