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

Rudimentary support for assets #975

Merged
merged 8 commits into from Jul 4, 2023
Merged

Rudimentary support for assets #975

merged 8 commits into from Jul 4, 2023

Conversation

trefis
Copy link
Contributor

@trefis trefis commented Jun 22, 2023

Context: #59 , #972

No support for referring to assets yet.
This only provides a way to get odoc to place them "in the right place" in the directory structure; so it's only marginally useful.

Current interface:

  • children given to odoc compile can now be of the form asset-filename
  • html-generate and html-targets commands now accept --asset FILE arguments, which are paired (based on filename) with the relevant child asset. Warnings are emitted for unknown and missing assets.
  • files passed to html-generate through --asset are copied in the directory of their parent; would it be better to put them in an _assets subdirectory?

This is illustrated in test/pages/assets.t/run.t

@trefis trefis requested review from dbuenzli and panglesd June 22, 2023 15:54
Comment on lines 387 to 388
| { iv = `AssetFile (p, _name); _ } ->
let page = Path.from_identifier p in
Ok { page; kind = `File; anchor = "" }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied what was done for `SourcePage here, but honestly it looks weird.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it the anchor = "" which is bothering you?

For some reason, "no anchor" is represented as "empty anchor". The type Url.t is even defined as Anchor.t. See any identifier which is a page, and thus has no anchor (Page, LeafPage, Root, ...)

So that's correct, but I agree it would look better if the anchor field was an option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it the anchor = "" which is bothering you?

No, it's that we're getting a url to the parent of the asset, not the asset itself.

Copy link
Collaborator

@panglesd panglesd Jun 28, 2023

Choose a reason for hiding this comment

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

Indeed, that's a bug, thanks for spotting it! It was not harmful because we only call Path.from_identifier on the `SourcePage variant, never Anchor.from_identifier.

Suggested change
| { iv = `AssetFile (p, _name); _ } ->
let page = Path.from_identifier p in
Ok { page; kind = `File; anchor = "" }
| { iv = `AssetFile _; _ } as p ->
let page = Path.from_identifier p in
Ok { page; kind = `File; anchor = "" }

Could you correct SourcePage and SourceDir as well?

src/document/url.mli Outdated Show resolved Hide resolved
src/model/paths.ml Outdated Show resolved Hide resolved
Comment on lines +37 to +38
File "img.jpg":
Warning: asset is missing.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wondered if this should have been a fatal error, since I didn't know how to make it be one I managed to convince myself that it shouldn't be.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think odoc tries to avoid failing too badly in case of errors.

So I don't think it should be a hard failure, but that should not stop processing the other assets (see above)

Copy link
Collaborator

@panglesd panglesd left a comment

Choose a reason for hiding this comment

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

Nice!
I'm not sure why assets could not be children of compilation unit. But that should not be a too restrictive restriction, so I'm happy with it!
The only thing I would like to see changed is the non-handling of other assets in case of a missing asset.

src/document/url.mli Outdated Show resolved Hide resolved
Comment on lines 387 to 388
| { iv = `AssetFile (p, _name); _ } ->
let page = Path.from_identifier p in
Ok { page; kind = `File; anchor = "" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it the anchor = "" which is bothering you?

For some reason, "no anchor" is represented as "empty anchor". The type Url.t is even defined as Anchor.t. See any identifier which is a page, and thus has no anchor (Page, LeafPage, Root, ...)

So that's correct, but I agree it would look better if the anchor field was an option.

src/model/paths.ml Outdated Show resolved Hide resolved
src/model_desc/paths_desc.ml Outdated Show resolved Hide resolved
src/odoc/html_page.ml Outdated Show resolved Hide resolved
src/odoc/html_page.ml Outdated Show resolved Hide resolved
Comment on lines +37 to +38
File "img.jpg":
Warning: asset is missing.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think odoc tries to avoid failing too badly in case of errors.

So I don't think it should be a hard failure, but that should not stop processing the other assets (see above)

@panglesd
Copy link
Collaborator

Also, there are compatibility issues that would need to be taken care of...

@dbuenzli
Copy link
Contributor

What's the story from a user and driver (say odig which works out of installs) perspective ?

@trefis
Copy link
Contributor Author

trefis commented Jun 27, 2023

What's the story from a user and driver (say odig which works out of installs) perspective ?

I guess that's still open?
In the absence of references to / lookup for assets it would indeed be best if the various drivers used the same convention for picking the parents of their asset, but this PR isn't prescriptive in any way in that regard.

I do hope we can add references to assets in the not too distant future to make this question disappear, in the meantime my intuition is that right now the easiest is probably to use the "package root" as parent of the assets.

Does that somewhat answer your question, or did I totally miss your point?

@dbuenzli
Copy link
Contributor

In the absence of references to / lookup for assets it would indeed be best if the various drivers used the same convention for picking the parents of their asset, but this PR isn't prescriptive in any way in that regard.

And yet that's what we need. It was already decided to not prescribe anything for the parent/child relationship and as I suggested at that the time that's not a good idea. We could have had perfectly self-described documents but are moving away from that more and more.

Look at what happend with upstream not prescribing anything for libraries: eco-system mess. Now odoc is perpetuating this.

@trefis
Copy link
Contributor Author

trefis commented Jul 4, 2023

It was already decided to not prescribe anything for the parent/child relationship and as I suggested at that the time that's not a good idea. We could have had perfectly self-described documents but are moving away from that more and more.

I get your point. However, after years of being away from odoc and having not been involved in this decision, I just came back for this "small" PR.
I do not plan to try and argue against decisions which have been made years ago, and certainly not in a PR like this one.

That being said:

  • I hope this PR will still be beneficial to you, and to everyone else
  • while odoc itself isn't prescriptive, other tools can and will be; in particular dune (and probably odig) and we are the ones who will write the behavior there, so if you have a precise proposal/request now is still a good time to make it known (or repeat it).

@panglesd
Copy link
Collaborator

panglesd commented Jul 4, 2023

I agree that the decision to make odoc more prescriptive is out of the scope of this PR, which just adds support for assets in a way that conforms to the current state of odoc.

The code looks good, let's merge, thanks @trefis!

@panglesd panglesd merged commit 6f72b2d into ocaml:master Jul 4, 2023
2 of 3 checks passed
@trefis trefis deleted the assets branch July 4, 2023 15:18
@dbuenzli
Copy link
Contributor

dbuenzli commented Jul 4, 2023

  • while odoc itself isn't prescriptive, other tools can and will be; in particular dune (and probably odig) and we are the ones who will write the behavior there, so if you have a precise proposal/request now is still a good time to make it known (or repeat it).

This has been written for ages here and it's mentioned in #59. Interacting with this project remains as frustrating as ever I have to say.

@panglesd panglesd mentioned this pull request Sep 20, 2023
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.

None yet

3 participants