jordansissel / fpm

Effing package management! Build packages for multiple platforms (deb, rpm, etc) with great ease and sanity.
http://fpm.readthedocs.io/en/latest/
Other
11.15k stars 1.07k forks source link

How to expose/install as executable an entrypoint from a virtualenv type RPM package #2030

Open John15321 opened 11 months ago

John15321 commented 11 months ago

I created an RPM package using fpm like this:

fpm --verbose -s virtualenv -t rpm -n dupa_cli -v 1.0 -p dupa_cli-1.0.rpm -m "Your Name <your@email.com>"  /root/dupa-cli/

The package is created without a problem, the pyproject:

[tool.poetry]
name = "dupa-cli"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"

[tool.poetry.scripts]
dupa-cli = 'dupa_cli.main:main' # this is the entry point as specified in Poetry documentation https://python-poetry.org/docs/pyproject/#scripts

[tool.poetry.dependencies]
python = "^3.11"
typer = {extras = ["all"], version = "^0.9.0"}

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

The package builds:

[root@7b13937f1d89 dupa-cli]# fpm --verbose -s virtualenv -t rpm -n dupa_cli -v 1.0 -p dupa_cli-1.0.rpm -m "Your Name <your@email.com>"  /root/dupa-cli/
Setting workdir {:workdir=>"/tmp", :level=>:info}
created virtual environment CPython3.11.6.final.0-64 in 207ms {:level=>:info}
  creator CPython3Posix(dest=/tmp/package-virtualenv-build-48a32fd649c2cb3b59346d9d8655be087ca0bfe0da4cfec21c58651281d0/usr/share/python/root/dupa-cli, clear=False, no_vcs_ignore=False, global=False) {:level=>:info}
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv) {:level=>:info}
    added seed packages: pip==23.2.1, setuptools==68.2.2, wheel==0.41.2 {:level=>:info}
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator {:level=>:info}
Looking in indexes: https://pypi.python.org/simple {:level=>:info}
Requirement already satisfied: pip in /tmp/package-virtualenv-build-48a32fd649c2cb3b59346d9d8655be087ca0bfe0da4cfec21c58651281d0/usr/share/python/root/dupa-cli/lib/python3.11/site-packages (23.2.1) {:level=>:info}
Collecting pip {:level=>:info}
  Obtaining dependency information for pip from https://files.pythonhosted.org/packages/e0/63/b428aaca15fcd98c39b07ca7149e24bc14205ad0f1c80ba2b01835aedde1/pip-23.3-py3-none-any.whl.metadata {:level=>:info}
  Using cached pip-23.3-py3-none-any.whl.metadata (3.5 kB) {:level=>:info}
Using cached pip-23.3-py3-none-any.whl (2.1 MB) {:level=>:info}
Installing collected packages: pip {:level=>:info}
  Attempting uninstall: pip {:level=>:info}
    Found existing installation: pip 23.2.1 {:level=>:info}
    Uninstalling pip-23.2.1: {:level=>:info}
      Successfully uninstalled pip-23.2.1 {:level=>:info}
Successfully installed pip-23.3 {:level=>:info}
Looking in indexes: https://pypi.python.org/simple {:level=>:info}
Processing /root/dupa-cli {:level=>:info}
  Installing build dependencies: started {:level=>:info}
  Installing build dependencies: finished with status 'done' {:level=>:info}
  Getting requirements to build wheel: started {:level=>:info}
  Getting requirements to build wheel: finished with status 'done' {:level=>:info}
  Preparing metadata (pyproject.toml): started {:level=>:info}
  Preparing metadata (pyproject.toml): finished with status 'done' {:level=>:info}
Collecting typer<0.10.0,>=0.9.0 (from typer[all]<0.10.0,>=0.9.0->dupa-cli==0.1.0) {:level=>:info}
  Using cached typer-0.9.0-py3-none-any.whl (45 kB) {:level=>:info}
Collecting click<9.0.0,>=7.1.1 (from typer<0.10.0,>=0.9.0->typer[all]<0.10.0,>=0.9.0->dupa-cli==0.1.0) {:level=>:info}
  Using cached click-8.1.7-py3-none-any.whl.metadata (3.0 kB) {:level=>:info}
Collecting typing-extensions>=3.7.4.3 (from typer<0.10.0,>=0.9.0->typer[all]<0.10.0,>=0.9.0->dupa-cli==0.1.0) {:level=>:info}
  Using cached typing_extensions-4.8.0-py3-none-any.whl.metadata (3.0 kB) {:level=>:info}
Collecting colorama<0.5.0,>=0.4.3 (from typer[all]<0.10.0,>=0.9.0->dupa-cli==0.1.0) {:level=>:info}
  Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB) {:level=>:info}
Collecting shellingham<2.0.0,>=1.3.0 (from typer[all]<0.10.0,>=0.9.0->dupa-cli==0.1.0) {:level=>:info}
  Using cached shellingham-1.5.3-py2.py3-none-any.whl.metadata (3.4 kB) {:level=>:info}
Collecting rich<14.0.0,>=10.11.0 (from typer[all]<0.10.0,>=0.9.0->dupa-cli==0.1.0) {:level=>:info}
  Using cached rich-13.6.0-py3-none-any.whl.metadata (18 kB) {:level=>:info}
Collecting markdown-it-py>=2.2.0 (from rich<14.0.0,>=10.11.0->typer[all]<0.10.0,>=0.9.0->dupa-cli==0.1.0) {:level=>:info}
  Using cached markdown_it_py-3.0.0-py3-none-any.whl.metadata (6.9 kB) {:level=>:info}
Collecting pygments<3.0.0,>=2.13.0 (from rich<14.0.0,>=10.11.0->typer[all]<0.10.0,>=0.9.0->dupa-cli==0.1.0) {:level=>:info}
  Using cached Pygments-2.16.1-py3-none-any.whl.metadata (2.5 kB) {:level=>:info}
Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich<14.0.0,>=10.11.0->typer[all]<0.10.0,>=0.9.0->dupa-cli==0.1.0) {:level=>:info}
  Using cached mdurl-0.1.2-py3-none-any.whl (10.0 kB) {:level=>:info}
Using cached click-8.1.7-py3-none-any.whl (97 kB) {:level=>:info}
Using cached rich-13.6.0-py3-none-any.whl (239 kB) {:level=>:info}
Using cached shellingham-1.5.3-py2.py3-none-any.whl (9.7 kB) {:level=>:info}
Using cached typing_extensions-4.8.0-py3-none-any.whl (31 kB) {:level=>:info}
Using cached markdown_it_py-3.0.0-py3-none-any.whl (87 kB) {:level=>:info}
Using cached Pygments-2.16.1-py3-none-any.whl (1.2 MB) {:level=>:info}
Building wheels for collected packages: dupa-cli {:level=>:info}
  Building wheel for dupa-cli (pyproject.toml): started {:level=>:info}
  Building wheel for dupa-cli (pyproject.toml): finished with status 'done' {:level=>:info}
  Created wheel for dupa-cli: filename=dupa_cli-0.1.0-py3-none-any.whl size=1635 sha256=54cecceeb181e0381c12aacd83bdd18cf76fd34ffbdfbb2d63a736e21f2c35ab {:level=>:info}
  Stored in directory: /root/.cache/pip/wheels/77/a8/aa/d22c29df4b55d9d6ba3bc6dd47b4c8780ce5c92fac30a06d2d {:level=>:info}
Successfully built dupa-cli {:level=>:info}
Installing collected packages: typing-extensions, shellingham, pygments, mdurl, colorama, click, typer, markdown-it-py, rich, dupa-cli {:level=>:info}
Successfully installed click-8.1.7 colorama-0.4.6 dupa-cli-0.1.0 markdown-it-py-3.0.0 mdurl-0.1.2 pygments-2.16.1 rich-13.6.0 shellingham-1.5.3 typer-0.9.0 typing-extensions-4.8.0 {:level=>:info}
Updated: . (/tmp/package-virtualenv-build-48a32fd649c2cb3b59346d9d8655be087ca0bfe0da4cfec21c58651281d0/usr/share/python/root/dupa-cli -> /usr/share/python/root/dupa-cli/) {:level=>:info}
Converting virtualenv to dir {:level=>:info}
Setting from flags: epoch= {:level=>:info}
Setting from flags: iteration= {:level=>:info}
Setting from flags: maintainer=Your Name <your@email.com> {:level=>:info}
Setting from flags: name=dupa_cli {:level=>:info}
Setting from flags: url=http://example.com/no-uri-given {:level=>:info}
Setting from flags: version=1.0 {:level=>:info}
Converting virtualenv to rpm {:level=>:info}
Reading template {:path=>"/usr/local/share/gems/gems/fpm-1.15.1/templates/rpm.erb", :level=>:info}
Running rpmbuild {:args=>["rpmbuild", "-bb", "--define", "buildroot /tmp/package-rpm-build-f6d572a018515e7a4b313715302c86c1044a3a08d18633983233bb8cb26d/BUILD", "--define", "_topdir /tmp/package-rpm-build-f6d572a018515e7a4b313715302c86c1044a3a08d18633983233bb8cb26d", "--define", "_sourcedir /tmp/package-rpm-build-f6d572a018515e7a4b313715302c86c1044a3a08d18633983233bb8cb26d", "--define", "_rpmdir /tmp/package-rpm-build-f6d572a018515e7a4b313715302c86c1044a3a08d18633983233bb8cb26d/RPMS", "--define", "_tmppath /tmp", "/tmp/package-rpm-build-f6d572a018515e7a4b313715302c86c1044a3a08d18633983233bb8cb26d/SPECS/dupa_cli.spec"], :level=>:info}
warning: Macro expanded in comment on line 24: %undefine __check_files {:level=>:info}
 {:level=>:info}
warning: source_date_epoch_from_changelog set but %changelog is missing {:level=>:info}
Executing(%prep): /bin/sh -e /tmp/rpm-tmp.PAQmMX {:level=>:info}
Executing(%build): /bin/sh -e /tmp/rpm-tmp.noAq8R {:level=>:info}
Executing(%install): /bin/sh -e /tmp/rpm-tmp.OH6qDf {:level=>:info}
Processing files: dupa_cli-1.0-1.aarch64 {:level=>:info}
warning: absolute symlink: /usr/share/python/root/dupa-cli/bin/python -> /usr/bin/python3 {:level=>:info}
Provides: dupa_cli = 1.0-1 dupa_cli(aarch-64) = 1.0-1 {:level=>:info}
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 {:level=>:info}
Wrote: /tmp/package-rpm-build-f6d572a018515e7a4b313715302c86c1044a3a08d18633983233bb8cb26d/RPMS/aarch64/dupa_cli-1.0-1.aarch64.rpm {:level=>:info}
Executing(%clean): /bin/sh -e /tmp/rpm-tmp.dL1GYc {:level=>:info}
Executing(rmbuild): /bin/sh -e /tmp/rpm-tmp.KBxp2a {:level=>:info}
 {:level=>:info}
    Macro expanded in comment on line 24: %undefine __check_files {:level=>:info}
RPM build warnings: {:level=>:info}
 {:level=>:info}
    source_date_epoch_from_changelog set but %changelog is missing {:level=>:info}
    absolute symlink: /usr/share/python/root/dupa-cli/bin/python -> /usr/bin/python3 {:level=>:info}
Created package {:path=>"dupa_cli-1.0.rpm"}

After installation the package is visible and also present in /usr/share...:

[root@7b13937f1d89 dupa-cli]# rpm -i dupa_cli-1.0.rpm
[root@7b13937f1d89 dupa-cli]# rpm -qa | grep dupa
dupa_cli-1.0-1.aarch64

But although the python pyproject.toml specifies an entry point, the entrypoitn is nowhere to be seen:

[root@7b13937f1d89 dupa-cli]# rpm -i dupa_cli-1.0.rpm
[root@7b13937f1d89 dupa-cli]# rpm -qa | grep dupa
dupa_cli-1.0-1.aarch64
[root@7b13937f1d89 dupa-cli]# dupa-cli
bash: /usr/bin/dupa-cli: No such file or directory
[root@7b13937f1d89 dupa-cli]# dupa_cli
bash: dupa_cli: command not found

The files are present in /usr/share/python/root/dupa-cli/:

[root@7b13937f1d89 dupa-cli]# ls -la
total 28
drwxr-xr-x 5 root root 4096 Oct 17 14:18 .
drwxr-xr-x 3 root root 4096 Oct 17 11:51 ..
-rw-r--r-- 1 root root   40 Oct 17 14:18 .gitignore
drwxr-xr-x 2 root root 4096 Oct 17 14:18 bin
drwxr-xr-x 3 root root 4096 Oct 17 11:51 lib
drwxr-xr-x 3 root root 4096 Oct 17 11:51 lib64
-rw-r--r-- 1 root root  207 Oct 17 14:18 pyvenv.cfg
[root@7b13937f1d89 dupa-cli]# cat pyvenv.cfg 
home = /usr/bin
implementation = CPython
version_info = 3.11.6.final.0
virtualenv = 20.24.5
include-system-site-packages = false
base-prefix = /usr
base-exec-prefix = /usr
base-executable = /usr/bin/python3
[root@7b13937f1d89 dupa-cli]# cd bin/
[root@7b13937f1d89 bin]# ls -la
total 72
drwxr-xr-x 2 root root 4096 Oct 17 14:18 .
drwxr-xr-x 5 root root 4096 Oct 17 14:18 ..
-rw-r--r-- 1 root root 2236 Oct 17 14:18 activate
-rw-r--r-- 1 root root 1503 Oct 17 14:18 activate.csh
-rw-r--r-- 1 root root 3066 Oct 17 14:18 activate.fish
-rw-r--r-- 1 root root 2840 Oct 17 14:18 activate.nu
-rw-r--r-- 1 root root 1650 Oct 17 14:18 activate.ps1
-rw-r--r-- 1 root root 1371 Oct 17 14:18 activate_this.py
-rwxr-xr-x 1 root root  271 Oct 17 14:18 dupa-cli
-rwxr-xr-x 1 root root  279 Oct 17 14:18 markdown-it
-rwxr-xr-x 1 root root  280 Oct 17 14:18 pip
-rwxr-xr-x 1 root root  280 Oct 17 14:18 pip3
-rwxr-xr-x 1 root root  280 Oct 17 14:18 pip3.11
-rwxr-xr-x 1 root root  274 Oct 17 14:18 pygmentize
lrwxrwxrwx 1 root root   16 Oct 17 14:18 python -> /usr/bin/python3
lrwxrwxrwx 1 root root    6 Oct 17 14:18 python3 -> python
lrwxrwxrwx 1 root root    6 Oct 17 14:18 python3.11 -> python
-rwxr-xr-x 1 root root  267 Oct 17 14:18 wheel
-rwxr-xr-x 1 root root  267 Oct 17 14:18 wheel-3.11
-rwxr-xr-x 1 root root  267 Oct 17 14:18 wheel3
-rwxr-xr-x 1 root root  267 Oct 17 14:18 wheel3.11

Executed with an absolute path it works:

[root@7b13937f1d89 bin]# /usr/share/python/root/dupa-cli/bin/dupa-cli --help

 Usage: dupa-cli [OPTIONS] COMMAND [ARGS]...                                                                              

╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --install-completion          Install completion for the current shell.                                                │
│ --show-completion             Show completion for the current shell, to copy it or customize the installation.         │
│ --help                        Show this message and exit.                                                              │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ bye                                                                                                                    │
│ hello                                                                                                                  │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

How can I/should I make it a normal executable from the perspective of the system?