Skip to content

URI-based dependency parsing #678

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

Conversation

straight-shoota
Copy link
Member

This proposes an alternative implementation for #673

@straight-shoota straight-shoota self-assigned this May 20, 2025
@bcardiff bcardiff merged commit 91c3656 into crystal-lang:dependency-cli-parsing May 21, 2025
8 of 9 checks passed
@straight-shoota straight-shoota deleted the refactor/dependency-cli-parsing branch May 21, 2025 19:39
case value
when .starts_with?("./"), .starts_with?("../")
Parts.new("path", Path[value].to_posix.to_s)
when .starts_with?("git@")
Copy link
Contributor

Choose a reason for hiding this comment

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

Edge case: it's the username to connect with, it doesn't have to be git.

Copy link
Member Author

@straight-shoota straight-shoota May 22, 2025

Choose a reason for hiding this comment

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

Yes of course. This is just an example for a heuristic to derive a resolver from a schemeless URI. If the username is git, it's likely a git repo.

We can do similar things for other URI components. For example, if the hostname starts with fossil., it's likely a fossil repo. If the path ends with .git it's likely a git repo.

I'm not entirely sure if we should do all those things when it's relatively simple to just provide a fully qualified URI. But it seems easy enough, shouldn't cause much issues and might improve UX in some cases.

expect_parses("file://#{local_absolute}", "path", local_absolute, Any)
# Path resolver syntax
expect_parses("path:#{local_absolute}", "path", local_absolute, Any)
expect_parses("path:#{local_relative}", "path", local_relative, Any)
# Other resolvers short
expect_parses("git:git://git.example.org/crystal-library.git", "git", "git://git.example.org/crystal-library.git", Any)
expect_parses("git+https://example.org/foo/bar", "git", "https://example.org/foo/bar", Any)
expect_parses("git:https://example.org/foo/bar", "git", "https://example.org/foo/bar", Any)
Copy link
Contributor

Choose a reason for hiding this comment

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

There are no specs for mercurial/hg or fossil URL.

else
Parts.new("git", uri.path)
end
when "git+https"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why treat git particularly, instead of <resolver>+ for fossil and mercurial?

Edge cases: what about other schemes and resolver combinations, like git+file:, fossil+http:, or hg+ssh://?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, of course. That all sounds good. This patch was really just intended to demonstrate the concept as an alternative to the original approach in #673. It certainly isn't production ready.

@ysbaddaden
Copy link
Contributor

I'm still not sure what are the acceptable formats, despite the method specs. I feel like : and + are kinda duplicates (but I'm not sure) and we should simplify to only one (+ seems to already be in used) and keep : for the shorthands, so we're coherent with SPEC:

  • <local_path> => {:path, local_path}
  • <resolver>+<url_or_path> => {resolver, url_or_path} (maybe simplify to shorthand)
  • <shorthand>:<user/repo> => {shorthand, user/repo} (to be coherent with SPEC)
  • https://<known_git_host>.+ => {:git, url} (maybe simplify to shorthand)
  • git://.+ => {:git, url} (maybe simplify to shorthand)
  • git@.+ => {:git, url}
  • file:///<path> => {:path, path} (don't think we should support)

Frankly, that's far too many cases already 😞

@straight-shoota
Copy link
Member Author

straight-shoota commented May 22, 2025

Yes, the git+https etc. schemes are well established (cf. https://pip.pypa.io/en/stable/topics/vcs-support/, https://nix.dev/manual/nix/2.28/command-ref/new-cli/nix3-flake#url-like-syntax). We should support them all.

URIs combining a resolver name with an opaque url is also coherent with SPEC. This does not apply only to shorthands. It's nice that you can always use the same notation as in shard.yml (minus the whitespace) for shards add.

We can easily generalize the mapping implementation and get rid of any special cases (see https://github.com/crystal-lang/shards/pull/673/files#r2102181386).
The only explicit URI handlers are for heuristics when the scheme is missing or inconclusive, and for mapping file to path.

I'm happy to drop all (or most) of these heuristics for the MVP. They're certainly not essential, only nice to have for a neat UX.

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