Move code around to declutter the src/python/pants directory#11458
Conversation
|
|
||
|
|
||
| def is_child_of(path: Path, directory: Path) -> bool: | ||
| abs_path = path if path.is_absolute() else directory.joinpath(path).resolve() |
There was a problem hiding this comment.
Hm this technically breaks the "no side effects" thing with the engine by calling .resolve(). It's good this is now isolated to one place at least so that we're less likely to keep using it.
There was a problem hiding this comment.
I spent a bit of time looking to see if there was a Python stdlib function that did this check for us already, but didn't find a convenient one.
There was a problem hiding this comment.
My concern is more using Path().resolve(). Ideally this function would solely use PurePath and not Path so that it didn't do any file operations. Those FS operations break the contract with the Rules API to avoid side effects.
This was a problem already before, so it's not a blocker. I'm not sure what the fix is in general, and this PR is good that it isolates this issue to only one call site.
There was a problem hiding this comment.
This should probably be implemented in terms of fast_relpath_optional.
| if len(workdir_src) > _MAX_FILENAME_LENGTH: | ||
| logger.warning( | ||
| f"The specified --pants-workdir `{workdir_src}` is longer than {_MAX_FILENAME_LENGTH}. This may be too long of a filename for some systems." | ||
| ) |
There was a problem hiding this comment.
I think this is fine, but please wait for an ack from someone else.
e64be8a to
4d2c1d7
Compare
|
|
3218b2e to
7f04c9f
Compare
So, while we should stop using Path-length and path-component-length are limited on real systems (many Docker mounts, for example), and when issues are encountered, they can break everything in surprising ways ("breaks only on my machine"). Particularly in large monorepos By "rebased directory structures", I'm referring to generating alternate destinations for a file/target like |
Makes sense. This was intended to be a quick refactor commit, and it sounds like actually getting rid of this functionality is both a good idea and would best be done in a separate chunk of work. I will put |
Mm, yea. Another reason to tackle this independently is that we now have duplicated codepaths doing this: pants/src/python/pants/build_graph/address.py Lines 301 to 318 in e9115cd |
[ci skip-rust] [ci skip-build-wheels]
lock.py is only impored from in pantsd code. Moving the file to within pantsd makes the `src/python` directory structure less cluttered. [ci skip-rust] [ci skip-build-wheels]
7f04c9f to
90cbb60
Compare
clean_global_runtime_statein lieu of calling its single line at its single callsitelock.pyinto thepantsddirectory, since it is only ever called there. This allowssrc/python/pants/processto be removed.is_child_ofand its associated test to its single callsite. This allowssrc/python/pants/fsto be removed.