question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrapping Tools in Functions

See original GitHub issue

Is there any particular reason why the tools analysis functions are not wrapped in functions with parameters? One challenge I have had is that sometimes it makes sense to use Python with these tools and that is often made difficult because the functionality is not wrapped inside of a functions. The benefits of doing this are the following:

  • Enables tool import into other tools outside of this library

  • Makes it easier to build off the tools

  • Provides a way to edit inputs without going through the GUI

I am willing to help with this if this is a big ask. The general pattern I used for my tools looks like this:

`# Main Function def chained_near_analysis(in_fc, near_features, search_radius=None, location=False, angle=False,fid=False, method=“PLANAR”):

if name == ‘main’:

# Define input parameters

input_features = arcpy.GetParameterAsText(0)

near_features = str(arcpy.GetParameterAsText(1)).split(";")

search_radius = arcpy.GetParameter(2)

location = arcpy.GetParameter(3)

angle = arcpy.GetParameter(4)

fid = arcpy.GetParameter(5)

method = arcpy.GetParameterAsText(6)

chained_near_analysis(input_features, near_features, search_radius, location, angle,fid, method)`

This isolates the function from the GetParameter functions which require typically some interaction from a GUI. Do you have any concerns with this approach?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mmorangcommented, Jun 5, 2019

The transit analysis tools will not be deprecated. They have been re-implemented as a python toolbox in a similar way to BetterBusBuffers (runTool()) in this branch, which will be merged as soon as Pro 2.4 is released.

0reactions
d-wassermancommented, Jun 6, 2019

While I might prefer a more descriptive function call name, this is acceptable. Thank you for incorporating this feedback, it actually saved me on a project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python | functools.wraps() function - GeeksforGeeks
functools is a standard Python module for higher-order functions (functions that act on or return other functions). wraps() is a decorator ...
Read more >
What does functools.wraps do? - Stack Overflow
functools.wraps is convenience function for invoking update_wrapper() as a function decorator, when defining a wrapper function. It is equivalent to partial( ...
Read more >
Gotcha: An Function-Wrapping Interface for HPC Tools
This paper introduces Gotcha, a function wrapping interface and library for HPC tools. Many HPC tools, and performance analysis tools in ...
Read more >
11 Genius Tools That Make Gift-Wrapping Easy | Martha Stewart
Ready to wrap? Shop these tools to help you gift-wrap presents like a pro from cutting paper to tying bows, ribbons, and toppers....
Read more >
functools — Higher-order functions and operations on callable ...
New in version 3.2. Decorator to wrap a function with a memoizing callable that saves up to the maxsize most recent calls. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found