cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Python extension 2.0 - include own sub-modules

r_weber
DynaMight Champion
DynaMight Champion

Hello extension devs,

I have a strange behavior when building a python 2.0 extension. I structure my code/modules like this:

 

 

extension
  extension.yaml
  actiavtionSchema.json
my_extension
- mymodule1
    - submodule
        sub.py
- mymodule2
    module.py
  __main__.py
setup.py

 

When I run the extension locally with the simulator everything works great. But when I build the extension only some/not all module subdirectories are included in the build and such I'm getting missing module errors.
Including the module directories in setup.py doesn't make sense as they would be treated as PyPi packeages, shouldn't the build include those without anything else?

Certified Dynatrace Master, Dynatrace Partner - 360Performance.net
2 REPLIES 2

r_weber
DynaMight Champion
DynaMight Champion

Answering to my own dumbness:
Of course you need to include a __init__.py (can be empty) in every sub directory as well so that the setuptools used when building the extension will include those directories!

Certified Dynatrace Master, Dynatrace Partner - 360Performance.net

r_weber
DynaMight Champion
DynaMight Champion

Also if you want to include non *.py files in your extension, you might want to add this in the setup.py code:
e.g. to also package some json template files with the extension:

 
setup(
    ...
    extras_require={"dev": ["dt-extensions-sdk[cli]"]},
    package_data={
        "my_ext_module_name": ["templates/*.json"],
    },
)
 
Certified Dynatrace Master, Dynatrace Partner - 360Performance.net

Featured Posts