cms-sw / cmssw-osenv

Provides wrapper scripts to provide CMSSW env using singularity
0 stars 1 forks source link

Accessing aliases inside Singularity #5

Closed kpedro88 closed 2 years ago

kpedro88 commented 2 years ago

Aliases are limited in bash (and related shells). As far as I can tell, there is absolutely no way to make a construct like this "work":

sh -c 'source ../cmsset_default.sh; /bin/bash'

where "work" is defined to mean that everything, including aliases, is passed to the (interactive) subshell. (shopt -s expand_aliases is not effective in this case, because the alias is defined before the subshell exists.) This has become more noticeable since the switch to el8 as the production OS. Since many of us do not have el8 machines yet, we are more often using the el8 container interactively, whereas previously (at least for me) the main usage of CMSSW containers was for specific commands or batch jobs.

I could only find one way to get this to work solely by modifying cmssw-env in this repo: https://github.com/cms-sw/cmssw-osenv/compare/master...kpedro88:here-string-tty

However, this is a bit clunky, as it displays on the screen (and puts into the command history) the following:

[ "slc7_amd64" != "$(./cmsos)" ] && export SCRAM_ARCH=; source ./../cmsset_default.sh ; exec </dev/tty

There is an alternative: use functions instead of aliases (as most Bash experts seem to recommend in the modern era). With a few changes in cmsset_default.sh, everything works: https://github.com/cms-sw/cms-common/compare/master...kpedro88:use-function

Therefore, I propose changing cmsset_default.sh; please provide any feedback if there is a reason not to do so.

cmsbuild commented 2 years ago

A new Issue was created by @kpedro88 Kevin Pedro.

@Dr15Jones, @perrotta, @dpiparo, @makortel, @smuzaffar, @qliphy can you please review it and eventually sign/assign? Thanks.

cms-bot commands are listed here

smuzaffar commented 2 years ago

@kpedro88 , I had also looked in to this and I think defining functions for cmsrel and cmsenv is better soultion. cmsrel should allow to use input parameters e.g. it shoudl be something like

cmsrel(){ scramv1 project CMSSW $@; }
kpedro88 commented 2 years ago

@smuzaffar see https://github.com/cms-sw/cms-common/pull/4

smuzaffar commented 2 years ago

this has been deployed and working now

[muzaffar@lxplus]$ cmssw-el8
Singularity> cmsenv
SCRAM fatal: Unable to locate the top of local release. Please run this command from a SCRAM-based area.