dguest / pandamonium

Command line scripts to parse panda web api
BSD 3-Clause "New" or "Revised" License
27 stars 17 forks source link

pandamon breaks after setting up athena release? #48

Closed jburzy01 closed 3 years ago

jburzy01 commented 3 years ago

I'm running pandamon on lxplus via the virtualenv described in the README. It works fine out of the box, but if I have set up an AnalysisBase release I get

Traceback (most recent call last):
  File "/afs/cern.ch/user/j/jburzyns/.venvs/base/bin/pandamon", line 7, in <module>
    from pandamonium.pandamon import main
ImportError: No module named pandamonium.pandamon

Has anyone else encountered this or have any thoughts on how to fix it?

matthewfeickert commented 3 years ago

Thanks for the Issue @jburzy01. What you are describing is an issue with how HEP software abuses the PYTHONPATH environment variable.

If you just do something on LXPLUS like setup a reasonable LCG view for Python 3

$ unset PYTHONPATH
$ lsetup 'views LCG_98python3 x86_64-centos7-gcc8-opt'
************************************************************************
Requested:  views ... 
 Setting up views LCG_98python3:x86_64-centos7-gcc8-opt ... 
>>>>>>>>>>>>>>>>>>>>>>>>> Information for user <<<<<<<<<<<<<<<<<<<<<<<<<
************************************************************************
$ echo $PYTHONPATH
/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages

you see that you already have a problem because LCG is now going to have control over site-packages and so will pollute your environment, making your virtual environment no longer guaranteed to be safe.

If for example you safeguard your virtual environment at login with something like the following in your .bashrc

# Setup default LCG view
default_LCG_release="LCG_98python3"
default_LCG_platform="x86_64-centos7-gcc8-opt"
printf "\nlsetup 'views ${default_LCG_release} ${default_LCG_platform}'\n"
lsetup "views ${default_LCG_release} ${default_LCG_platform}"
# strip out LGG view site-packages from PYTHONPATH to allow venv control of pip
IFS=':' read -ra _LCG_paths <<< "${PYTHONPATH}"
for idx in "${!_LCG_paths[@]}"
do
    [[ "${_LCG_paths[$idx]}" == *"site-packages"* ]] && unset -v "_LCG_paths[${idx}]"
done
export PYTHONPATH=$(IFS=:; echo "${_LCG_paths[*]}")

then your default login will now give your virtual environments full control over themselves (note no site-packages in PYTHONPATH now)

$ echo $PYTHONPATH
/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/lib

As an explicit example, if we start with this sort of .bashrc guarding and then make a new virtual environment, everything is fine

$ cd $HOME
$ python -m venv example
(example) $ . example/bin/activate
(example) $ echo $PYTHONPATH
/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/lib
(example) $ python -m pip install --quiet --upgrade pip setuptools wheel
(example) $ python -m pip install --quiet pandamonium
(example) $ pip show pandamonium # We see that pandamonium lives in our virtual environment's site-packages
Name: pandamonium
Version: 0.2.1
Summary: Command line library to parse the Panda web API
Home-page: https://github.com/dguest/pandamonium
Author: Dan Guest, Matthew Feickert
Author-email: daniel.hay.guest@cern.ch, matthew.feickert@cern.ch
License: BSD 3-Clause
Location: /home/feickert/example/lib/python3.7/site-packages
Requires: panda-client
Required-by: 
(example) $ pip list
Package      Version
------------ -------
panda-client 1.4.45
pandamonium  0.2.1
pip          20.3.3
pyspark      2.4.6
setuptools   51.1.1
wheel        0.36.2
(example) $ python -m pip list | wc -l
8

However, if we just setup a new LCG view it will prepend /cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages to PYTHONPATH which means that is the first site-packages that will be found by your shell and so your virtual environment is effectively destroyed, as LCG views are forms of virtual environments of their own.

(example) $ lsetup 'views LCG_98python3 x86_64-centos7-gcc8-opt'
************************************************************************
Requested:  views ... 
 Setting up views LCG_98python3:x86_64-centos7-gcc8-opt ... 
>>>>>>>>>>>>>>>>>>>>>>>>> Information for user <<<<<<<<<<<<<<<<<<<<<<<<<
************************************************************************
(example) $ echo $PYTHONPATH
/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages:/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/lib
(example) $ python -m pip list | grep pandamonium
(example) $ python -m pip list | wc -l # Note this was previously 8
280

Anytime you setup an ATLAS software release you will be doing the same sort of thing as it is setting up specific views that trash PYTHONPATH. In general, this is totally horrible and should never be done, but HEP has decided this is how we are going to do things.

To get access to your installed libraries in your virtual environment you'll need to update the shell environment again by deactivating and activating the virtual environment again, but as you can see the LCG view is still there polluting it.

(example) $ deactivate 
$ . example/bin/activate
(example) $ python -m pip list | grep pandamonium
pandamonium                        0.2.1           
(example) $ python -m pip list | wc -l
282

I realize that so far I've just reshown you your problem. In general, there is no "solution" to your problem as if you are trying to use an interactive shell you need to choose one and only one environment that you will work in for that shell. If you want to be able to fluidly switch between environments and LCG views then I would recommend (what I do) exclusively running all ATLAS code in subshells so that is can never pollute my interactive environment (so never source anything in your interactive shell but just write a short script and then bash your_shell_script.sh).

If this is not reasonable for you then I think you might need to install pandamonium like @dguest does by cloning the repo and then putting the shell scripts in PATH, which should be a bit more safe from the radical shell environment changes that ATLAS software imposes.

I'm not sure if this is helpful at all, so please let us know if you have follow up questions here.

dguest commented 3 years ago

Hi @jburzy01!

I think the easiest solution is to follow the "oldschool" instructions (just stuffing this package into your PATH). I'm very happy that @matthewfeickert put in the effort to make this package work properly with pip, but unfortunately this isn't how most ATLAS software is designed. Unfortunately that might mean we're stuck with the same slightly hacky solution that the rest of ATLAS uses.

I was hoping to deprecate the "old way" of installing this package, but if this is the only way some people can get it working I guess we might need to keep it around until everyone else in hep cleans up their code (I'm not holding my breath...)

dantrim commented 3 years ago

If we define an entry point in the setup.py, will that cure this? As far as I can tell, it just points to a specific executable file path.

matthewfeickert commented 3 years ago

If we define an entry point in the setup.py, will that cure this? As far as I can tell, it just points to a specific executable file path.

I don't think so, given that we already define entry points in setup.cfg

https://github.com/dguest/pandamonium/blob/d6457c8f302d949d732968cf8641a8d13146113b/setup.cfg#L47-L53

dantrim commented 3 years ago

Ah, I did not look in setup.cfg. 👍

dguest commented 3 years ago

@jburzy01, does this solve your problem? Can you let us know what you ended up doing?

jburzy01 commented 3 years ago

Thanks for your help everyone! The easiest solution in the end was to revert to the old way of doing things. I'll close the issue for now.

matthewfeickert commented 2 years ago

This might be effectively fixed with use of https://github.com/matthewfeickert/cvmfs-venv.

matthewfeickert commented 2 years ago

@dguest This isn't too bad actually. Maybe I should spend some time making a not terrible https://github.com/matthewfeickert/cvmfs-venv CLI :thinking:

Example: ```console $ ssh lxplus [feickert@lxplus778 ~]$ curl -sLO https://raw.githubusercontent.com/matthewfeickert/cvmfs-venv/d3d6b3e30b942a00fc64ebab2acc4ec6f621c339/atlas_setup.sh [feickert@lxplus778 ~]$ . atlas_setup.sh pandamonium lsetup 'views LCG_101 x86_64-centos7-gcc10-opt' ************************************************************************ Requested: views ... Setting up views LCG_101:x86_64-centos7-gcc10-opt ... >>>>>>>>>>>>>>>>>>>>>>>>> Information for user <<<<<<<<<<<<<<<<<<<<<<<<< ************************************************************************ # Creating new Python virtual environment 'pandamonium' (pandamonium) [feickert@lxplus778 ~]$ command -v python /afs/cern.ch/user/f/feickert/pandamonium/bin/python (pandamonium) [feickert@lxplus778 ~]$ python --version --version Python 3.9.6 (default, Sep 6 2021, 15:35:00) [GCC 10.3.0] (pandamonium) [feickert@lxplus778 ~]$ python -m pip install --upgrade pandamonium Collecting pandamonium Downloading pandamonium-0.3.0-py2.py3-none-any.whl (13 kB) Collecting panda-client>=1.0 Downloading panda-client-1.5.6.tar.gz (203 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 203.4/203.4 KB 3.6 MB/s eta 0:00:00 Preparing metadata (setup.py) ... done Building wheels for collected packages: panda-client Building wheel for panda-client (setup.py) ... done Created wheel for panda-client: filename=panda_client-1.5.6-py2.py3-none-any.whl size=156889 sha256=f1a52174911b07e8e703cc2700d054822e5a35903e4a32bee3769cdc1aaaa454 Stored in directory: /afs/cern.ch/user/f/feickert/.cache/pip/wheels/60/e2/c9/5f715e2b3986f7ca8b64d69c16f5fc4b4c518ea79efeed0200 Successfully built panda-client Installing collected packages: panda-client, pandamonium Successfully installed panda-client-1.5.6 pandamonium-0.3.0 (pandamonium) [feickert@lxplus778 ~]$ python -m pip show pandamonium Name: pandamonium Version: 0.3.0 Summary: Command line library to parse the Panda web API Home-page: https://github.com/dguest/pandamonium Author: Dan Guest, Matthew Feickert Author-email: daniel.hay.guest@cern.ch, matthew.feickert@cern.ch License: BSD 3-Clause Location: /afs/cern.ch/user/f/feickert/pandamonium/lib/python3.9/site-packages Requires: panda-client Required-by: (pandamonium) [feickert@lxplus778 ~]$ voms-proxy-init -voms atlas # note: not needed for pandamon Enter GRID pass phrase for this identity: Contacting voms2.cern.ch:15001 [/DC=ch/DC=cern/OU=computers/CN=voms2.cern.ch] "atlas"... Remote VOMS server contacted succesfully. Created proxy in /tmp/x509up_u50892. Your proxy is valid until Thu Feb 24 10:57:44 CET 2022 (pandamonium) [feickert@lxplus778 ~]$ lsetup rucio # note: note needed for pandamon ************************************************************************ Requested: rucio ... Setting up emi 4.0.2-1_200423.fix4a ... Skipping: grid middleware already setup (from UI) Setting up rucio 1.25.5.post1 ... Info: Setting compatibility to centos7 Setting up xrootd 5.4.0-x86_64-centos7 ... >>>>>>>>>>>>>>>>>>>>>>>>> Information for user <<<<<<<<<<<<<<<<<<<<<<<<< emi: Warning: current gcc version (gcc1030) is older than needed for emi (gcc48) emi: Your proxy has 11h:59m:27s remaining ************************************************************************ (pandamonium) [feickert@lxplus778 ~]$ pandamon user.dguest --days 200 --more-info done 27433539 12362 100% 0% user.dguest.800036.e7914_s3126_d1677_r12711.trigger_wp.2021-11-13T2101.r12684_r12782.v0-73-gba9dfd8/ done 27433538 12357 100% 0% user.dguest.364704.e7142_s3126_d1677_r12711.trigger_wp.2021-11-13T2101.r12684_r12782.v0-73-gba9dfd8/ done 27433537 12359 100% 0% user.dguest.410470.e6337_e5984_s3126_d1677_r12711.trigger_wp.2021-11-13T2101.r12684_r12782.v0-73-gba9dfd8/ done 27433536 12360 100% 0% user.dguest.364702.e7142_s3126_d1677_r12711.trigger_wp.2021-11-13T2101.r12684_r12782.v0-73-gba9dfd8/ done 27433535 12361 100% 0% user.dguest.427080.e5362_e5984_s3126_d1677_r12711.trigger_wp.2021-11-13T2101.r12684_r12782.v0-73-gba9dfd8/ finished 27433534 12358 100% 0% user.dguest.364703.e7142_s3126_d1677_r12711.trigger_wp.2021-11-13T2101.r12684_r12782.v0-73-gba9dfd8/ finished 27097524 12294 99% 1% user.dguest.364704.e7142_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-41-gb0d9a95.r1/ done 27070331 11807 100% 0% user.dguest.427080.e5362_e5984_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-41-gb0d9a95/ broken 27070330 11808 0% 1% user.dguest.364704.e7142_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-41-gb0d9a95/ done 27070329 11803 100% 0% user.dguest.364702.e7142_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-41-gb0d9a95/ finished 27070328 11806 100% 0% user.dguest.410470.e6337_e5984_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-41-gb0d9a95/ finished 27070327 11804 90% 10% user.dguest.364703.e7142_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-41-gb0d9a95/ done 27070326 11805 100% 0% user.dguest.800036.e7914_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-41-gb0d9a95/ done 27068790 11790 100% 0% user.dguest.410470.e6337_e5984_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-40-gca24e61/ done 27068789 11789 100% 0% user.dguest.364703.e7142_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-40-gca24e61/ done 27068787 11786 100% 0% user.dguest.364702.e7142_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-40-gca24e61/ done 27068786 11788 100% 0% user.dguest.427080.e5362_e5984_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-40-gca24e61/ done 27068785 11787 100% 0% user.dguest.364704.e7142_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-40-gca24e61/ done 27068784 11785 100% 0% user.dguest.800036.e7914_s3126_d1677_r12711.trigger.2021-10-05T2101.r12684_r12782.v0-40-gca24e61/ done 26421989 11720 100% 0% user.dguest.427080.e5362_e5984_s3126_d1677_r12711.trigger.2021-08-01T2101.r12684_r12782.v0-27-gd31cd40/ done 26421988 11719 100% 0% user.dguest.410470.e6337_e5984_s3126_d1677_r12711.trigger.2021-08-01T2101.r12684_r12782.v0-27-gd31cd40/ (pandamonium) [feickert@lxplus778 ~]$ command -v pandamon # pandamon lives inside of virtual environment /afs/cern.ch/user/f/feickert/pandamonium/bin/pandamon (pandamonium) [feickert@lxplus778 ~]$ deactivate # deactivate virtual environment [feickert@lxplus778 ~]$ command -v pandamon # no command found as inside of virtual environment ```
Just the commands: ``` curl -sLO https://raw.githubusercontent.com/matthewfeickert/cvmfs-venv/d3d6b3e30b942a00fc64ebab2acc4ec6f621c339/atlas_setup.sh . atlas_setup.sh pandamonium command -v python python --version --version python -m pip install --upgrade pandamonium python -m pip show pandamonium voms-proxy-init -voms atlas lsetup rucio pandamon user.dguest --days 200 --more-info command -v pandamon deactivate command -v pandamon ```