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

Clickify cleanup #359

Merged
merged 5 commits into from
Dec 19, 2024
Merged

Clickify cleanup #359

merged 5 commits into from
Dec 19, 2024

Conversation

o-smirnov
Copy link
Member

@o-smirnov o-smirnov commented Dec 17, 2024

@landmanbester please check if this works with PFB.

I've removed the pass_missing_as_none logic from clickify_parameters(), as upon closer investigation, this is what click now does always and anyways, except when dealing with some multiply-valued parameters (that is, Lists with a policy of repeat: repeat, in which case a missing parameter is passed as an empty tuple). I don't see any way to change this behaviour. The new code checks for UNSET defaults, and doesn't give click a default value for them, which results in a None being passed to the callable in the absence of the parameter. I think this behaviour is harmless and unlikely to trip us up, except when you have something perverted like

def func(a: float=3):
  print(a)

with a schema that doesn't mention the default from the function signature:

a:
  dtype: float
  required: false

...which results in func(a=None) when the command-line doesn't specify --a. This is because neither stimela nor click knows anything about the signature actually, and has no choice but to trust what the schema says.

Note that pass_missing_as_none is still honoured by stimela itself when invoking a cab (i.e. is the difference between having nothing in **kw, or having a None value in **kw). Given your love for **kw, I think this is what you expect, right?

@o-smirnov
Copy link
Member Author

Run tests/scabha_tests/test_clickify.py to test this behaviour (and feel free to extend).

Copy link
Collaborator

@landmanbester landmanbester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems ok to me. It will require handling optional lists differently in pfb but that should be doable. More worrying is the numpy dependency here

numpy = "^1.20"

Not sure if this relates to the current setuptools issues but even with setuptools[core] I get the following conflicts

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
codex-africanus 0.4.1 requires numpy<3.0,>=2.0, but you have numpy 1.26.4 which is incompatible.
dask-ms 0.2.23 requires numpy>=2.0.0, but you have numpy 1.26.4 which is incompatible.

What does stimela use numpy for anyway?

@o-smirnov
Copy link
Member Author

o-smirnov commented Dec 19, 2024

Oh fsck numpy, I was only using it in one place, and I can work around without it. I've taken the dependency out, try again.

It will require handling optional lists differently in pfb but that should be doable.

Well nothing's changed there -- it seems that click was passing optional lists as () all along, even with pass_missing_as_none in effect. So if you depend on optional_list is None and don't cope with empty lists, your CLI has always been slightly broken. But checking for an empty optional list or None with if optional_list: is probably harmless to do in most cases, right? Unless "empty list" and "None" are two distinct logic cases for you, which would be a bit perverse.

Copy link
Collaborator

@landmanbester landmanbester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be working for me. Empty lists are still parsed as None for some reason though so this does not really change anything in pfb. I guess it's because I don't have a repeat policy set. Note I will be mostly AFK until I get back from leave in early Jan

@o-smirnov
Copy link
Member Author

OK well if @Athanaseus approves, I'll merge this and do a point release, so he can get his breizorro PR in as well.

@o-smirnov o-smirnov merged commit 2849d49 into master Dec 19, 2024
4 checks passed
@o-smirnov o-smirnov deleted the clickify-cleanup branch December 19, 2024 17:17
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

Successfully merging this pull request may close these issues.

2 participants