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

Use looseversion in place of distutils #904

Open
wants to merge 1 commit into
base: stable/caracal
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion charmhelpers/core/hookenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
# Charm Helpers Developers <[email protected]>

import copy
from distutils.version import LooseVersion
try:
from distutils.version import LooseVersion
except ImportError:
from looseversion import LooseVersion
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

shouldn't this be more like:

try:
    from distutils.version import LooseVersion
except ImportError:
    try:
        # reactive charm path, where the venv already has this package
        from looseversion import LooseVersion
    except ImportError:
        # classic charm code path where python packages are installed via apt-get
        apt_install(['python3-looseversion'], fatal=True)
        from looseversion import LooseVersion

Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't like this pattern where charmhelpers runs apt_install; I'd much rather the parent charm resolved the dependencies and installed python3-looseversion where necessary; (which might be all of them in the future). It makes unit testing harder when apt_install() is at module load time.

from enum import Enum
from functools import wraps
from collections import namedtuple, UserDict
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ Jinja2
netaddr

pbr!=2.1.0,>=2.0.0 # Apache-2.0

looseversion;python_version >= '3.12'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

how does this work when being used in a classic charm?

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on your comment above, it probably breaks unless the parent charm ensures that the package is installed.

Loading