pcdshub / happi

Heuristic Access to Positions of Photon Instruments
https://pcdshub.github.io/happi/master
Other
13 stars 29 forks source link

ENH: allow relative paths for json db in happi config #269

Closed JJL772 closed 2 years ago

JJL772 commented 2 years ago

Paths to the json db can now be relative to the happi config, unless they're already absolute.

Resolves #188

Description

This allows paths to the json db to be relative to the happi config.

For the device_config repo, its happi.cfg can look like this, instead of containing an absolute path:

[DEFAULT]
path=db.json

Other relative paths will work fine too, ie ../device_config/db.jsonm ./db.json. Absolute paths are not transformed at all by the json backend when looking for the db, so /reg/g/pcds/happi.cfg will still mean /reg/g/pcds/happi.cfg.

The solution I came up with for this isn't as clean as I'd like. Since each backend accepts arbitrary args from the happi config, there's no good way to process paths before sending them to the backend. Ultimately, it's up to the backend implementation to process any paths such that they're correct. Luckily, the only backend that relies on paths from the config is the json backend.

Motivation and Context

Our happi configs all have absolute paths in them, which makes them annoying to use outside of our LCLS environment. For example, I needed to modify the happi.cfg in our device_config repo so I could play around with the LCLS device db on my local machine.

How Has This Been Tested?

One test was modified to account for the new handling, and another test was added to specifically test configs with absolute paths for the json db.

Where Has This Been Documented?

Relevant comments have been modified or created in the code changed by this PR. I didn't see anything in the happi documentation that would need to be changed.

ZLLentz commented 2 years ago

Travis is failing on the pre-commit isort style check

isort....................................................................Failed
- hook id: isort
- files were modified by this hook
Fixing /home/travis/build/pcdshub/happi/happi/utils.py
=====================================================================
WARNING: One or more pre-commit checks have failed!
This means you do not have pre-commit set up in your local checkout!
See https://github.com/pcdshub/pre-commit-hooks/blob/master/README.md
or use the above output and the following diff to fix the issues
manually:
=====================================================================
diff --git a/happi/utils.py b/happi/utils.py
index 6b491c3..8b0363b 100644
--- a/happi/utils.py
+++ b/happi/utils.py
@@ -4,8 +4,8 @@ Basic module utilities
 import functools
 import keyword
 import logging
-import warnings
 import os
+import warnings
 from typing import Callable

 from .errors import EnforceError
~/build/pcdshub/happi
The command "bash $CI_HELPER_PATH/travis/pre_commit.sh" exited with 1.
JJL772 commented 2 years ago

If we update the happi configs I'm slightly worried about compatibility with old versions of happi that don't use this feature... I'm not entirely sure what to do about this. But that's no reason to not fix this for future use.

Maybe we could update configs in a year or so? At that point we shouldn't be running an old version of happi (hopefully :smile:)

ZLLentz commented 2 years ago

Maybe we could update configs in a year or so? At that point we shouldn't be running an old version of happi (hopefully 😄)

Maybe a bit sooner during the next downtime we could switch over and see if we broke anything