diff --git a/tutorpicasso/commands/enable_private_packages.py b/tutorpicasso/commands/enable_private_packages.py index 7e982f7..9cebdec 100644 --- a/tutorpicasso/commands/enable_private_packages.py +++ b/tutorpicasso/commands/enable_private_packages.py @@ -5,9 +5,9 @@ import click from packaging.version import Version from tutor import config as tutor_config -from tutor.__about__ import __version__ as tutor_version -from tutor import utils as tutor_utils from tutor import fmt as tutor_fmt +from tutor import utils as tutor_utils +from tutor.__about__ import __version__ as tutor_version @click.command(name="enable-private-packages", help="Enable picasso private packages") diff --git a/tutorpicasso/commands/run_extra_commands.py b/tutorpicasso/commands/run_extra_commands.py index c70e3c7..74e0082 100644 --- a/tutorpicasso/commands/run_extra_commands.py +++ b/tutorpicasso/commands/run_extra_commands.py @@ -1,7 +1,6 @@ import re import subprocess from itertools import chain - from typing import Any, List, Pattern import click diff --git a/tutorpicasso/plugin.py b/tutorpicasso/plugin.py index 2c06e61..e7ff3fc 100644 --- a/tutorpicasso/plugin.py +++ b/tutorpicasso/plugin.py @@ -1,11 +1,12 @@ from __future__ import annotations import os +import re from glob import glob import click import importlib_resources -from packaging.version import Version +from packaging.version import InvalidVersion, Version from tutor import hooks from tutor.__about__ import __version__ as tutor_version @@ -19,7 +20,30 @@ # Tutor introduces the MOUNTED_DIRECTORIES in the latest Palm version. latest_palm_version = "16.1.8" -if Version(tutor_version) > Version(latest_palm_version): + + +def safe_version(v: str) -> Version: + """Parse a version string, tolerating non-PEP-440 suffixes like '-main', '-dev', etc. + + Converts '21.0.6-main' -> '21.0.6+main' (a valid PEP 440 local version), + and falls back to stripping the suffix entirely if that still fails. + """ + try: + return Version(v) + except InvalidVersion: + pass + + # Replace the first '-' with '+' (PEP 440 local segment) + normalized = re.sub(r"-([A-Za-z][\w.]*)", r"+\1", v, count=1) + try: + return Version(normalized) + except InvalidVersion: + # Last resort: strip any trailing non-numeric segment + stripped = re.sub(r"[-+].*$", "", v) + return Version(stripped) + + +if safe_version(tutor_version) > safe_version(latest_palm_version): hooks.Filters.MOUNTED_DIRECTORIES.add_items( [ ("openedx", r"eox-.*"),