Packaging with pip packages

Hello
I’m currently working on the new release of calibre-web.
Although I could just keep the package mainly the way it is, I noticed that calibreweb is now released as a pip package and I was wondering if there were any recommandations regarding the best way to do it for Yunohost:

  • Should I move to install it via pip? If yes, is there any “good practices” (regarding venv, target directory, etc.) ?
  • Or should I keep the “standard” install via github download and manually deal with all the dependencies and so on and stay maybe more aligned with the package philosophy?
  • Or in the end, it does not matter, I’m overthinking it and I can do whatever I want because I’m the king of my castle :crown: :european_castle: !?

Thanks for your feedback!

3 Likes

Their recommended practices are definitely sound. Virtual envs are needed to avoid conflicting with Python system packages.

Installation via pip (recommended)

  1. Create a virtual environment for Calibre-Web to avoid conflicts with existing Python dependencies
  2. Install Calibre-Web via pip: pip install calibreweb (or pip3 depending on your OS/distro)
  3. Install optional features via pip as needed, see this page for details
  4. Start Calibre-Web by typing cps

However I’m surprised, the current script already uses pip after downloading the sources:


You should find the balance between maintenance easiness and resources needed for install/upgrade for the end user. :innocent:

1 Like

Yes, pip is used to install the python dependencies, but the app itself is just downloaded from the github release assets.
However, since the last release, the maintainer does not release a tar.gz or zip archive as part of the assets anymore (except for the standard source code ones from github) and I was pondering which way to go as it was the occasion to switch.
So I think for now, as long as I can easily download the sources from github, I won’t go for the full pip install, it’s much easier for me!
Thanks for replying!

I would suggest to use pip-tools and create a requirements.txt with hashes and pinned version.

e.g.: GitHub - YunoHost-Apps/pyinventory_ynh: YunoHost app package for: https://github.com/jedie/PyInventory i store it into /conf/requirements.txt

My helper for this is:

myynh_setup_python_venv() {
    # Always recreate everything fresh with current python version
    ynh_secure_remove "$data_dir/venv"

    # Skip pip because of: https://github.com/YunoHost/issues/issues/1960
    python3 -m venv --without-pip "$data_dir/venv"

    chown -c -R "$app:" "$data_dir"

    # run source in a 'sub shell'
    (
        set +o nounset
        source "$data_dir/venv/bin/activate"
        set -o nounset
        set -x
        ynh_exec_as $app $data_dir/venv/bin/python3 -m ensurepip
        ynh_exec_as $app $data_dir/venv/bin/pip3 install --upgrade wheel pip setuptools
        ynh_exec_as $app $data_dir/venv/bin/pip3 install --no-deps -r "$data_dir/requirements.txt"
    )
}
1 Like

As a matter of fact, I think I already reused your code in my scripts :wink:

#Use venv to install pip requirements - Inspired from https://github.com/YunoHost-Apps/pyinventory_ynh/blob/master/scripts/install
ynh_script_progression --message="Installing pip requirements..." --weight=70
# Always recreate everything fresh with current python version
if [ -d "${install_dir}/venv" ] ; then
	ynh_secure_remove "${install_dir}/venv"
fi

# Skip pip because of: https://github.com/YunoHost/issues/issues/1960
python3 -m venv --without-pip "${install_dir}/venv"
chown -R "$app:" "$install_dir"

#run source in a 'sub shell'
(
	set +o nounset
	source "${install_dir}/venv/bin/activate"
	set -o nounset
	ynh_exec_as $app $install_dir/venv/bin/python3 -m ensurepip
	ynh_exec_as $app $install_dir/venv/bin/pip3 install --upgrade wheel pip setuptools
	ynh_exec_as $app $install_dir/venv/bin/pip3 install --no-cache-dir --upgrade -r "$install_dir/requirements.txt"
	ynh_exec_as $app $install_dir/venv/bin/pip3 install --no-cache-dir --upgrade -r "$install_dir/optional-requirements.txt"
)````