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

[BACKPORT] Allow Task.Source/Task.Sources to be constructed directly from subpath string literals #4487

Merged
merged 4 commits into from
Feb 6, 2025

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Feb 6, 2025

First step in #4447, by providing an alternative to the previous os.Path APIs.

Effectively this allows us to replace

def mainScript = Task.Source { millSourcePath / "src/foo.py" }

with

def mainScript = Task.Source { "src/foo.py" }

Pulls in com-lihaoyi/os-lib#353 from upstream to make constructing os.SubPaths more ergonomic by eliding the lead os.sub / prefix in the case of literal strings while still maintaining a degree of safety:

  • "outer" paths starting with ..s and absolute paths starting with / are rejected at compile time
  • Only literal strings are converted implicitly, anything non-literal needs to be an explicit os.SubPath

For now we provide this as an alternative to passing in an absolute os.Path, but probably 99% of scenarios should be using this sub-path API rather than absolute paths since (a) it's more concise and (b) your sources should be within your millSourcePath anyway. I'm not sure we can get rid of the os.Path-taking API entirely, but we can definitely de-prioritize it and call it SourcesUnsafe or something so that anyone who needs it can use it but most people won't use it accidentally

@lihaoyi lihaoyi added this to the 0.12.8 milestone Feb 6, 2025
@lihaoyi lihaoyi force-pushed the subpath-sources-12 branch from d98e656 to 846521a Compare February 6, 2025 02:57
@lihaoyi lihaoyi merged commit 9aa054e into com-lihaoyi:0.12.x Feb 6, 2025
9 checks passed
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.

1 participant