When using a python toolbox (.pyt) in ArcMap, I'll typically follow a pattern where the .pyt file itself is simply a wrapper to collect input arguments and define the tools themselves. Supporting code is kept in separate unit-testable modules.
Example:
import supporting_module
class MyTool(object):
...
def execute(self, parameters, messages):
"""The source code of the tool."""
some_input = parameters[0].valueAsText
some_output = parameters[1].valueAsText
supporting_module.do_something(some_input, some_output)
arcpy.SetParameter(2, some_output)
This works out really well but I've run into one frustrating issue during development. Right-click -> Refresh on the .pyt in ArcMap only refreshes the .pyt file's code. It does not refresh the imported modules, so I have to close and re-open ArcMap whenever I change something there. Fortunately, since I'm testing the code independently, I don't have to do this a ton, but it's still a major hassle. Is there any way around this? Somewhat related - is there any way to fully refresh the Python console (i have a custom site-package that I must also close/reopen ArcMap to pull in changes from as well)?
I'm using ArcMap 10.2.1.
reload()right after importing the supporting module, at the top of the toolbox's PYT file. Thus, if the toolbox contains several tools, I do not have to duplicate the reload in each tool'sexecute()function. – Mike Finch Aug 31 '17 at 15:19from pyfile import Tool, addingreload(tool)returnstypeError: reload() argument must be module. Any ideas? – Ratnanil Feb 06 '18 at 22:29