8000 Exception thrown including environment if installed via pip · Issue #14 · ameliaholcomb/biomass-recovery · GitHub
[go: up one dir, main page]

Skip to content

Exception thrown including environment if installed via pip #14

Open

Description

@mdales

I hit this today, will try come up with a patch for this, but if you install this package into a system folder via pip (which I do when using docker) you can't import environment.py (or things that import that), as you get an exception:

>>> import biomassrecovery.utils.unzip 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/dist-packages/biomassrecovery/utils/unzip.py", line 10, in <module>
    from biomassrecovery.utils import logging_util
  File "/usr/local/lib/python3.10/dist-packages/biomassrecovery/utils/logging_util.py", line 7, in <module>
    from biomassrecovery.environment import DEFAULT_FORMATTER, DEFAULT_LOG_FILE, DEFAULT_LOG_LEVEL
  File "/usr/local/lib/python3.10/dist-packages/biomassrecovery/environment.py", line 20, in <module>
    LOG_PATH.mkdir(parents=True, exist_ok=True)
  File "/usr/lib/python3.10/pathlib.py", line 1175, in mkdir
    self._accessor.mkdir(self, mode)
OSError: [Errno 30] Read-only file system: '/usr/local/lib/python3.10/dist-packages/logs'

In environment.py the LOG_PATH is created (which feels wrong if this code is to be a library, side effects on import considered harmful? but I appreciate the common case isn't to use this as a library). But the path is relative to the module, specifically the module's parent path, hence the path in the last line there.

#  Source folder path
constants_path = Path(__file__)
SRC_PATH = constants_path.parent
PROJECT_PATH = SRC_PATH.parent
CONDA_ENV = os.getenv("CONDA_DEFAULT_ENV")

# Log relatedd paths
LOG_PATH = PROJECT_PATH / "logs"
LOG_PATH.mkdir(parents=True, exist_ok=True)

Unfortunately unlike other things in environment, you can't override this, so this stops us using it outside a python virtualenv.

For now I guess the plan would be to make this path overridable by and environmental variable. Ideally we'd not try create it or at least not fail like this if we can't, but that's a longer term question for you @ameliaholcomb in terms of burdening users with explicit setup.

Activity

  1. self-assigned this
    on Jan 25, 2024
  2. ameliaholcomb commented on Feb 9, 2024

    @ameliaholcomb
    Owner

    Ah, I hate all the custom log stuff in this code, so many regrets.
    I agree side effects considered harmful, and better to use all default logging style anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0