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

scripts/_common.py: add a shared Python file to move duplicated code #12755

Merged
merged 36 commits into from May 18, 2024

Conversation

sebastiaanspeck
Copy link
Member

@sebastiaanspeck sebastiaanspeck changed the title scipts/_common.py: add a shared Python file to move duplicated code scripts/_common.py: add a shared Python file to move duplicated code May 7, 2024
@github-actions github-actions bot added the tooling Helper tools, scripts and automated processes. label May 7, 2024
@sebastiaanspeck sebastiaanspeck force-pushed the common-python-script branch 3 times, most recently from 25f7717 to 839c057 Compare May 7, 2024 18:21
@tldr-pages tldr-pages deleted a comment from tldr-bot May 7, 2024
@tldr-pages tldr-pages deleted a comment from tldr-bot May 7, 2024
@tldr-pages tldr-pages deleted a comment from tldr-bot May 7, 2024
Copy link
Member

@vitorhcl vitorhcl left a comment

Choose a reason for hiding this comment

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

I was going to open a issue myself and start the refactoring another day, thank you for already starting this work :)

I took a quick look at the code, and in general it looks good indeed.

I think we can extract more functions, for example: the "--page" code in main(), I think we can extract the gathering of the target paths and maybe more things.

I will see if I can review this PR more carefully later.

@sebastiaanspeck
Copy link
Member Author

sebastiaanspeck commented May 7, 2024

I was going to open a issue myself and start the refactoring another day, thank you for already starting this work :)

I took a quick look at the code, and in general it looks good indeed.

I think we can extract more functions, for example: the "--page" code in main(), I think we can extract the gathering of the target paths and maybe more things.

I will see if I can review this PR more carefully later.

It is WIP 🚧 and definitely not ready to merge for the time being, but feel free to add commits 😄

@tldr-bot

This comment has been minimized.

@vitorhcl
Copy link
Member

vitorhcl commented May 8, 2024

(I didn't took a closer look at the code yet)

Unfortunately it's not possible to comment on unmodified lines, but set-alias-page.py still depends on os.path, it uses some of its functions in, for example get_alias_page() and set_alias_page(), for example.

It would be good to remove the os.path and use pathlib everywhere since we are already modifying the scripts, and also because _common.py uses pathlib.

@sebastiaanspeck
Copy link
Member Author

It would be good to remove the os.path and use pathlib everywhere since we are already modifying the scripts, and also because _common.py uses pathlib.

I will definitely look into that. I found out yesterday that the set-alias-page.py as it is right now in this PR does not skip the files that are listed in the IGNORE_FILES

@vitorhcl
Copy link
Member

vitorhcl commented May 8, 2024

I will definitely look into that. I found out yesterday that the set-alias-page.py as it is right now in this PR does not skip the files that are listed in the IGNORE_FILES

Does this problem also happens with set-more-info-link.py? It isn't because of the value of IGNORE_FILES, but because of the functions that use IGNORE_FILES, right?

Do you know which function(s) is/are causing this error?

@sebastiaanspeck
Copy link
Member Author

I will definitely look into that. I found out yesterday that the set-alias-page.py as it is right now in this PR does not skip the files that are listed in the IGNORE_FILES

Does this problem also happens with set-more-info-link.py? It isn't because of the value of IGNORE_FILES, but because of the functions that use IGNORE_FILES, right?

I did not check. Due to the fact that set-more-info-link.py is not changing any pages at the moment, I did not look closer at that one.

Do you know which function(s) is/are causing this error?

It is on line 237 and 243 in set-alias-page.py. I think because page is not a string but a Path, checking if it is in IGNORE_FILES will always fail.

@tldr-bot

This comment was marked as resolved.

@tldr-bot

This comment was marked as resolved.

@tldr-bot

This comment was marked as resolved.

@sebastiaanspeck
Copy link
Member Author

I will definitely look into that. I found out yesterday that the set-alias-page.py as it is right now in this PR does not skip the files that are listed in the IGNORE_FILES

Does this problem also happens with set-more-info-link.py? It isn't because of the value of IGNORE_FILES, but because of the functions that use IGNORE_FILES, right?

I did not check. Due to the fact that set-more-info-link.py is not changing any pages at the moment, I did not look closer at that one.

Do you know which function(s) is/are causing this error?

It is on line 237 and 243 in set-alias-page.py. I think because page is not a string but a Path, checking if it is in IGNORE_FILES will always fail.

It was a typo after all... if p not in IGNORE_FILES should've been if p.name not in IGNORE_FILES

@tldr-bot

This comment was marked as resolved.

@sebastiaanspeck sebastiaanspeck force-pushed the common-python-script branch 2 times, most recently from 7b1a484 to 5afdf6b Compare May 11, 2024 11:50
Copy link
Member

@vitorhcl vitorhcl left a comment

Choose a reason for hiding this comment

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

I have a suggestion to clarify the color handling that would require updating all code that uses any ANSI code.

scripts/_common.py Outdated Show resolved Hide resolved
Copy link
Member

@vitorhcl vitorhcl left a comment

Choose a reason for hiding this comment

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

Now we use pathlib, it's easy to resolve relative paths to absolute paths.

This allow us to remove the dependency on the current directory, specially on the stage function.

BTW, adding tests for _common.py was an excellent idea. Good choice on pytest, too :)

scripts/_common.py Outdated Show resolved Hide resolved
scripts/_common.py Outdated Show resolved Hide resolved
scripts/_common.py Outdated Show resolved Hide resolved
scripts/_common.py Outdated Show resolved Hide resolved
scripts/_common.py Outdated Show resolved Hide resolved
Copy link
Member

@vitorhcl vitorhcl left a comment

Choose a reason for hiding this comment

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

scripts/set-alias-page.py Outdated Show resolved Hide resolved
scripts/set-more-info-link.py Outdated Show resolved Hide resolved
@sebastiaanspeck sebastiaanspeck marked this pull request as ready for review May 13, 2024 21:16
@kbdharun kbdharun self-assigned this May 14, 2024
Copy link
Member

@vitorhcl vitorhcl left a comment

Choose a reason for hiding this comment

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

A minor suggestion on the get_tldr_root error message that makes it clearer for anyone not used with environment variables, allowing them to search for the term.

scripts/_common.py Outdated Show resolved Hide resolved
Copy link
Member

@vitorhcl vitorhcl left a comment

Choose a reason for hiding this comment

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

Now that we use absolute paths in stage(), there's no reason to use relative paths in these places.

Obviously, we need to update the variable names and not take the relative path

scripts/set-alias-page.py Outdated Show resolved Hide resolved
scripts/set-alias-page.py Outdated Show resolved Hide resolved
scripts/set-more-info-link.py Outdated Show resolved Hide resolved
scripts/set-more-info-link.py Outdated Show resolved Hide resolved
scripts/set-page-title.py Outdated Show resolved Hide resolved
scripts/set-page-title.py Outdated Show resolved Hide resolved
scripts/set-page-title.py Outdated Show resolved Hide resolved
scripts/set-more-info-link.py Outdated Show resolved Hide resolved
Co-authored-by: Vítor Henrique <87824454+vitorhcl@users.noreply.github.com>
Copy link
Member

@kbdharun kbdharun left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your contribution. Tested all the changes locally.

@kbdharun kbdharun requested a review from vitorhcl May 17, 2024 16:38
@github-actions github-actions bot added the documentation Issues/PRs modifying the documentation. label May 17, 2024
Copy link
Member

@vitorhcl vitorhcl left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for your contribution.

@kbdharun kbdharun merged commit dff913f into tldr-pages:main May 18, 2024
4 checks passed
@sebastiaanspeck sebastiaanspeck deleted the common-python-script branch May 18, 2024 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues/PRs modifying the documentation. tooling Helper tools, scripts and automated processes.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants