hey guys :wave: wonder who is using pulumi with py...
# general
s
hey guys 👋 wonder who is using pulumi with python projects, how do you import packages from the main project for example if you need to use information from models/dataclasses
👍 1
s
yes, in this example
config
locates in the same folder as
___main___
in my case I’m trying to import package from level above typically you can do relative import like
from ..models import ModelItem
, but with pulumi it doesn’t work
the idea to share models between pulumi and application code
c
If it helps; the only workaround I found was to use the
sys.path.append
trick:
Copy code
sys.path.append(os.fsdecode(Path(__file__).resolve().parent.parent.parent))
from path.to.whatever import *
I found through trial and error that this only works if you use
__main__
for the main Pulumi module, if you override it in config then it doesn’t work. It also only works with the
from x import y
form of import
I recall seeing a GH issue and a link to a sample repo as well, I don’t have the link to hand (oh, the example workaround is linked to the above GH issue, if you click through enough links! https://github.com/followben/pulumi-example/blob/master/src/infra/project2/__main__.py#L12)
I suggest upvoting https://github.com/pulumi/pulumi/issues/7360 as this is something that could really use improvement
1
s
thank you