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

feat(all): Add global parameters #4

Merged
merged 3 commits into from
Sep 11, 2024

Conversation

nuclearcat
Copy link
Member

1)Moving load_toml to main file, as it is common for all files. 2)Adding context to forward instance and settings to subcommands 3)Modifying at least "commit" subcommand to support latest Pipeline API 4)Add automatic repo info retrieval for "commit" with option to override by cli arguments.

@aliceinwire
Copy link
Member

can you please divide this pr in small change as is difficult to review all toghether

@nuclearcat
Copy link
Member Author

ok

@aliceinwire
Copy link
Member

aliceinwire commented Sep 10, 2024

also I don't understand why you want to merge commit and patch with a general kci-dev.toml instead of keeping the current configuration file and trying to move away from standard click usage implementing a ctx context

@nuclearcat
Copy link
Member Author

settings have identical functionality, it make sense to make it somewhere single place instead of duplicating function on each subcommand.
As i recall context also standard click feature, if you want to have global options that are identical for all subcommands (and instance+settings are indeed same for all subcommands).

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
Copy link
Member

@aliceinwire aliceinwire Sep 10, 2024

Choose a reason for hiding this comment

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

python2 as been deprecated years ago
python2 shebang is "#!/usr/bin/env python2"

python is usually just a symlink to your distribution python version
your distribution should be able to decide the correct python version for you

Copy link
Member Author

Choose a reason for hiding this comment

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

According to PEP 394, For Python script publishers:

"Older Linux distributions will provide a python command that refers to Python 2, and will likely not provide a python2 command."
"Some Linux distributions will not provide a python command at all by default, but will provide a python3 command by default."

In my case (Debian bookworm) python is not provided at all (unless i install python-is-python3), so it is preferable to point to python3 which is supposed to work for all.

Copy link
Member

@aliceinwire aliceinwire Sep 11, 2024

Choose a reason for hiding this comment

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

we should change all the python file not just this one file

Copy link
Member Author

Choose a reason for hiding this comment

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

we should change all the python file not just this one file

Good point, will change all.

@nuclearcat
Copy link
Member Author

nuclearcat commented Sep 10, 2024

My point is that if we will have for example 4 subcommands (jobretry, commit, patch, patchset), we will have to duplicate --settings and load_toml in each file. So i am applying DRY principle and found way to make it shared, i think only way to do that is to make this option as global, as is it is mostly identical.
Also it opens way to add convenient option --instance, where we can test first some feature on local instance, then make PR and test on staging, and then if all ok - production. This is somehow similar concept how kernelci.toml works in kci(kernelci-core).

@aliceinwire
Copy link
Member

aliceinwire commented Sep 11, 2024

My point is that if we will have for example 4 subcommands (jobretry, commit, patch, patchset), we will have to duplicate --settings and load_toml in each file. So i am applying DRY principle and found way to make it shared, i think only way to do that is to make this option as global, as is it is mostly identical. Also it opens way to add convenient option --instance, where we can test first some feature on local instance, then make PR and test on staging, and then if all ok - production. This is somehow similar concept how kernelci.toml works in kci(kernelci-core).

my idea about this was to move such duplicated code to a sort of common library script file, and just call the kernelci.toml reading function on each sub-command as needed. This would make each sub-command more flexible but still preventing to duplicate code.

@nuclearcat
Copy link
Member Author

My point is that if we will have for example 4 subcommands (jobretry, commit, patch, patchset), we will have to duplicate --settings and load_toml in each file. So i am applying DRY principle and found way to make it shared, i think only way to do that is to make this option as global, as is it is mostly identical. Also it opens way to add convenient option --instance, where we can test first some feature on local instance, then make PR and test on staging, and then if all ok - production. This is somehow similar concept how kernelci.toml works in kci(kernelci-core).

my idea about this was to move such duplicated code to a sort of common library script file, and just call the kernelci.toml reading function on each sub-command as needed. This would make each sub-command more flexible but still preventing to duplicate code.

Agree, if it is common function that still have to be present on each subcommand (for example API call wrapper).
Also i think load_toml i can move to such common library.
But i think if each subcommand have common settings file, --settings logically should be global option?

@aliceinwire
Copy link
Member

My point is that if we will have for example 4 subcommands (jobretry, commit, patch, patchset), we will have to duplicate --settings and load_toml in each file. So i am applying DRY principle and found way to make it shared, i think only way to do that is to make this option as global, as is it is mostly identical. Also it opens way to add convenient option --instance, where we can test first some feature on local instance, then make PR and test on staging, and then if all ok - production. This is somehow similar concept how kernelci.toml works in kci(kernelci-core).

my idea about this was to move such duplicated code to a sort of common library script file, and just call the kernelci.toml reading function on each sub-command as needed. This would make each sub-command more flexible but still preventing to duplicate code.

Agree, if it is common function that still have to be present on each subcommand (for example API call wrapper). Also i think load_toml i can move to such common library. But i think if each subcommand have common settings file, --settings logically should be global option?

right, so I think we can go with your patch.

@aliceinwire
Copy link
Member

aliceinwire commented Sep 11, 2024

This PR looks good just be sure to have reformatted everything with python black (https://black.readthedocs.io/en/stable/index.html)

@nuclearcat
Copy link
Member Author

Regarding load_toml, to place in some common library, where do you prefer to put it / name this library?
kci-dev/common.py
kci-dev/libs/common.py?
Sure common and libs can be changed.
Would like to know your preference.

@aliceinwire
Copy link
Member

aliceinwire commented Sep 11, 2024

kci-dev/libs/common.py looks better

thanks for helping on this

@aliceinwire
Copy link
Member

aliceinwire commented Sep 11, 2024

I added isort and python black check with GitHub action through poetry
could you rebase over main?
the import order change could have created some conflicts
For reference: #8

@nuclearcat
Copy link
Member Author

sure, will do today

Many distributions don't have python by default, but have
python3. Update shebang to reflect that.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
@nuclearcat nuclearcat force-pushed the many-changes branch 2 times, most recently from 92aab24 to 09bf3b3 Compare September 11, 2024 14:17
@nuclearcat nuclearcat marked this pull request as ready for review September 11, 2024 14:18
@nuclearcat
Copy link
Member Author

I will do by small bits for now, i will open separate PR for --instance support and few more things

@nuclearcat nuclearcat marked this pull request as draft September 11, 2024 14:19
Following DRY principle creating common library and moving
load_toml there to deduplicate functions.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
As we use same settings file for all subcommands it make sense
to make it global, parse in the beginning, and pass to subcommands
already parsed result.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
@nuclearcat nuclearcat marked this pull request as ready for review September 11, 2024 14:20
@aliceinwire aliceinwire changed the title feat(all): Many improvements and changes feat(all): Add global parameter and common library Sep 11, 2024
@aliceinwire aliceinwire changed the title feat(all): Add global parameter and common library feat(all): Add global parameters Sep 11, 2024
@aliceinwire aliceinwire merged commit 3e74d19 into kernelci:main Sep 11, 2024
1 check passed
@aliceinwire
Copy link
Member

I will do by small bits for now, i will open separate PR for --instance support and few more things

thanks you

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