https://pulumi.com logo
#python
Title
# python
p

purple-appointment-84502

06/22/2021, 8:52 AM
Hi all, struggling with the pulumi automation API in python, and some import issues, wondering if you can help. I'm trying to import a common component resource from a sibling directory as a module. In my main__.py files, i'm trying to import:
from ..common.commonComponentResource
And I'm getting relative import errors. From my understanding, the
work_dir
specified as part of the automation api, needs to be where the stack .yaml files are, and this is then used as the python working directory too. Is there any way to have a different work directory to get around the relative import errors? So the project structure I have is: -- Common ---- CommonComponentResource.py ---- __init.py -- Stack1 ---- _main.py ---- yaml -- Stack2 Thanks for your help!
b

billowy-army-68599

06/22/2021, 8:56 AM
Hi!
and this is then used as the python working directory too
I don't think this is necessarily true, it's a little hard to follow your directory layout structure, but your python interpreter just reads the files as they are
p

purple-appointment-84502

06/22/2021, 9:02 AM
Hi, So I've tried printing the python working directory using something like:
Copy code
import os
cwd = os.getcwd()
What I've noticed is when the automation script runs the tries to run the main stack, the working directory is the stack1 folder. Which is why it's having an issue with the relative imports. I should mention, I've using the automation API to run a "Local Program"
7 Views