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

Move common utility functions to a common library #12773

Merged
merged 6 commits into from
Oct 14, 2024
Merged

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Oct 10, 2024

Prerequisite for #12772

Unfortunately, this is a bit hacky, but I don't have a better idea.

@@ -162,7 +162,7 @@ extra-standard-library = [
"pyexpat",
"zoneinfo",
]
known-first-party = ["_metadata", "_utils"]
known-first-party = ["ts_utils", "_utils"]
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove _utils?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, there's still a scripts/sync_protobuf/_utils.py file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

tbf I only named it _utils to reflect this config, and as it is right know, it wouldn't even affect the order as those scripts are only using stdlib.

I also see no issue moving or renaming scripts/sync_protobuf/_utils.py if that's wanted.

@@ -22,8 +22,11 @@
import tomli
from packaging.requirements import Requirement

from _metadata import PackageDependencies, get_recursive_requirements, read_metadata
from _utils import (
sys.path += ["lib"]
Copy link
Member

Choose a reason for hiding this comment

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

This is pretty unfortunate, and also seems to create a dependency on the working directory from which the code is invoked. Could we instead add pyproject.toml to the lib directory to make it installable, then add it as a local dependency to requirements.txt?

Copy link
Collaborator Author

@srittau srittau Oct 11, 2024

Choose a reason for hiding this comment

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

Another option is to use Path(__file__).parent.parent / "lib". On the other hand, most scripts already assume that they're called from the root typeshed directory, as they are using Path("stubs") and similar constructs.

I'm open to all three solutions (pyproject.toml, just "lib", using Path(__file__)).

Copy link
Collaborator

@Avasam Avasam Oct 11, 2024

Choose a reason for hiding this comment

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

Personally I'd rather scripts be agnostics of their working directory when possible.

Jelle's suggestions sounds clean to me and reflects what I'm used to do and see in monorepo JS/TS projects with a shared library (using npm workspaces). If you're actively modifying lib/ts_utils, you could editable install it.

@srittau
Copy link
Collaborator Author

srittau commented Oct 13, 2024

Third-party test failure is unrelated (gdb).

Copy link
Collaborator

@Avasam Avasam left a comment

Choose a reason for hiding this comment

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

Personally I'm happy with this

@srittau srittau merged commit 1fa4986 into python:main Oct 14, 2024
98 of 99 checks passed
@srittau srittau deleted the lib branch October 14, 2024 06:00
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