DiamondLightSource / DiamondLightSource/cothread
Import order causes warnings when working with epicscorelibs and softioc
- Dominant language
- C
- Stars
- 13
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
As [epicscorelibs](https://github.com/mdavidsaver/epicscorelibs) maintains its own libca, it provides the option to set the 'CATOOLS_LIBCA_PATH' before using cothread. This can be found [here](https://github.com/mdavidsaver/epicscorelibs/blob/9974875f9cbddd68a3d8dcc358eb4dd6c38b95db/src/python/epicscorelibs/path/cothread.py#L22). This mechanism does not appear to be ideal.
For example, [softioc](https://github.com/dls-controls/pythonSoftIOC) uses this mechanism [here](https://github.com/dls-controls/pythonSoftIOC/blob/dfc3971d91873f7b44c0daadf675022f5da3aa9d/softioc/__init__.py#L11). The problem comes when another program attempts to use both softioc and cothread itself. A simple program such as the following:
```
#! /usr/bin/env python3
import cothread.catools
import softioc
```
will result in the following error (and potentially problematic behaviour):
```
$ ./test_imports.py
/path/to/pipenv/environment/lib/python3.7/site-packages/epicscorelibs/path/cothread.py:18: UserWarning: epicscorelibs.path.cothread must be imported before cothread.catools to have effect
warnings.warn("epicscorelibs.path.cothread must be imported before cothread.catools to have effect")
```
There are two problems:
1. It is not immediately clear what is causing the error
2. If using standard tools such as isort, you need to manually force a particular order of imports to avoid this error. You need to `isort:skip` multiple lines of code
I am not sure why cothread does not use epicscorelibs by default. Would it be possible to implement this?
Alternatively, some kind of conditional import of epicscorelibs could be useful.
Contributor guide
Assessment
This issue has not been assessed yet.