Move Python virtalenv out of $data_dir?

Currently i move the default directory from: $data_dir/venv to $data_dir/.venv
(e.g.: master <- testing by jedie · Pull Request #77 · YunoHost-Apps/django-for-runners_ynh · GitHub )

This destination or ${install_dir}/venv is quite common, isn’t it?

But maybe it should be complete out of $data_dir / ${install_dir} ?

Because it will be backup by ynh_backup "$data_dir" and restored by ynh_restore "$data_dir"

But i will be always recreated, because reuse a existing venv may result in a broken state.
So it’s useless to put it into the backup archive, isn’t it?

Yes.

On the postulate that $install_dir is for the binairies, dependencies, and basically all the software side of an app, IMHO the Python virtual environment should be out of $data_dir and in $install_dir/(.)venv.

That is very interesting, tell me more, please. :slight_smile:
I only foresee a change of server architecture that could break a virtual environment, are there any other cases?

Yes it breaks if arch changed, but also if major python version changed.

This is the reason why i add --clear to the python -m venv call. I will just remove the whole venv directory structure. So it’s also useless to backup/restore it.

Maybe a solution is also if we can exclude stuff from ynh_backup ?
e.g.: .venv and __pycache__ etc.

But there is currently no way to do this, isn’t it?

Maybe we can add something like .gitignore ? Or just arguments to ynh_backup call…

The utility is that builing a venv may take time, especially if some dependencies happen to be built locally, and most of the time the backup/restore happens on the same arch, so it’s totally reusable.

Good point.

Maybe i should implement this:

  1. Try to reuse a existing venv
  2. If this doesn’t work: Recreate it

EDIT: Try to reuse existing venv and use pip-sync to install requirements.txt by jedie · Pull Request #79 · YunoHost-Apps/django-for-runners_ynh · GitHub

Seems to work. I will change all my projects in this way…

1 Like