-
Notifications
You must be signed in to change notification settings - Fork 169
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
There was a problem hiding this 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 haverelpath="."
- 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 withrelpath
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.
8b90267
to
dcda5eb
Compare
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 |
f89aa5c
to
f04bfac
Compare
There was a problem hiding this 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/
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this 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.
everything works now, ready for a new review. Thanks for the previous round -- I think it's better now. |
There was a problem hiding this 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.
There was a problem hiding this 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.
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) |
There was a problem hiding this comment.
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))
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_file.src_path = os.sep.join(["try", "this", "dict"]) | |
test_file.src_path = os.path.join("try", "this", "dict") |
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:
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
).