Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI #8

Merged
merged 1 commit into from
Sep 24, 2024
Merged

Add CLI #8

merged 1 commit into from
Sep 24, 2024

Conversation

mfocko
Copy link
Collaborator

@mfocko mfocko commented Feb 29, 2024

  • specfile needs to be adjusted

Related to #6

@mfocko mfocko self-assigned this Feb 29, 2024
Copy link
Member

@FrostyX FrostyX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the PR!

fedora_distro_aliases/cli.py Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
"console_scripts": [
'resolve-fedora-aliases = fedora_distro_aliases.cli:cli'
],
},
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update fedora-distro-aliases.spec as well and install the script?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect it to be taken from this 👀 isn't it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we both have been kinda wrong 😄

The script is automatically installed as you said but it still needs to be mentioned in the %files section:

error: Installed (but unpackaged) file(s) found:
   /usr/bin/resolve-fedora-aliases

RPM build errors:
    Installed (but unpackaged) file(s) found:
   /usr/bin/resolve-fedora-aliases

You can try tito build --rpm --test to reproduce this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect this:

%files -n python3-fedora-distro-aliases -f %{pyproject_files}

to cover the CLI script too… Python packaging can't be simple and straightforward, can it? smh my head

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way

error: Failed build dependencies:
        python3dist(wheel) is needed by fedora-distro-aliases-1.4-1.git.22.ed527ad.fc40.noarch
Wrote: /tmp/tito/fedora-distro-aliases-1.4-1.git.22.ed527ad.fc40.buildreqs.nosrc.rpm


ERROR: Error running command: rpmbuild   --eval '%undefine scl' --define "_topdir /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a" --define "_sourcedir /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/SOURCES" --define "_builddir /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD" --define "_srcrpmdir /tmp/tito" --define "_rpmdir /tmp/tito"   --clean  -ba /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/SOURCES/fedora-distro-aliases-git-22.ed527ad/fedora-distro-aliases.spec

Status code: 11

Command output: ['', 'setting SOURCE_DATE_EPOCH=1724112000', 'Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.zOAhVn', '+ umask 022', '+ cd /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD', '+ cd /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD', '+ rm -rf fedora-distro-aliases-git-22.ed527ad', '+ /usr/lib/rpm/rpmuncompress -x /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/SOURCES/fedora-distro-aliases-git-22.ed527ad.tar.gz', '+ STATUS=0', "+ '[' 0 -ne 0 ']'", '+ cd fedora-distro-aliases-git-22.ed527ad', '+ rm -rf /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD/fedora-distro-aliases-git-22.ed527ad-SPECPARTS', '+ /usr/bin/mkdir -p /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD/fedora-distro-aliases-git-22.ed527ad-SPECPARTS', '+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .', '+ RPM_EC=0', '++ jobs -p', '+ exit 0', 'Executing(%generate_buildrequires): /bin/sh -e /var/tmp/rpm-tmp.1AtIAD', '+ umask 022', '+ cd /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD', '+ cd fedora-distro-aliases-git-22.ed527ad', "+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer '", '+ export CFLAGS', "+ CXXFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer '", '+ export CXXFLAGS', "+ FFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -I/usr/lib64/gfortran/modules '", '+ export FFLAGS', "+ FCFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -I/usr/lib64/gfortran/modules '", '+ export FCFLAGS', '+ VALAFLAGS=-g', '+ export VALAFLAGS', "+ RUSTFLAGS='-Copt-level=3 -Cdebuginfo=2 -Ccodegen-units=1 -Cstrip=none -Cforce-frame-pointers=yes --cap-lints=warn'", '+ export RUSTFLAGS', "+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed  -Wl,-z,pack-relative-relocs -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1  '", '+ export LDFLAGS', '+ LT_SYS_LIBRARY_PATH=/usr/lib64:', '+ export LT_SYS_LIBRARY_PATH', '+ CC=gcc', '+ export CC', '+ CXX=g++', '+ export CXX', '+ echo pyproject-rpm-macros', '+ echo python3-devel', "+ echo 'python3dist(pip) >= 19'", "+ echo 'python3dist(packaging)'", "+ '[' -f pyproject.toml ']'", "+ '[' -f setup.py ']'", "+ echo 'python3dist(setuptools) >= 40.8'", "+ echo 'python3dist(wheel)'", "+ rm -rfv '*.dist-info/'", "+ '[' -f /usr/bin/python3 ']'", '+ mkdir -p /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD/.pyproject-builddir', '+ echo -n', "+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer '", "+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed  -Wl,-z,pack-relative-relocs -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1  '", '+ TMPDIR=/tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD/.pyproject-builddir', '+ RPM_TOXENV=py312', '+ HOSTNAME=rpmbuild', '+ /usr/bin/python3 -Bs /usr/lib/rpm/redhat/pyproject_buildrequires.py --generate-extras --python3_pkgversion 3 --wheeldir /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD/pyproject-wheeldir --output /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD/fedora-distro-aliases-1.4-1.git.22.ed527ad.fc40.x86_64-pyproject-buildrequires', 'Handling setuptools >= 40.8 from default build backend', 'Requirement satisfied: setuptools >= 40.8', '   (installed: setuptools 69.0.3)', 'Handling wheel from default build backend', 'Requirement not satisfied: wheel', 'Exiting dependency generation pass: build backend', '+ cat /tmp/tito/rpmbuild-fedora-distro-aliases6knwar5a/BUILD/fedora-distro-aliases-1.4-1.git.22.ed527ad.fc40.x86_64-pyproject-buildrequires', "+ rm -rfv '*.dist-info/'", '+ RPM_EC=0', '++ jobs -p', '+ exit 0', 'error: Failed build dependencies:', '\tpython3dist(wheel) is needed by fedora-distro-aliases-1.4-1.git.22.ed527ad.fc40.noarch', 'Wrote: /tmp/tito/fedora-distro-aliases-1.4-1.git.22.ed527ad.fc40.buildreqs.nosrc.rpm']

ERROR: Please run 'dnf builddep fedora-distro-aliases.spec' as root.

dnf builddep does nothing (as it appears to be already installed), what's going on 👀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You changed the %files so that it now produces two packages. Was this intended or an accident?

- /tmp/tito/noarch/python3-fedora-distro-aliases-1.4-1.git.5.67d613a.fc40.noarch.rpm
- /tmp/tito/noarch/fedora-distro-aliases-1.4-1.git.5.67d613a.fc40.noarch.rpm

I would do it this way

--- a/fedora-distro-aliases.spec
+++ b/fedora-distro-aliases.spec
@@ -49,12 +49,11 @@ Summary:        %{summary}
 %{python3} -m pytest -vv


-%files
-%{_bindir}/resolve-fedora-aliases
+%files -n python3-fedora-distro-aliases -f %{pyproject_files}
 %license LICENSES/GPL-2.0-or-later.txt
 %doc README.md
+%{_bindir}/resolve-fedora-aliases

-%files -n python3-fedora-distro-aliases -f %{pyproject_files}

 %changelog
 * Tue Aug 20 2024 Jakub Kadlcik <frostyx@email.cz> 1.4-1

to have everything in a single package. But if you prefer separate subpackages, that's okay too. But in that case, dependencies would have to be specified between those subpackages, etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll apply the suggestion, I thought it needs to be separated because of the arguments passed in the %files that was there before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, if you want to squash the small changes, let me know :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, if you want to squash the small changes, let me know :)

Yes please, everything into one commit. Then I am merging. Thank you very much :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@xsuchy
Copy link
Member

xsuchy commented Aug 1, 2024

@mfocko this is stalled for long time. Do you want to finish it?

@mfocko
Copy link
Collaborator Author

mfocko commented Aug 2, 2024

@mfocko this is stalled for long time. Do you want to finish it?

Adding it to TODO list, cause I totally forgot about that

print(" ".join(resolved_aliases))


def setup_parser() -> argparse.ArgumentParser:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this should allow you to generate manual pages for free:
$ argparse-manpage --pyfile fedora_distro_aliases/cli.py --function setup_parser > resolve-fedora-aliases.1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I noticed is that argparse ignores newlines, now that you mention the manpages, it feels like a bit poor decision on their end 🤔

Copy link
Member

@praiskup praiskup Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd create the manpage in a follow-up PR, as this has been open for some time already, would that be an issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No no, a follow-up PR is fine :-)
Thank you

Copy link
Member

@FrostyX FrostyX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the update @mfocko

"console_scripts": [
'resolve-fedora-aliases = fedora_distro_aliases.cli:cli'
],
},
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we both have been kinda wrong 😄

The script is automatically installed as you said but it still needs to be mentioned in the %files section:

error: Installed (but unpackaged) file(s) found:
   /usr/bin/resolve-fedora-aliases

RPM build errors:
    Installed (but unpackaged) file(s) found:
   /usr/bin/resolve-fedora-aliases

You can try tito build --rpm --test to reproduce this.


resolved_aliases: set[str] = set()
for alias in aliases:
resolved_aliases.update(getter(x) for x in distro_aliases[alias])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GETTERS seems redundant to me because you can do something like this here:

new = {getattr(x, output_type) for x in distro_aliases[alias]}
resolved_aliases.update(new)

but I don't mind either option.

@mfocko mfocko force-pushed the feat/gh-action branch 3 times, most recently from dc4afd8 to 9635ccc Compare September 24, 2024 12:01
Related to rpm-software-management#6

Co-authored-by: Jakub Kadlcik <frostyx@email.cz>
Signed-off-by: Matej Focko <mfocko@redhat.com>
@FrostyX FrostyX merged commit 00d9694 into rpm-software-management:main Sep 24, 2024
@praiskup
Copy link
Member

🎉

@mfocko mfocko deleted the feat/gh-action branch September 25, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants