I may be having similar issues as <@U0216C1J78B> a...
# python
f
I may be having similar issues as @purple-appointment-84502 above, if I'm understanding correctly (I'm having a bit of trouble following the directory layout structure as well). I'm trying to manage multiple Pulumi projects in a single repository that share common resource code (e.g., I have defined some component resources that each project uses). I happen to also be using Pants (https://pantsbuild.org) to manage our other Python code, and I can use the Automation API (based on the "Local Program" pattern in the documentation) to run things under Pants, and therefore take advantage of its Python dependency management to resolve the common code. However, I don't want to forego the use of the
pulumi
CLI to interact with these projects and their stacks (e.g., if something goes wrong, I'd like to be easily do something like
pulumi export
-> edit file ->
pulumi import
, without having to also encode that via the Automation API). The best I've managed so far (though I'm still investigating) is to manipulate the
sys.path
in my various
__main__.py
in order to get the shared code importing correctly, but that seems like a hack I'd rather avoid. Is there any guidance for how to structure things (with directory structures, configuration parameters, etc.) to be able to juggle multiple related Pulumi Python projects that share code? Thanks in advance.
n
this is a known python thing, the way we got around this was to have part of the bootstrapping adding the project root folder to PYTHONPATH and dump that to .bashrc/.zshrc Adding the path to sys may work, but it's a bit unamntainable IMO and I preferred to do that at another level
Copy code
pythonpath-add:
	@if [ -f ~/.zshrc ]; then\
		if [ $(shell cat ~/.zshrc | grep "export PYTHONPATH=\$$PYTHONPATH:$$(pwd)" | wc -l) -eq 0 ]; then\
			echo "export PYTHONPATH=\$$PYTHONPATH:$$(pwd)" >> ~/.zshrc;\
		fi;\
	elif [ -f ~/.bashrc ]; then\
		if [ $(shell cat ~/.bashrc | grep "export PYTHONPATH=\$$PYTHONPATH:$$(pwd)" | wc -l) -eq 0 ]; then\
			echo "export PYTHONPATH=\$$PYTHONPATH:$$(pwd)" >> ~/.bashrc;\
		fi;\
	else\
		echo "No shell recognized, append `export PYTHONPATH=$PYTHONPATH:/path/to/this/folder` to your shell configuration file";\
	fi