https://pulumi.com logo
#general
Title
# general
s

shy-musician-55524

12/13/2021, 5:13 PM
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

shy-musician-55524

12/13/2021, 6:52 PM
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

colossal-boots-62227

12/14/2021, 1:13 AM
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

shy-musician-55524

12/17/2021, 12:07 PM
thank you
3 Views