#Is there a way to find out what dagger version I am currently running on?

1 messages ยท Page 1 of 1 (latest)

raw bane
#

This is a non-problem for Go as it can be version-locked via go.mod and go.sum but for Python we don't have this.

My use case is: I want to standardize the build tools for all projects with same/similar build scripts and Dagger/Python is perfect for this.

However, if I want to ensure that the correct version of dagger are installed there is currently no way to enforce it short of telling everyone to run the same pip3 install -v dagger-io==0.xx command before running the build scripts.

Either that or I have to force every project to include a poetry (or venv/pip/requirements.txt) lock file, which is not ideal and kind of defeat the purposes of using the Python SDK (instead of the Go SDK with built-in version locking) in the first place.

Python is almost universally available, no matter what platform you are on, compared to Go or Node. I'd love to be able to just python build.py wherever any of my codebase happens to be cloned to and get reproducible builds there. I already have a diag message printed out if the user hasn't yet to install the dagger-io package, but I cannot enforce (or check/validate) the version if it's already installed.

At the moment I'd love to be able to tell if the script is running with the right Dagger version from inside the script itself and at least produce a proper help text/error message if it's not.

Is this possible? What are alternatives?

umbral silo
#

@raw bane not a python expert but doesn't poetry and Pipenv have analogous go.mod and go.lock files as well?

having said that, you can still provide a requirements.txt with your Dagger version fixed there.

rich topaz
#

but I cannot enforce (or check/validate) the version if it's already installed

Yes you can @raw bane ๐Ÿ™‚ With any python package, actually:

from importlib import metadata

def get_sdk_version():
    try:
        return metadata.version("dagger-io")
    except metadata.PackageNotFoundError:
        return "n/a"

It's actually implemented in https://github.com/dagger/dagger/blob/6dc61b1d56190bb40205fc2bc95331b8d154d97e/sdk/python/src/dagger/engine/cli.py#L22-L26 but I'd rather you don't depend on that (can be moved) ๐Ÿ™‚

#

As for the lock file, you're right. It requires you to standardize on a build tool like Poetry. Even freezing in requirements.txt is not good if you have users on Poetry. That's if I understand correctly that your users could be using any number of python package managers (there's several).

#

In NodeJS it's the same as using npm vs yarn. They don't share the same lock file.

rich topaz
#

Just for fun: ๐Ÿ˜

from importlib.metadata import version as get_version, PackageNotFoundError
from packaging.version import parse, InvalidVersion

MIN_DAGGER_VERSION = parse("0.5.1")

class BootstrapError(Exception):
    ...

def check_dagger_version():
    try:
        version = parse(get_version("dagger-io"))
    except PackageNotFoundError:
        raise BootstrapError("The `dagger-io` package isn't installed")
    except InvalidVersion:
        raise BootstrapError(f"Could't verify `dagger-io` package: {e}")
    if version < MIN_DAGGER_VERSION:
        raise BootstrapError(f"Minimum supported Dagger SDK version is {MIN_DAGGER_VERSION} but found {version}")
    return version