aces / Loris-MRI

The set of scripts that preprocess and insert MRI data into the database.
10 stars 50 forks source link

Python library proposal: Typed argument parser #1141

Open MaximeMulder opened 2 days ago

MaximeMulder commented 2 days ago

Proposal

LORIS-MRI has its own handwritten argument parser. I propose to use an external library for this task instead. The scripts that currently use LORIS-MRI argument parser do not have to change, but I believe new ones could benefit from this change (including #1117).

Options

Here are the two possible libraries:

Arguments

I personally believe reimplementing features that already exist in established libraries (more discussion on "established" later) has several drawbacks:

There are also arguments against using libraries like the lack of flexibility or potential for dependency hell but I believe those are minor if the library is established enough, as it should then be complete or modular enough so that we don't need to modify it, and should also stay up-to-date to not create a dependency hell.

TAP or Argparse

I am personally a big advocate of static typing, which I believe helps to write robust code, document this code, and refactor this code (emphasis on this point, writing untyped code is imo not a problem, but refactoring a large untyped codebase without breaking stuff is much more complicated). For this reason, I have a preference for TAP over Argparse (or our handwritten implementation that is also untyped), which is described as a "typed modernization of Python's argparse library".

Is TAP established ?

As said previously, it is highly desirable for a library to be established enough before adding it to a project. Hence the question: Is TAP established ?

At the time of this writing, the latest Python version is 3.12 (not 3.13 like I said in the meeting !), TAP is compatible with this version and was last updated on April 11.

When looking for "python argparse typing" on Google, the first two results are StackOverflow answers that recommend TAP, which is a sign of the library being the main actor in its space. Looking for "Python typed argument parsing" also brings up this library. Omitting typing brings Argparse.

Argparse is obviously established as it is part of Python's standard library (but note that it is also older and predates Python static typing).