cthoyt / pystow

👜 Easily pick a place to store data for your Python code.
https://pystow.readthedocs.io
MIT License
36 stars 6 forks source link

Improve permission error text #64

Closed cthoyt closed 1 year ago

cthoyt commented 1 year ago

I was sent the following traceback which seems to correspond to someone who is using the Bioregistry, which has PyStow as a transitive dependency. They call code that invokes the Bioregistry, which imports PyStow and tries to create a README file in its default folder. However, the default folder is created in the home directory of the server, which is /var/www, and this user doesn't have permission to write in that folder.

Therefore, the solution is to change the PyStow configuration to overwrite the default location and pick somewhere where the user has write privileges. Changing the default Pystow location can be done by following instructions here: https://pystow.readthedocs.io/en/latest/installation.html#configuration

Traceback (most recent call last): File "signorValidator.py", line 5, in #import bioregistry File "/usr/local/lib/python3.8/dist-packages/bioregistry/__init__.py", line 5, in from .collection_api import get_collection, get_context # noqa:F401 File "/usr/local/lib/python3.8/dist-packages/bioregistry/collection_api.py", line 7, in from .resource_manager import manager File "/usr/local/lib/python3.8/dist-packages/bioregistry/resource_manager.py", line 27, in from .constants import ( File "/usr/local/lib/python3.8/dist-packages/bioregistry/constants.py", line 10, in import pystow File "/usr/local/lib/python3.8/dist-packages/pystow/__init__.py", line 53, in ensure_readme() File "/usr/local/lib/python3.8/dist-packages/pystow/utils.py", line 1010, in ensure_readme readme_path = get_home(ensure_exists=True).joinpath("README.md") File "/usr/local/lib/python3.8/dist-packages/pystow/utils.py", line 978, in get_home return getenv_path(PYSTOW_HOME_ENVVAR, default, ensure_exists=ensure_exists) File "/usr/local/lib/python3.8/dist-packages/pystow/utils.py", line 475, in getenv_path mkdir(rv, ensure_exists=ensure_exists) File "/usr/local/lib/python3.8/dist-packages/pystow/utils.py", line 433, in mkdir path.mkdir(exist_ok=True, parents=True) File "/usr/lib/python3.8/pathlib.py", line 1288, in mkdir self._accessor.mkdir(self, mode) PermissionError: [Errno 13] Permission denied: '/var/www/.data'
codecov-commenter commented 1 year ago

Codecov Report

Merging #64 (15e0a64) into main (eecf60f) will decrease coverage by 0.11%. The diff coverage is 50.00%.

@@            Coverage Diff             @@
##             main      #64      +/-   ##
==========================================
- Coverage   66.80%   66.70%   -0.11%     
==========================================
  Files          10       10              
  Lines         946      949       +3     
  Branches      198      198              
==========================================
+ Hits          632      633       +1     
- Misses        291      293       +2     
  Partials       23       23              
Files Coverage Δ
src/pystow/utils.py 61.65% <50.00%> (-0.27%) :arrow_down:

:mega: Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!