Update search path?

I’m working on an Ansible module that will enable Mesos operators to easily update resource reservations within the mesos platform. I’ve got things unit tested and validated against a dev cluster. Unfortunately, when I install the ansible package locally, some path issues come up.

How can a update the search path at runtime for a module? I have a package under module_utils that contains generated python code from protobuf files. In order for the generated code to work, the package search path must start at the module_utils directory. Updating the search path in the init.py for this package works in the dev environment and under test, but not when installing ansible locally from my fork. Afterward, I’ve tried using pkg_resources.working_set.add_entries, it does not seem to update the search path because the path is not found when I execute my module outside of the dev environment. Let me provide an example:

Base module_utils directory:

lib/ansible/module_utils/mesos

The generated python code in the mesos package must reference package like this:

import mesos.mesos_pb2

In the dev environment, conditionally updating the sys.path to include the module_utils directory does the trick, but not in other executing environments.

Is there a recommended method of updating the search path so it will work outside of the development environment? I’m using the generated python code to avoid having to deal with JSON as the Content-Type. the generated code generates classes that are type checked and makes working with the Mesos Operator API a lot more predictable.

My code can be found here: https://github.com/miroswan/ansible. Of course, it is subject to change over time.

Thanks in advance.

Did some investigation. When the code is executed, it appears the bundled in a zip archive. I’ve did some inspection using this in the init.py for lib/ansible/module_utils/mesos

z = os.path.abspath(os.path.join(os.path.dirname(file), ‘…’, ‘…’, ‘…’))
files = [item.filename for item in ZipFile(z).infolist()]
raise Exception(files)

[‘ansible/init.py’, ‘ansible/module_utils/init.py’, ‘ansible_module_mesos_resource_reservations.py’, ‘ansible/modu
le_utils/mesos/api.py’, ‘ansible/module_utils/basic.py’, ‘ansible/module_utils/mesos/init.py’, ‘ansible/module_utils/_text.py’, ’
ansible/module_utils/parsing/convert_bool.py’, ‘ansible/module_utils/parsing/init.py’, ‘ansible/module_utils/pycompat24.py’, ‘ans
ible/module_utils/six/init.py’, ‘sitecustomize.py’]

None of the sub-packages are showing up. This is after i’ve updated the pythonpath. Now to figure out why.