Use conda entry_points
!53 (merged) introduces conda entry_points
, which allows to define a tool "alias"
.
This involves very slight modifications. But a standard would have to be chosen for all these tools, including whether the parameters are named or positional.
A small example, a tool in a file named new_tool.py
:
def check_user_ground_truth(vector_copy, data_field, epsg,
do_corrections):
....
def main():
description = ("\ncheck ground truth database\n"
"\t- remove empty geometries\n"
"\t- remove duplicate geometries\n"
"\t- split multi-polygons to polygons\n"
"\t- check projection\n"
"\t- check vector's name\n"
"\t- check if the label field is integer type\n")
parser = argparse.ArgumentParser(description)
parser.add_argument("-in.vector",
help="absolute path to the vector (mandatory)",
dest="input_vector",
required=True)
parser.add_argument("-out.vector",
help="output vector",
dest="output_vector",
required=False,
default=None)
parser.add_argument("-dataField",
help="field containing labels (mandatory)",
dest="data_field",
required=True)
parser.add_argument("-epsg",
help="expected EPSG's code (mandatory)",
dest="epsg",
required=True,
type=int)
parser.add_argument("-doCorrections",
help="enable corrections (default = False)",
dest="do_corrections",
required=False,
default=False,
type=str2bool)
args = parser.parse_args()
vector_copy = args.output_vector
ds = ogr.Open(args.input_vector)
drv = ds.GetDriver()
drv.CopyDataSource(ds, vector_copy)
check_user_ground_truth(vector_copy, args.data_field, args.epsg,
args.do_corrections)
if __name__ == "__main__":
sys.exit(main())
Then in the iota2 recipe meta.yaml
we can declare a new entry_point
build:
skip: True # [not linux]
number: 1
entry_points:
- Iota2.py = iota2.Iota2:main
- new_tool.py = iota2.common.tool.new_tool:main
This allows in the conda environment to call directly the tool:
new_tool.py -h
without modifying the path #429 (closed), or search in the complex conda path or clone the repository.
The two last line replacing the main allow the following:
python /path/to/new_tool.py -h
It also possible to use click or other parser even argv
.
Once !53 (merged) will be merged and a new package provided, it will be easier to show the differences between arguments parser.
Once a standard has been chosen, the main concerned by #452 can be updated and thus be easily accessible.