Skip to content

Add pusimp

Francesco Ballarin requested to merge francesco/pusimp into experimental

Ready to review, but marked as draft until:

  1. python3-pusimp is available on CI
  2. we clarify whether --break-system-packages should be used on older ubuntu, or not

Dependencies which are currently checked

["dijitso", "ffc", "FIAT", "ufl_legacy", "ufl"]

Further dependencies (e.g. petsc4py) could be added in future if this first integration of pusimp goes well for end users.

See !4 (fc8bc67e) for the patch which adds pusimp, and https://github.com/python-pusimp/pusimp/blob/main/pusimp/prevent_user_site_imports.py#L13 for the signature of pusimp.prevent_user_site_imports.


Sample usage 1, tested on pytest: a user who has a local installation of a single dependency

Consider /tmp/tmppbxfyy_i as a mock $HOME/.local (or /usr/local) path, where the temporary directory is automatically generated by pytest.

ImportError: pusimp has detected the following problems with dolfin dependencies:
1) Dependencies imported from a local path rather than from the path provided by apt:
* ufl_legacy was imported from a local path: expected in /usr/lib/python3/dist-packages/ufl_legacy/__init__.py, but imported from /tmp/tmppbxfyy_i/venv/lib/python3.11/site-packages/ufl_legacy/__init__.py.

pusimp suggests to apply all of the following fixes:
1) To uninstall local dependencies:
* run 'pip uninstall --break-system-packages fenics-ufl-legacy' in a terminal, and verify that you are prompted to confirm removal of files in /tmp/tmppbxfyy_i/venv/lib/python3.11/site-packages/ufl_legacy. 

You can disable this check by exporting the DOLFIN_ALLOW_USER_SITE_IMPORTS environment variable. Note, however, that this may break the installation provided by apt.
If you believe that this message appears incorrectly, report this at https://fenicsproject.discourse.group/ .

Sample usage 2, tested on pytest: a user who has a local installation of more than one dependency

Note how all local dependencies are listed.

ImportError: pusimp has detected the following problems with dolfin dependencies:
1) Dependencies imported from a local path rather than from the path provided by apt:
* FIAT was imported from a local path: expected in /usr/lib/python3/dist-packages/FIAT/__init__.py, but imported from /tmp/tmpecf571c8/venv/lib/python3.11/site-packages/FIAT/__init__.py.
* ufl_legacy was imported from a local path: expected in /usr/lib/python3/dist-packages/ufl_legacy/__init__.py, but imported from /tmp/tmpecf571c8/venv/lib/python3.11/site-packages/ufl_legacy/__init__.py.

pusimp suggests to apply all of the following fixes:
1) To uninstall local dependencies:
* run 'pip uninstall --break-system-packages fenics-fiat' in a terminal, and verify that you are prompted to confirm removal of files in /tmp/tmpecf571c8/venv/lib/python3.11/site-packages/FIAT. 
* run 'pip uninstall --break-system-packages fenics-ufl-legacy' in a terminal, and verify that you are prompted to confirm removal of files in /tmp/tmpecf571c8/venv/lib/python3.11/site-packages/ufl_legacy. 

You can disable this check by exporting the DOLFIN_ALLOW_USER_SITE_IMPORTS environment variable. Note, however, that this may break the installation provided by apt.
If you believe that this message appears incorrectly, report this at https://fenicsproject.discourse.group/ .

Sample usage 3, tested on pytest: a user who has a local installation of ufl, even though dolfin switched to ufl-legacy

Note the extra text linking the announcement in discourse.

ImportError: pusimp has detected the following problems with dolfin dependencies:
1) Dependencies imported from a local path rather than from the path provided by apt:
* ufl was imported from a local path: expected in /usr/lib/python3/dist-packages/ufl/__init__.py, but imported from /tmp/tmp5d2jyzqq/venv/lib/python3.11/site-packages/ufl/__init__.py.

pusimp suggests to apply all of the following fixes:
1) To uninstall local dependencies:
* run 'pip uninstall --break-system-packages fenics-ufl' in a terminal, and verify that you are prompted to confirm removal of files in /tmp/tmp5d2jyzqq/venv/lib/python3.11/site-packages/ufl. Be aware that legacy dolfin codes must now import ufl_legacy instead of ufl, see https://fenicsproject.discourse.group/t/announcement-ufl-legacy-and-legacy-dolfin/11583 .

You can disable this check by exporting the DOLFIN_ALLOW_USER_SITE_IMPORTS environment variable. Note, however, that this may break the installation provided by apt.
If you believe that this message appears incorrectly, report this at https://fenicsproject.discourse.group/ .

Sample usage 4, tested on pytest: a user who has a broken local installation of a single dependency

Note how the suggestion is slightly different than usages 1-3

ImportError: pusimp has detected the following problems with dolfin dependencies:
1) Broken dependencies:
* ffc is broken. Error on import was 'ffc was purposely broken.'.

pusimp suggests to apply all of the following fixes:
1) To fix broken dependencies:
* run 'pip show fenics-ffc' in a terminal: if the location field is not /usr/lib/python3/dist-packages consider running 'pip uninstall --break-system-packages fenics-ffc' in a terminal, because the broken dependency is probably being imported from a local path rather than from the path provided by apt. 

You can disable this check by exporting the DOLFIN_ALLOW_USER_SITE_IMPORTS environment variable. Note, however, that this may break the installation provided by apt.
If you believe that this message appears incorrectly, report this at https://fenicsproject.discourse.group/ .

Sample usage 5, tested on pytest: a user who has a local installation of two dependencies, one of which is broken and in turns breaks the other one

ImportError: pusimp has detected the following problems with dolfin dependencies:
1) Broken dependencies:
* ffc is broken. Error on import was 'ufl_legacy was purposely broken.'.
* ufl_legacy is broken. Error on import was 'ufl_legacy was purposely broken.'.

pusimp suggests to apply all of the following fixes:
1) To fix broken dependencies:
* run 'pip show fenics-ffc' in a terminal: if the location field is not /usr/lib/python3/dist-packages consider running 'pip uninstall --break-system-packages fenics-ffc' in a terminal, because the broken dependency is probably being imported from a local path rather than from the path provided by apt. 
* run 'pip show fenics-ufl-legacy' in a terminal: if the location field is not /usr/lib/python3/dist-packages consider running 'pip uninstall --break-system-packages fenics-ufl-legacy' in a terminal, because the broken dependency is probably being imported from a local path rather than from the path provided by apt. 

You can disable this check by exporting the DOLFIN_ALLOW_USER_SITE_IMPORTS environment variable. Note, however, that this may break the installation provided by apt.
If you believe that this message appears incorrectly, report this at https://fenicsproject.discourse.group/ .

Sample usage 6, NOT tested on pytest: a user who pip installed a dependency with sudo

Cannot test this on pytest because I cannot mimick sudo, but the logic of pusimp does not depend on sudo. Note however that sudo is prepended to all suggestions, to make the user's life as easy as possible

ImportError: pusimp has detected the following problems with dolfin dependencies:
1) Dependencies imported from a local path rather than from the path provided by apt:
* FIAT was imported from a local path: expected in /usr/lib/python3/dist-packages/FIAT/__init__.py, but imported from /usr/local/lib/python3.11/dist-packages/FIAT/__init__.py.

pusimp suggests to apply all of the following fixes:
1) To uninstall local dependencies:
* run 'sudo pip uninstall --break-system-packages fenics-fiat' in a terminal, and verify that you are prompted to confirm removal of files in /usr/local/lib/python3.11/dist-packages/FIAT. 

You can disable this check by exporting the DOLFIN_ALLOW_USER_SITE_IMPORTS environment variable. Note, however, that this may break the installation provided by apt.
If you believe that this message appears incorrectly, report this at https://fenicsproject.discourse.group/ .

Sample usage 7, NOT tested on pytest: a user who pip installed a dependency with sudo and another one without sudo

Also this one cannot be added to pytest. sudo is added in front of the suggestions where appropriate.

ImportError: pusimp has detected the following problems with dolfin dependencies:
1) Dependencies imported from a local path rather than from the path provided by apt:
* dijitso was imported from a local path: expected in /usr/lib/python3/dist-packages/dijitso/__init__.py, but imported from /home/debian_developer/.local/lib/python3.11/site-packages/dijitso/__init__.py.
* FIAT was imported from a local path: expected in /usr/lib/python3/dist-packages/FIAT/__init__.py, but imported from /usr/local/lib/python3.11/dist-packages/FIAT/__init__.py.

pusimp suggests to apply all of the following fixes:
1) To uninstall local dependencies:
* run 'pip uninstall --break-system-packages fenics-dijitso' in a terminal, and verify that you are prompted to confirm removal of files in /home/debian_developer/.local/lib/python3.11/site-packages/dijitso. 
* run 'sudo pip uninstall --break-system-packages fenics-fiat' in a terminal, and verify that you are prompted to confirm removal of files in /usr/local/lib/python3.11/dist-packages/FIAT. 

You can disable this check by exporting the DOLFIN_ALLOW_USER_SITE_IMPORTS environment variable. Note, however, that this may break the installation provided by apt.
If you believe that this message appears incorrectly, report this at https://fenicsproject.discourse.group/ .

Sample usage 8, NOT tested on pytest: a user who messed up their installation with a mixture of working and broken local packages

Note how the list now includes an item 1) and an item 2). The logic behind this case is already tested in pusimp and it's basically the combination of the logic of the previous usages, so I didn't bother adding this case to the tests.

ImportError: pusimp has detected the following problems with dolfin dependencies:
1) Broken dependencies:
* ffc is broken. Error on import was 'No module named 'ufl''.
2) Dependencies imported from a local path rather than from the path provided by apt:
* FIAT was imported from a local path: expected in /usr/lib/python3/dist-packages/FIAT/__init__.py, but imported from /home/debian_developer/.local/lib/python3.11/site-packages/FIAT/__init__.py.

pusimp suggests to apply all of the following fixes:
1) To fix broken dependencies:
* run 'pip show fenics-ffc' in a terminal: if the location field is not /usr/lib/python3/dist-packages consider running 'pip uninstall --break-system-packages fenics-ffc' in a terminal, because the broken dependency is probably being imported from a local path rather than from the path provided by apt. 
2) To uninstall local dependencies:
* run 'pip uninstall --break-system-packages fenics-fiat' in a terminal, and verify that you are prompted to confirm removal of files in /home/debian_developer/.local/lib/python3.11/site-packages/FIAT. 

You can disable this check by exporting the DOLFIN_ALLOW_USER_SITE_IMPORTS environment variable. Note, however, that this may break the installation provided by apt.
If you believe that this message appears incorrectly, report this at https://fenicsproject.discourse.group/ .
Edited by Francesco Ballarin

Merge request reports

Loading