Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] simple CLI #622

Open
8 tasks
adebardo opened this issue Oct 28, 2024 · 0 comments · May be fixed by #629
Open
8 tasks

[POC] simple CLI #622

adebardo opened this issue Oct 28, 2024 · 0 comments · May be fixed by #629
Labels
[POC] TODO Ready for developpment

Comments

@adebardo
Copy link

Given that @vschaffn is making good progress this month, we will set up a simple CLI that allows for the coregistration of two DEMs with Nuth and Kaab.

Context

The purpose of this ticket is to set up the initial file that will allow xDEM to be executed via a CLI command: xdem path_ref path_sec -v. Initially, the command will not execute any functionality but will simply display output.

  • Add the file xdem_cli.py
  • Add the function get_parser
def get_parser():
    """
    ArgumentParser for xdem

    :return: parser
    """
    parser = argparse.ArgumentParser(
        description=("Compare Digital Elevation Models"),
        fromfile_prefix_chars="@",
    )

    parser.add_argument(
        "reference_dem",
        help=(
            "path to a reference dem"
        ),
    )
    
    parser.add_argument(
        "dem_to_be_aligned",
        help=(
            "path to a second dem"
        ),
    )
    
	 parser.add_argument(
	 "--loglevel",
	 default="INFO",
	 choices=("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"),
	 help="Logger level (default: INFO. Should be one of "
	 "(DEBUG, INFO, WARNING, ERROR, CRITICAL)",
	 )

    parser.add_argument(
        "--version",
        "-v",
        action="version",
        version=f"%(prog)s {xdem.__version__}",
    )

	return parser
  • add main function
def main():
    """
    Call demcompare's main
    """
    parser = get_parser()
    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    # use a global try/except to cath
    xdem.run(args.reference_dem, args.dem_to_be_aligned, args.verbose)
    
if __name__ == "__main__":
    main()
  • add imports in setup.py file
  • in file init.py add function run(configfile)
def run(reference_dem: str, dem_to_be_aligned: str, verbose: bool):  
	"""
	docstring
	"""

	print("hello world")
  • in setup.cfg add
# xdem entry points cli scripts
# xdem : main cli Program
[options.entry_points]
console_scripts =
    xdem = xdem.xdem:main

Tests

  • "Add a test that runs the execution and checks the output string in a file named tests/test_cli.py"

Documentation

In folder doc/source/quickstart.md :

  • Add a section about the CLI
@adebardo adebardo added the [POC] TODO Ready for developpment label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[POC] TODO Ready for developpment
Projects
None yet
1 participant