stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
107 stars 29 forks source link

Configuration file not found after installing with root privileges #997

Open arporter opened 4 years ago

arporter commented 4 years ago

During the tutorial there were two cases identified where we fail to find the installed PSyclone configuration file:

  1. PSyclone installed using root privileges under WSL2
  2. PSyclone installed in a Singularity container built with root privileges

In case 1., the config file is installed to /usr/local/share/psyclone/psyclone.cfg and PSyclone does not look there:

ConfigurationError: "PSyclone configuration error: psyclone.cfg not found in any of ['/mnt/c/Users/USERNAME/Projects/PSyclone/tutorial/notebooks/psyir/.psyclone', '/root/.local/share/psyclone', '/usr/share/psyclone']
arporter commented 4 years ago

@deardenchris I know you've played with containers. Have you used Singularity?

deardenchris commented 4 years ago

Hi Andy, yes I've used Singularity previously

arporter commented 4 years ago

I don't suppose you have a Singularity container handy that you could test the installation in do you?

deardenchris commented 4 years ago

I'd need a Singularity definition file that contains the build recipe - if such a thing exists for PSyclone, I should be able to test the installation

arporter commented 4 years ago

In the case of WSL2, it's definitely the use of root privileges that causes trouble. When I do this, psyclone is installed to /usr/local/bin and the config file is put in /usr/local/share/psyclone/ but the list of directories searched is:

[PWD, ~/.local/share/psyclone, /usr/share/psyclone]
arporter commented 4 years ago

If I startup python3 with sudo then I can see that sys.prefix is /usr. This matches with the list of directories being searched but not with where PSyclone has been installed.

arporter commented 4 years ago

Having googled, it seems there's no hard-and-fast rule as to where pip will install system-wide packages - it depends upon the Linux distribution. The simple solution in this particular case is therefore to add sys.prefix + /share to the list of searched locations. Alternatively, could we do what a lot of packages do and install the config file when PSyclone is run for the first time?

arporter commented 4 years ago

Obviously, to install it we'd need to be able to find it or create it. I can imagine that we could programmatically incorporate the src of the distributed config file within PSyclone somehow. Or maybe, we don't distribute the config file separately and change to having PSyclone 'generate' it?