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

Python pre-release SDKs use wrong provider version #16212

Open
danielrbradley opened this issue May 16, 2024 · 0 comments
Open

Python pre-release SDKs use wrong provider version #16212

danielrbradley opened this issue May 16, 2024 · 0 comments
Labels
area/codegen SDK-gen, program-gen, convert impact/reliability Something that feels unreliable or flaky kind/bug Some behavior is incorrect or out of spec language/python

Comments

@danielrbradley
Copy link
Member

Python SDKs for pre-release versions of providers send incorrect version numbers in the default resource and invoke options.

In the generated _utilities.py file, the default options are calculated by:

def get_resource_opts_defaults() -> pulumi.ResourceOptions:
    return pulumi.ResourceOptions(
        version=get_version(),
        plugin_download_url=get_plugin_download_url(),
    )

def get_invoke_opts_defaults() -> pulumi.InvokeOptions:
    return pulumi.InvokeOptions(
        version=get_version(),
        plugin_download_url=get_plugin_download_url(),
    )

get_version is defined as:

_version = _get_semver_version()
_version_str = str(_version)

def get_version():
    return _version_str

_get_semver_version reads the version from the root_package version metadata:

def _get_semver_version():
    # __name__ is set to the fully-qualified name of the current module, In our case, it will be
    # <some module>._utilities. <some module> is the module we want to query the version for.
    root_package, *rest = __name__.split('.')

    # pkg_resources uses setuptools to inspect the set of installed packages. We use it here to ask
    # for the currently installed version of the root package (i.e. us) and get its version.

    # Unfortunately, PEP440 and semver differ slightly in incompatible ways. The Pulumi engine expects
    # to receive a valid semver string when receiving requests from the language host, so it's our
    # responsibility as the library to convert our own PEP440 version into a valid semver string.

    pep440_version_string = importlib.metadata.version(root_package)
    pep440_version = PEP440Version.parse(pep440_version_string)
    (major, minor, patch) = pep440_version.release
    prerelease = None
    if pep440_version.pre_tag == 'a':
        prerelease = f"alpha.{pep440_version.pre}"
    elif pep440_version.pre_tag == 'b':
        prerelease = f"beta.{pep440_version.pre}"
    elif pep440_version.pre_tag == 'rc':
        prerelease = f"rc.{pep440_version.pre}"
    elif pep440_version.dev is not None:
        prerelease = f"dev.{pep440_version.dev}"

    # The only significant difference between PEP440 and semver as it pertains to us is that PEP440 has explicit support
    # for dev builds, while semver encodes them as "prerelease" versions. In order to bridge between the two, we convert
    # our dev build version into a prerelease tag. This matches what all of our other packages do when constructing
    # their own semver string.
    return SemverVersion(major=major, minor=minor, patch=patch, prerelease=prerelease)

This python version is insufficient to calculate the correct provider version. For example, a provider version of 1.93.1-alpha.1675198718+c586f7b1 gets transformed into the python version 1.93.1a1675198718 which lacks the whole section for +c586f7b1.

When the python SDK is generated with the respectSchemaVersion option enabled, the pulumi-plugin.json file is generated with the .version field populated with the original provider version. If this is available (which it is now for all providers), then this value should be used for the default resource and invoke options.

@danielrbradley danielrbradley added kind/bug Some behavior is incorrect or out of spec impact/reliability Something that feels unreliable or flaky language/python area/codegen SDK-gen, program-gen, convert needs-triage Needs attention from the triage team labels May 16, 2024
@danielrbradley danielrbradley changed the title Python pre-release SDKs use wrong version Python pre-release SDKs use wrong provider version May 16, 2024
@justinvp justinvp removed the needs-triage Needs attention from the triage team label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codegen SDK-gen, program-gen, convert impact/reliability Something that feels unreliable or flaky kind/bug Some behavior is incorrect or out of spec language/python
Projects
None yet
Development

No branches or pull requests

2 participants