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

Bundle path handling in ts_utils.paths #12805

Merged
merged 6 commits into from
Oct 17, 2024
Merged

Bundle path handling in ts_utils.paths #12805

merged 6 commits into from
Oct 17, 2024

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Oct 14, 2024

Use relative paths, which allows running scripts in any working directory.

srittau and others added 2 commits October 14, 2024 21:14
Use relative paths, which allows running scripts in any working directory.
from pathlib import Path
from typing import Final

TS_BASE_PATH: Final = Path(__file__).parent.parent.parent.relative_to(Path.cwd(), walk_up=True)
Copy link
Member

Choose a reason for hiding this comment

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

walk_up=True is new in 3.12; it might be too early to require 3.12 here?

I think an alternative would be:

Suggested change
TS_BASE_PATH: Final = Path(__file__).parent.parent.parent.relative_to(Path.cwd(), walk_up=True)
TS_BASE_PATH: Final = Path(__file__).parent.parent.parent.resolve().relative_to(Path.cwd())

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

resolve() won't help as Path(__file__) is already absolute. I'll just skip the walk_up on Python < 3.12. This means, it's not possible to run the scripts from sub-directories, but that's the status quo anyway.

@srittau
Copy link
Collaborator Author

srittau commented Oct 14, 2024

I guess that using -e to install ts_utils breaks type checking ...

@srittau
Copy link
Collaborator Author

srittau commented Oct 15, 2024

I've used non-relative paths for now. I still think it makes sense to bundle all path handling in one file and we are prepared for relative paths once we solve the problem of determining where the typeshed directory lives.

@srittau srittau merged commit 2d0f6d8 into python:main Oct 17, 2024
67 checks passed
@srittau srittau deleted the rel-paths branch October 17, 2024 06:16
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.

2 participants