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

add python script to generate config based on gitlab group #337

Merged
merged 4 commits into from
Feb 25, 2022

Conversation

aschleifer
Copy link
Contributor

@tony this is the python version of the script we added with #336 for #334 .

It has the same usages as for the bash script, but it also validates that it can write the file and will ask the user if it should overwrite an existing config.

As I said before I'm not a python expert, so if you have any improvement ideas please let me know.

Also I wasn't sure about any style guides this project follows. If you name me the guide I'm happy to format the code accordingly.

Best regards
Segaja

@aschleifer aschleifer force-pushed the 334_generate_gitlab_script_python branch from 6bcdc3c to 0c45519 Compare February 24, 2022 18:38
@aschleifer
Copy link
Contributor Author

Ok, I saw that github automatically ran flake8 against the changes and I fixed the issues it showed.

@aschleifer
Copy link
Contributor Author

I must say I'm not a fan of all changes the [pre-commit.ci] is doing ( ae27f03 ). Some of the formattings just make the code harder to read now, but ok.

@codecov
Copy link

codecov bot commented Feb 24, 2022

Codecov Report

Merging #337 (ae27f03) into master (cd079a5) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #337   +/-   ##
=======================================
  Coverage   82.48%   82.48%           
=======================================
  Files          11       11           
  Lines         651      651           
=======================================
  Hits          537      537           
  Misses        114      114           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd079a5...ae27f03. Read the comment docs.

@tony
Copy link
Member

tony commented Feb 24, 2022

I must say I'm not a fan of all changes the [pre-commit.ci] is doing ( ae27f03 ). Some of the formattings just make the code harder to read now, but ok.

Yeah, it formats to to what black formatter's settings are

this is becoming more and more common in open source projects (not the precommit, but running black on the code).

I will look at this tonight / tomorrow

you could also rebase it into your changes and squash as you'd like in the mean time

@aschleifer
Copy link
Contributor Author

Yeah, it formats to to what black formatter's settings are

this is becoming more and more common in open source projects (not the precommit, but running black on the code).

I'm ok with running a formatter in a project to agree on the formatting. I'm just saying I myself are not too happy with one of the formatting options, but I can live with it.

you could also rebase it into your changes and squash as you'd like in the mean time

Nah, I'm fine with leaving it as it is right now. Unless you want me to rebase this all into one perfect commit which brings in the script in one clean commit.

@tony
Copy link
Member

tony commented Feb 25, 2022

Unless you want me to rebase this all into one perfect commit which brings in the script in one clean commit.

Based on the commits in the PR, i will likely do "squash and merge" which will have the same effect when merged to the trunk

@tony
Copy link
Member

tony commented Feb 25, 2022

@aschleifer Is this good to merge for now? Anything else you'd like me to add?

@aschleifer
Copy link
Contributor Author

@aschleifer Is this good to merge for now? Anything else you'd like me to add?

From my side this is good to go. I guess in the end the only thing missing is the already mentioned example entry.

@tony
Copy link
Member

tony commented Feb 25, 2022

@aschleifer This sounds good. Thank you for this!

Merging this in

This coming week I will make a release that ships a root command with vcspull sync and through the next week(s), publish fixes for the bugs.

@tony tony merged commit 50b6382 into vcs-python:master Feb 25, 2022
@aschleifer aschleifer deleted the 334_generate_gitlab_script_python branch February 25, 2022 15:40
args = vars(parser.parse_args())
gitlab_host = args["gitlab_host"]
gitlab_namespace = args["gitlab_namespace"]
config_filename = args["config_file_name"]
Copy link

Choose a reason for hiding this comment

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

You might just want to create a pathlib.Path here, as it has easy object based handling (e.g. Path.is_file())

Copy link
Member

Choose a reason for hiding this comment

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

@dvzrv @aschleifer would either of you like to make a follow up PR improving upon this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tony I will do a follow up PR soon to address this point.

try:
if os.path.isfile(config_filename):
result = input(
"The target config file (%s) already exists, \
Copy link

Choose a reason for hiding this comment

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

As this codebase is for python >= 3.7, you can just use f-strings PEP0498. E.g. f"foo {my_variable}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tony how do you stand on the topic of injecting variables into strings? is there one formatting / style you would like to see used in the python code?

tony added a commit that referenced this pull request Feb 26, 2022
@tony
Copy link
Member

tony commented Feb 26, 2022

@aschleifer Added to https://vcspull.git-pull.com/config-generation.html#python-version

Similar to #336, I included my demo usage there.

@tony
Copy link
Member

tony commented Feb 26, 2022

@aschleifer P.S. Is it your desire to have the scripts included in the python package itself? Either inside the directory or available in the bin/ packages?

@aschleifer
Copy link
Contributor Author

@aschleifer P.S. Is it your desire to have the scripts included in the python package itself? Either inside the directory or available in the bin/ packages?

I think at the end I will try to add this as a "native command" in vcspull and then we can remove these scripts.

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.

3 participants