Skip to content

os.rel / os.sub should accept a "." #381

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

Open
lefou opened this issue Apr 2, 2025 · 1 comment · May be fixed by #382
Open

os.rel / os.sub should accept a "." #381

lefou opened this issue Apr 2, 2025 · 1 comment · May be fixed by #382

Comments

@lefou
Copy link
Member

lefou commented Apr 2, 2025

This limitation is hitting Mill in its Task.Source which is accepting a os.SubPath. Since the idea is to provide a directory relative to an implicitly provided base directory, it is currently not possible to refer to that exact same directory without using it explicitly.

Definition of Task.Source:

inline def Source(inline value: os.SubPath)(implicit inline ctx: mill.define.Ctx)

While specifying a sub-directory works:

Task.Source("src")

Using the base dir does not:

Task.Source(".")

//           |Task.Source(".")
//
// [error]   │             ^^^
// [error]   │Exception occurred while executing macro expansion.
// [error]   │os.PathError$InvalidSegment: [.] is not a valid path segment. Literal path sequence [.] doesn't affect path being formed, please remove it
// [error]   │     at os.PathError$InvalidSegment$.apply(Path.scala:268)
// [error]   │     at os.PathChunk$.segmentsFromStringLiteralValidation(Path.scala:43)
// [error]   │     at os.Macros$.stringSubPathValidatedImpl(Macros.scala:58)
@lefou lefou linked a pull request Apr 3, 2025 that will close this issue
lefou added a commit to lefou/os-lib that referenced this issue Apr 3, 2025
@lefou
Copy link
Member Author

lefou commented Apr 3, 2025

I think the original use case in Mill is valid, while a proper support in OS-Lib is probably not the right approach. I did a experimental POC PR #382. I looks like enabling the literal "." would also allow it when composing paths via segments. E.g. the following would be no longer an error: root / "src" / ".", which is IMHO not a design goal of os.Path.

lefou added a commit to lefou/os-lib that referenced this issue Apr 3, 2025
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 a pull request may close this issue.

1 participant