pulumi/sdk/python/dist/pulumi-resource-pulumi-python.cmd

32 lines
1.5 KiB
Batchfile
Raw Normal View History

Python Dynamic Providers (#2900) Dynamic providers in Python. This PR uses [dill](https://pypi.org/project/dill/) for code serialization, along with a customization to help ensure deterministic serialization results. One notable limitation - which I believe is a general requirement of Python - is that any serialization of Python functions must serialize byte code, and byte code is not safely versioned across Python versions. So any resource created with Python `3.x.y` can only be updated by exactly the same version of Python. This is very constraining, but it's not clear there is any other option within the realm of what "dynamic providers" are as a feature. It is plausible that we could ensure that updates which only update the serialized provider can avoid calling the dynamic provider operations, so that version updates could still be accomplished. We can explore this separately. ```py from pulumi import ComponentResource, export, Input, Output from pulumi.dynamic import Resource, ResourceProvider, CreateResult, UpdateResult from typing import Optional from github import Github, GithubObject auth = "<auth token>" g = Github(auth) class GithubLabelArgs(object): owner: Input[str] repo: Input[str] name: Input[str] color: Input[str] description: Optional[Input[str]] def __init__(self, owner, repo, name, color, description=None): self.owner = owner self.repo = repo self.name = name self.color = color self.description = description class GithubLabelProvider(ResourceProvider): def create(self, props): l = g.get_user(props["owner"]).get_repo(props["repo"]).create_label( name=props["name"], color=props["color"], description=props.get("description", GithubObject.NotSet)) return CreateResult(l.name, {**props, **l.raw_data}) def update(self, id, _olds, props): l = g.get_user(props["owner"]).get_repo(props["repo"]).get_label(id) l.edit(name=props["name"], color=props["color"], description=props.get("description", GithubObject.NotSet)) return UpdateResult({**props, **l.raw_data}) def delete(self, id, props): l = g.get_user(props["owner"]).get_repo(props["repo"]).get_label(id) l.delete() class GithubLabel(Resource): name: Output[str] color: Output[str] url: Output[str] description: Output[str] def __init__(self, name, args: GithubLabelArgs, opts = None): full_args = {'url':None, 'description':None, 'name':None, 'color':None, **vars(args)} super().__init__(GithubLabelProvider(), name, full_args, opts) label = GithubLabel("foo", GithubLabelArgs("lukehoban", "todo", "mylabel", "d94f0b")) export("label_color", label.color) export("label_url", label.url) ``` Fixes https://github.com/pulumi/pulumi/issues/2902.
2019-07-19 19:18:25 +02:00
@echo off
if defined PULUMI_RUNTIME_VIRTUALENV (
REM If python exists in the virtual environment, set PATH and run it.
if exist "%PULUMI_RUNTIME_VIRTUALENV%\Scripts\python.exe" (
REM Update PATH and unset PYTHONHOME.
set "PATH=%PULUMI_RUNTIME_VIRTUALENV%\Scripts;%PATH%"
set PYTHONHOME=
REM Run python from the virtual environment.
"%PULUMI_RUNTIME_VIRTUALENV%\Scripts\python.exe" -u -m pulumi.dynamic %*
exit /B
) else (
echo The 'virtualenv' option in Pulumi.yaml is set to %PULUMI_RUNTIME_VIRTUALENV%, but %PULUMI_RUNTIME_VIRTUALENV% doesn't appear to be a virtual environment. 1>&2
echo Run the following commands to create the virtual environment and install dependencies into it: 1>&2
echo 1. python -m venv %PULUMI_RUNTIME_VIRTUALENV% 1>&2
echo 2. %PULUMI_RUNTIME_VIRTUALENV%\Scripts\python.exe -m pip install --upgrade pip setuptools wheel 1>&2
echo 3. %PULUMI_RUNTIME_VIRTUALENV%\Scripts\python.exe -m pip install -r %cd%\requirements.txt 1>&2
echo For more information see: https://www.pulumi.com/docs/intro/languages/python/#virtual-environments 1>&2
exit 1
)
) else (
if defined PULUMI_PYTHON_CMD (
REM If PULUMI_PYTHON_CMD is defined, run it.
"%PULUMI_PYTHON_CMD%" -u -m pulumi.dynamic %*
) else (
REM Otherwise, just run python. We use `python` instead of `python3` because Windows
REM Python installers install only `python.exe` by default.
@python -u -m pulumi.dynamic %*
)
)