Skip to content

Commit

Permalink
Simplify version checks and remove module symbol
Browse files Browse the repository at this point in the history
It is unnecessarily complicated to look for the _version module. We know
there will always be a string version label so we'll always decode it
  • Loading branch information
AlexanderWells-diamond committed Nov 1, 2023
1 parent bbdee3a commit 089d658
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/python/epicscorelibs/path/cothread.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,18 @@

from . import get_lib

if "cothread" in sys.modules:
# Ensure we don't `import cothread` ourselves as that can have side-effects
cothread = sys.modules["cothread"]
if hasattr(cothread, "_version"):
# This attribute only exists in cothread 2.19+.
# It is always safe to use alongside epicscorelibs
pass
else:
# Some cothread versions only include major and minor, no build version
version_components = cothread.__version__.split(".")
major = int(version_components[0])
minor = int(version_components[1])
if major >= 2 and minor >=16:
# Cothread 2.16 was the first to fallback to epicscorelibs' get_lib functionality
pass
else:
warnings.warn("epicscorelibs.path.cothread must be imported before cothread.catools to have effect")
def check_cothread_order():
if "cothread" not in sys.modules:
return
cothread = sys.modules.get("cothread")
# >= 2.16 will attempt to import this module
ver = tuple(int(c) for c in cothread.__version__.split("."))
if ver < (2, 16):
warnings.warn("epicscorelibs.path.cothread must be imported before cothread.catools to have effect")


check_cothread_order()
del check_cothread_order

# don't override if already set
if 'CATOOLS_LIBCA_PATH' not in os.environ:
Expand Down

0 comments on commit 089d658

Please sign in to comment.