Skip to content

build: refactor configure.py - #47323

Closed
VoltrexKeyva wants to merge 1 commit into
nodejs:mainfrom
VoltrexKeyva:refact-conf
Closed

build: refactor configure.py#47323
VoltrexKeyva wants to merge 1 commit into
nodejs:mainfrom
VoltrexKeyva:refact-conf

Conversation

@VoltrexKeyva

@VoltrexKeyvaVoltrexKeyva commented Mar 30, 2023

Copy link
Copy Markdown
Contributor
  • Explicitly specify the encoding when opening files.
  • Use f-strings to format strings.
  • Use isinstance() for type checks instead of type().
  • Use the with keyword for resource-allocating operations.
  • Avoid using multiple statements in a single line.
  • Remove unnecessary else clauses after return.
  • Iterate with the items() method of dictionaries when both the key and value are used.
  • Remove unnecessary parentheses.
  • Rename unused unpacked variables to _, _1, etc etc.
  • Rename the list variable to avoid conflict with the global list() function.
  • Remove unused path parameter of the icu_download() function.
  • Use the pathlib library for paths instead of os.path.

@nodejs-github-botnodejs-github-bot added build Issues and PRs related to build files or the CI. needs-ci PRs that need a full CI run. labels Mar 30, 2023
@VoltrexKeyva

Copy link
Copy Markdown
ContributorAuthor

Note that the tests are failing because the packaging library is not installed, I'm not sure where to add the command to install it so that it applies to all the tests that run configure.py.

@VoltrexKeyva
VoltrexKeyvaforce-pushed the refact-conf branch 2 times, most recently from 762c432 to 14b08f7CompareMarch 30, 2023 17:32
@richardlau

Copy link
Copy Markdown
Member

FWIW some previous discussion in #42186. packaging not being part of the Python stdlib is going to be a pain for everyone/new contributors.

@TrottTrott added the python PRs and issues that require attention from people who are familiar with Python. label Mar 30, 2023
@VoltrexKeyva

Copy link
Copy Markdown
ContributorAuthor

packaging not being part of the Python stdlib is going to be a pain for everyone/new contributors.

I'm not sure about that, we'll have to switch either way though we could make our own class/function implementing version parsing but it's too much work for the simple use cases here, so I'd say we should make the move to the packaging library, and of course, add it to the build instructions if automatic installation is not a preferable choice.

Comment threadconfigure.py Outdated
@VoltrexKeyva
VoltrexKeyvaforce-pushed the refact-conf branch 3 times, most recently from f2d5605 to e6931deCompareApril 5, 2023 14:23
Comment threadconfigure.py Outdated
Comment on lines 1637 to 1631

@VoltrexKeyvaVoltrexKeyvaApr 5, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure about this change, the path parameter of the icu_download() function was never used (not inside the function I mean), not even from the day it was added.

But an argument to the path parameter is being passed here:

localzip=icu_download(icu_full_path)

even though it's not used inside the icu_download() function, is this a mistake or was it supposed to be used?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 Let's revert this change and put a # noqa here to placate the linter.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Why should we revert this? Do you want me to make this change in a separate PR?

@targos

Copy link
Copy Markdown
Member

@nodejs/python

@targos
targos removed their request for review April 12, 2023 08:19
Comment threadconfigure.py Outdated

@cclausscclauss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a legacy codebase that a lot of folks depend on so we want to keep any possible breakage to a minimum. Here are some ideas...

Also, I would like to land #47519 before we land this so we have some stronger guardrails in place.

Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
Comment on lines 1637 to 1631

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 Let's revert this change and put a # noqa here to placate the linter.

Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
@VoltrexKeyva
VoltrexKeyvaforce-pushed the refact-conf branch 2 times, most recently from ed5706f to 89e91edCompareApril 15, 2023 10:07
@VoltrexKeyva

This comment was marked as outdated.

@VoltrexKeyva
VoltrexKeyvaforce-pushed the refact-conf branch 3 times, most recently from edf05e6 to ff0ff9bCompareApril 16, 2023 10:08

@cclausscclauss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

more ideas

I know we are only changing a single file but it is a vital file and I do not know if it has enough tests... Perhaps we should introduce these changes in multiple PRs. Your thoughts on test coverage?

Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
Comment threadconfigure.py Outdated
@VoltrexKeyva
VoltrexKeyvaforce-pushed the refact-conf branch 2 times, most recently from dec8698 to f3c8e7fCompareApril 16, 2023 11:23
- Explicitly specify the encoding when opening files.
- Use f-strings to format strings.
- Use `isinstance()` for type checks instead of `type()`.
- Use the `with` keyword for resource-allocating operations.
- Avoid using multiple statements in a single line.
- Remove unnecessary `else` clauses after `return`.
- Iterate with the `items()` method of dictionaries when both the key
and value are used.
- Remove unnecessary parentheses.
- Rename unused unpacked variables to `_`, `_1`, etc etc.
- Rename the `list` variable to avoid conflict with the global
`list()` function.
- Remove unused `path` parameter of the `icu_download()` function.
- Use the `pathlib` library for paths instead of `os.path`.
@VoltrexKeyva

Copy link
Copy Markdown
ContributorAuthor

Perhaps we should introduce these changes in multiple PRs.

I'm fine with that, should I introduce each of these changes in separate PRs to reduce review time?

Your thoughts on test coverage?

Writing new tests for such build files sounds like a good idea, but I have no experience writing tests for such files 😅.

Comment threadconfigure.py
valid_intl_modes = ('none', 'small-icu', 'full-icu', 'system-icu')
with open ('tools/icu/icu_versions.json') as f:
icu_versions = json.load(f)
icu_versions = json.loads((tools_path / 'icu' / 'icu_versions.json').read_text())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.read_text(encoding='utf-8') is also possible.

@cclauss

cclauss commented Apr 16, 2023

Copy link
Copy Markdown
Contributor

I think we should get this PR will all changes ready and with all tests passing. Then we should have a second PR that is a strict subset of these changes. We land the second PR first and then after a release and user feedback, we rebase this PR and push the remaining into the next Node release. All the pathlib changes should land separately from all other changes. Thoughts? Or am I just being too paranoid?

@VoltrexKeyva

Copy link
Copy Markdown
ContributorAuthor

Then we should have a second PR that is a strict subset of these changes.

What changes here counts as a strict subset?

All the pathlib changes should land separately from all other changes. Thoughts? Or am I just being too paranoid?

That's a good idea.

@cclauss

Copy link
Copy Markdown
Contributor

What changes here counts as a strict subset?

The pathlib changes vs. all non-pathlib changes.

@VoltrexKeyva

Copy link
Copy Markdown
ContributorAuthor

Closing this since there are now two different PRs, one for pathlib changes (#47581) and one for non-pathlib changes (#47667).

@VoltrexKeyva
VoltrexKeyva deleted the refact-conf branch April 22, 2023 08:50
VoltrexKeyva added a commit to VoltrexKeyva/node that referenced this pull request May 2, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.
Refs: nodejs#47323 (comment)nodejs#47323 (comment)
nodejs-github-bot pushed a commit that referenced this pull request May 2, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.
Refs: #47323 (comment)#47323 (comment)
PR-URL: #47581
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
targos pushed a commit that referenced this pull request May 3, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.
Refs: #47323 (comment)#47323 (comment)
PR-URL: #47581
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
danielleadams pushed a commit that referenced this pull request Jul 6, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.
Refs: #47323 (comment)#47323 (comment)
PR-URL: #47581
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
MoLow pushed a commit to MoLow/node that referenced this pull request Jul 6, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.
Refs: nodejs#47323 (comment)nodejs#47323 (comment)
PR-URL: nodejs#47581
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
@srl295srl295 added the i18n-api Issues and PRs related to the i18n implementation. label Oct 1, 2024
@srl295

Copy link
Copy Markdown
Member

broke ICU downloading on windows (the 'path' argument is a URL or a file path) - see #55214

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

buildIssues and PRs related to build files or the CI.i18n-apiIssues and PRs related to the i18n implementation.needs-ciPRs that need a full CI run.pythonPRs and issues that require attention from people who are familiar with Python.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@VoltrexKeyva@richardlau@targos@cclauss@srl295@Trott@nodejs-github-bot