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

Python library proposal: Typed argument parser #1141

Open
MaximeMulder opened this issue Jul 4, 2024 · 0 comments
Open

Python library proposal: Typed argument parser #1141

MaximeMulder opened this issue Jul 4, 2024 · 0 comments

Comments

@MaximeMulder
Copy link

MaximeMulder commented Jul 4, 2024

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:

  • Usually, our handwritten implementation will be of worse quality than a library because we are not specialized on the specific feature and we have to spread our efforts on many other features.
  • Usually, established libraries tend to have better documentation, which helps new people to get onboard.

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.

I just did a downloads comparison of the number of downloads last day with the current requirements of LORIS-MRI to get an idea, in descending order:

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).

@MaximeMulder MaximeMulder changed the title Library proposal : Typed argument parser Library proposal: Typed argument parser Jul 4, 2024
@MaximeMulder MaximeMulder changed the title Library proposal: Typed argument parser Python Library proposal: Typed argument parser Jul 4, 2024
@MaximeMulder MaximeMulder changed the title Python Library proposal: Typed argument parser Python library proposal: Typed argument parser Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant