Select to view content in your preferred language

Allow multiple files for Python toolboxes

2690
5
02-20-2013 10:53 AM
Status: Closed
Labels (1)
ChrisGarrard
Occasional Contributor

I would like to be able to put each tool in a Python toolbox in its own file. This way I don't end up with a huge and hard to manage .pyt file if the toolbox contains a lot of tools. Right now I can write other modules and use them in the tool's execute method, which definitely helps, but putting the entire tool in its own file would be a lot better.

I was thinking that maybe a Python toolbox could be a folder that contained all of the required files, kind of like a file geodatabase.

 

5 Comments
DavidWynne
Have a look at this python toolbox the Spatial Analyst team recently put out.  

What they did, and what you could do is, is write out tool classes into individual .py's.  Then use a from-<py>-import-<tool> style to import in the tool classes.  Then you just have to add  the imported tool class(es) to the toolbox's tools property.

-Dave
 
Luke_Pinner
HannesZiegler
Status changed to: Closed

Thank you for submitting your idea to break out individual tools in a .pyt into separate files. We appreciate your suggestion and the time you took to provide detailed feedback. The recommended way to separate individual tool logic from your Python Toolbox code is to place the tool logic in separate modules and import these in your .pyt (as described by in Dave and Luke's previous responses).

HaydenWelch

@HannesZiegler 

I do think that the implementation I've shown in pytframe2 is a good iteration on the code shown here. Utilizing module reloading and a more agnostic import system that relies not on import statements, but on a configuration dictionary.

Only adding a comment here to raise some awareness on similar solutions and hopefully gather similar ideas into one solution.

HannesZiegler

Yes, thanks, some users viewing this idea may find it helpful