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

[INFRA] fix spec-internal links from schema entries #1056

Closed
wants to merge 22 commits into from

Conversation

sappelhoff
Copy link
Member

@sappelhoff sappelhoff commented Apr 9, 2022

update the new way works, see comments further below.

fixed for:

  • env.macro(macros.make_glossary, "MACROS___make_glossary")
  • env.macro(macros.make_suffix_table, "MACROS___make_suffix_table")
  • env.macro(macros.make_metadata_table, "MACROS___make_metadata_table")
  • env.macro(macros.make_columns_table, "MACROS___make_columns_table")

attempt to implement solution for #974

This doesn't work as I expected, because (I think) two passes to render macros would be needed:

  1. to paste a schema entry into a table
  2. to change a link within that pasted table

Currently only step 1. happens, and step 2. remains unresolved, with the {{ xxx }} schema syntax in the table. I guess this was to be expected - do you have an idea how to circumvent this with the existing infrastructure @tsalo?

Another way I can think of is to make this "link fixing" a special citizen in the form of a python script that we run on the built files (after mkdocs build).

src/03-modality-agnostic-files.md Show resolved Hide resolved
src/03-modality-agnostic-files.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Apr 9, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.10%. Comparing base (e140f35) to head (29e9ca5).
Report is 1423 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1056      +/-   ##
==========================================
+ Coverage   70.53%   72.10%   +1.56%     
==========================================
  Files           9        9              
  Lines         930      950      +20     
==========================================
+ Hits          656      685      +29     
+ Misses        274      265       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member Author

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

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

Okay, I got a new idea that I pushed in d0bea64

Basically:

  • whenever we specify a macro, we add an optional input relpath
  • relpath is a string containing the relative path to /src (the root of the spec)
  • E.g., for src/03-modality-agnostic-files.md, we have relpath="."
  • links in the schema are then specified as if directly relative to /src ... that is: [Units](/02-common-principles.html#units) becomes [Units](REPLACEME/02-common-principles.md#units)
  • the REPLACEME gets replaced with relpath during the macrocall

This does work locally ... not sure if it'll pass CI, because we'd also have to fix it in the glossary etc.

Consider this a proof of concept -- what are your thoughts?

EDIT: As expected, the CI fails due to warnings about the glossary (we run in strict mode, we warnings = failure). However, you can inspect the CircleCI artifacts, see: https://output.circle-artifacts.com/output/job/c904e3d6-4744-4642-8790-daf6eb0cbf57/artifacts/0/dev_docs/03-modality-agnostic-files.html#scans-file ... the first link to Units in the acq_time metadata is the link as it is currently ... the second one is using the fix described above.

@tsalo tsalo added the schema Issues related to the YAML schema representation of the specification. Patch version release. label Apr 12, 2022
@sappelhoff
Copy link
Member Author

As evident from the last few commits I am just going ahead with my plan. I think it might also be easier to review if you see all the required changes in front of you, instead of thinking about it conceptually

@sappelhoff sappelhoff marked this pull request as ready for review April 26, 2022 10:32
Copy link
Member Author

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

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

@VisLab you can see the build artifact of this PR and check that the links work again once the fixes here are applied: https://bids-specification--1056.org.readthedocs.build/en/1056/

Copy link
Collaborator

@effigies effigies left a comment

Choose a reason for hiding this comment

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

This all seems reasonable. Some nit-picky questions/suggestions.

tools/schemacode/schemacode/render.py Outdated Show resolved Hide resolved
tools/schemacode/schemacode/render.py Outdated Show resolved Hide resolved
src/02-common-principles.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@ericearl ericearl left a comment

Choose a reason for hiding this comment

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

@sappelhoff @effigies

If this works and looks good (I don't know how/where to look at the render, but I trust @sappelhoff has already viewed it), then I am in favor of putting it in there since it works.

I feel like the ideal solution just involves using python's os.walk() method looking for the referenced files "PATH_TO_SRC" automatically by exact basename (this assumes we don't have two files with the same names inside any of the .MD files). And pair that with the os.path.relpath() method to get the relative path within the repo from there. This would save anyone having to specify these extra "relpath" things that might be technical debt in the future.

Copy link
Member Author

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

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

okay, the new way works and looks prettier and has lower maintenance burden (always using page.file instead of manually inserting a relative path).

BUT it doesn't work for the PDF build. I'll see if I can fix it.

@sappelhoff
Copy link
Member Author

everything works now, ready for a new review. Thanks for the previous round -- I think it's better now.

Copy link
Collaborator

@ericearl ericearl left a comment

Choose a reason for hiding this comment

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

Great updates! Nice work and thanks.

Copy link
Collaborator

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Does the job. Small suggestions, and one probably ill-advised idea for extracting the filename in the macro functions, rather than repeatedly throughout the source.

Comment on lines +125 to +128
if page_file is not None:
relpath = os.sep.join([".."] * page_file.src_path.count(os.sep))
relpath = "." if not relpath else relpath
obj_desc = obj_desc.replace("SPEC_ROOT", relpath)
Copy link
Collaborator

@effigies effigies Apr 27, 2022

Choose a reason for hiding this comment

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

This could be refactored rather than repeated 4 times. It's also duplicating some stdlib behavior.

import posixpath

def get_relpath(src_path):
    """ Retrieve relative path to the source root from the perspective of a Markdown file

    Examples
    --------
    >>> get_relpath("02-common-principles.md")
    '.'
    >>> get_relpath("04-modality-specific-files/01-magnetic-resonance-imaging-data.md")
    '..'
    >>> get_relpath("we/lack/third_levels.md")
    '../..'
    """
    return posixpath.relpath(".", posixpath.dirname(src_path))
Suggested change
if page_file is not None:
relpath = os.sep.join([".."] * page_file.src_path.count(os.sep))
relpath = "." if not relpath else relpath
obj_desc = obj_desc.replace("SPEC_ROOT", relpath)
if page_file is not None:
obj_desc = obj_desc.replace("SPEC_ROOT", get_relpath(page_file.src_path))

@@ -486,7 +486,8 @@ and a guide for using macros can be found at
"Units": "RECOMMENDED",
"TermURL": "RECOMMENDED",
"HED": "OPTIONAL",
}
},
page.file
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was kind of hoping just to make it implicit. It looks like you found where the information can be grabbed from, so if we're up for some deep magic of inspecting the call stack and extracting variables, I could make a PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems doable (#1096). Some cleanup needed if we do want to go that route.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the proposal - I like it and commented there. If others agree I am happy to close this PR and let #1096 take over.



test_file = TestFile()
test_file.src_path = os.sep.join(["try", "this", "dict"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
test_file.src_path = os.sep.join(["try", "this", "dict"])
test_file.src_path = os.path.join("try", "this", "dict")

@sappelhoff sappelhoff marked this pull request as draft April 29, 2022 06:39
@sappelhoff sappelhoff deleted the links/schema branch July 20, 2022 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
schema Issues related to the YAML schema representation of the specification. Patch version release.
Projects
None yet
5 participants