Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only print warning when using old cothread version #23

Conversation

AlexanderWells-diamond
Copy link
Contributor

@AlexanderWells-diamond AlexanderWells-diamond commented Oct 25, 2023

Everything from cothread 2.16+ is safe to use alongside epicscorelibs.

This has been manually tested with Python 2.7 with cothread 2.13.1 through 2.18.1, and Python 3.8 with cothread 2.16 through 2.19.1.

Fixes #22

CC @Araneidae

Everything from cothread 2.16+ is safe to use alongside epicscorelibs.
Copy link
Member

@mdavidsaver mdavidsaver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to minimize the number of module level variables. So either del the new module variables, especially cothread, or move this check into a function.

Maybe something like:

def check_cothread_order():
    cothread = sys.modules.get("cothread")
    # >= 2.16 will attempt to import this module
    # >= 2.19 adds cothread._version
    ver = getattr(cothread, "_version", None) or 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

src/python/epicscorelibs/path/cothread.py Outdated Show resolved Hide resolved
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
@AlexanderWells-diamond
Copy link
Contributor Author

Thank you @mdavidsaver.

There was a slight issue with the suggestion, as getattr(cothread, "_version", None) returns a Module object rather than the version string in newer Cothread versions. I figure it's simplest to just always find and parse the version string in all cases.

@AlexanderWells-diamond AlexanderWells-diamond merged commit 581fd56 into epics-base:master Jul 31, 2024
31 checks passed
@AlexanderWells-diamond AlexanderWells-diamond deleted the fix_cothread_warning branch July 31, 2024 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect warning when using epciscorelibs.path.cothread
3 participants