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

build: refactor configure.py #47323

Closed
wants to merge 1 commit into from

Conversation

VoltrexKeyva
Copy link
Member

@VoltrexKeyva VoltrexKeyva commented Mar 30, 2023

  • 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-bot nodejs-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
Member Author

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 VoltrexKeyva force-pushed the refact-conf branch 2 times, most recently from 762c432 to 14b08f7 Compare March 30, 2023 17:32
@richardlau
Copy link
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.

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

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.

configure.py Outdated Show resolved Hide resolved
@VoltrexKeyva VoltrexKeyva force-pushed the refact-conf branch 3 times, most recently from f2d5605 to e6931de Compare April 5, 2023 14:23
configure.py Outdated
Comment on lines 1637 to 1631
def icu_download(path):
def icu_download():
Copy link
Member Author

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:

node/configure.py

Line 1819 in 069365c

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
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
Member Author

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
Member

targos commented Apr 12, 2023

@nodejs/python

@targos targos removed their request for review April 12, 2023 08:19
configure.py Outdated Show resolved Hide resolved
Copy link
Contributor

@cclauss cclauss left a comment

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.

configure.py Outdated Show resolved Hide resolved
configure.py Show resolved Hide resolved
configure.py Outdated Show resolved Hide resolved
configure.py Outdated Show resolved Hide resolved
configure.py Outdated Show resolved Hide resolved
configure.py Outdated Show resolved Hide resolved
configure.py Outdated
Comment on lines 1637 to 1631
def icu_download(path):
def icu_download():
Copy link
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.

configure.py Outdated Show resolved Hide resolved
configure.py Show resolved Hide resolved
@VoltrexKeyva VoltrexKeyva force-pushed the refact-conf branch 2 times, most recently from ed5706f to 89e91ed Compare April 15, 2023 10:07
@VoltrexKeyva

This comment was marked as outdated.

@VoltrexKeyva VoltrexKeyva force-pushed the refact-conf branch 3 times, most recently from edf05e6 to ff0ff9b Compare April 16, 2023 10:08
Copy link
Contributor

@cclauss cclauss left a comment

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?

configure.py Outdated Show resolved Hide resolved
configure.py Outdated Show resolved Hide resolved
configure.py Outdated Show resolved Hide resolved
configure.py Outdated Show resolved Hide resolved
configure.py Outdated Show resolved Hide resolved
configure.py Show resolved Hide resolved
@VoltrexKeyva VoltrexKeyva force-pushed the refact-conf branch 2 times, most recently from dec8698 to f3c8e7f Compare April 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
Member Author

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 😅.

@@ -53,8 +56,7 @@
valid_mips_fpu = ('fp32', 'fp64', 'fpxx')
valid_mips_float_abi = ('soft', 'hard')
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
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
Copy link
Contributor

cclauss commented Apr 16, 2023

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
Member Author

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
Contributor

cclauss commented Apr 16, 2023

What changes here counts as a strict subset?

The pathlib changes vs. all non-pathlib changes.

VoltrexKeyva added a commit to VoltrexKeyva/node that referenced this pull request Apr 16, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.

Refs: nodejs#47323 (comment) nodejs#47323 (comment)
VoltrexKeyva added a commit to VoltrexKeyva/node that referenced this pull request Apr 16, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.

Refs: nodejs#47323 (comment) nodejs#47323 (comment)
VoltrexKeyva added a commit to VoltrexKeyva/node that referenced this pull request Apr 17, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.

Refs: nodejs#47323 (comment) nodejs#47323 (comment)
VoltrexKeyva added a commit to VoltrexKeyva/node that referenced this pull request Apr 17, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.

Refs: nodejs#47323 (comment) nodejs#47323 (comment)
VoltrexKeyva added a commit to VoltrexKeyva/node that referenced this pull request Apr 18, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.

Refs: nodejs#47323 (comment) nodejs#47323 (comment)
VoltrexKeyva added a commit to VoltrexKeyva/node that referenced this pull request Apr 21, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.

Refs: nodejs#47323 (comment) nodejs#47323 (comment)
VoltrexKeyva added a commit to VoltrexKeyva/node that referenced this pull request Apr 21, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.

Refs: nodejs#47323 (comment) nodejs#47323 (comment)
@VoltrexKeyva
Copy link
Member Author

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 1, 2023
Use Python's `pathlib` library for paths and related operations
instead of `os.path`.

Refs: nodejs#47323 (comment) nodejs#47323 (comment)
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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. needs-ci PRs that need a full CI run. python PRs 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.

None yet

6 participants