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

[SCHEMA] Reorganize schema code into a package #892

Merged
merged 38 commits into from
Jan 5, 2022

Conversation

tsalo
Copy link
Member

@tsalo tsalo commented Oct 7, 2021

This stems from #885 (comment). The idea is to make the schema code operate as a proper Python package, so we can also start writing tests for it.

We still may want to move schema-related code into a different repository at some point (e.g., bids-schema, pybids), but for now I'd just like to have the code organized nicely within this repo.

Changes proposed:

  • Reorganize schemacode into a Python package, so that it can be installed and tests can be written for it.
    • This involves symlinking the schema files in src/schema to tools/schemacode/schemacode/data/schema. Thanks to @effigies for that.
  • Write a few initial tests for schemacode. These can be improved in future PRs.
  • Add a GitHub Action to run continuous integration for the new package and upload a coverage report to CodeCov.
  • Add new schema-related folders to the CODEOWNERS file with myself listed.

@tsalo
Copy link
Member Author

tsalo commented Oct 11, 2021

I'm not sure why mkdocs has such a hard time tracking down the schema files in CircleCI. It works fine locally...

EDIT: Of course, it's because, now that schemacode is a package, it's stored in site-packages, away from the rest of the repo!

@tsalo
Copy link
Member Author

tsalo commented Oct 17, 2021

My main blocker at the moment is that, as a package, schemacode will end up in site-packages instead of with the bids-specification files. As a result, relative paths to the schema files (which are in src/schema and not tools/schemacode) will break when schemacode is installed. I don't know how to work around that without creating a copy of the schema files in schemacode, which would make it hard to test out changes to the schema.

@effigies
Copy link
Collaborator

@tsalo Made several updates. RTD is fixed. The PDF build looks like it needs updating to new modules. I assume you'll be able to figure that out faster than me, but let me know if you want me to tackle it.

@tsalo
Copy link
Member Author

tsalo commented Dec 15, 2021

Thanks @effigies! How does it work? It looks like the schema files are duplicated in tools/schemacode/schemacode/data/schema/. Are those files updated automatically when the files in src/schema/ are updated?

@effigies
Copy link
Collaborator

effigies commented Dec 15, 2021

It's just a symlink, so they will be copied into the package. If you're going to develop, it probably makes sense to pip install -e so you can keep using the symlink, rather than a frozen snapshot from install time. But from a CI build perspective, it's all based on the current commit, so fine to freeze.

@tsalo
Copy link
Member Author

tsalo commented Dec 15, 2021

Awesome! I fixed the module paths, so I think everything is good to go.

@tsalo tsalo marked this pull request as ready for review December 15, 2021 17:08
@tsalo tsalo requested a review from bendhouseart December 17, 2021 15:58
@tsalo
Copy link
Member Author

tsalo commented Dec 17, 2021

@bendhouseart sorry for not requesting your review earlier. I know you wanted to take a look, though we didn't end up trying out poetry.

Copy link
Member

@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.

I believe that the messed up links only appear in HTML comments in the built site.

I see :| but it's still annoying to have linkchecker now fail until we release ...

But that's not a blocker for this PR, which I approve of!

Copy link
Collaborator

@yarikoptic yarikoptic left a comment

Choose a reason for hiding this comment

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

just some minor comments/suggestions - ok to ignore

tools/schemacode/setup.cfg Show resolved Hide resolved
.github/workflows/schemacode_ci.yml Outdated Show resolved Hide resolved
.github/workflows/schemacode_ci.yml Show resolved Hide resolved
@sappelhoff
Copy link
Member

I believe that the messed up links only appear in HTML comments in the built site.

I see :| but it's still annoying to have linkchecker now fail until we release ...

We could add a small Python script that checks whether the current commit is tagged (=stable), or not (=dev), and then in CI before building with mkdocs, that Python scripts changes stable to latest in the following line:

site_url: https://bids-specification.readthedocs.io/en/stable/

🤔 or would we screw up search engine results with that? I am not very familiar with "canonical URL" metadata in HTML headers.

@tsalo
Copy link
Member Author

tsalo commented Dec 20, 2021

We could add a small Python script that checks whether the current commit is tagged (=stable), or not (=dev), and then in CI before building with mkdocs, that Python scripts changes stable to latest

I have no clue if that's possible, but having the ability to update content files with Python scripts within CI would be really useful for adding tooltips (#954). The problem I have been bumping into for that is that the macros-generated content is not available for the auto-linked tooltips to grab onto. Generating the glossary within CI would circumvent that issue, I believe.

That said, I don't even know where to start to do it.

Copy link
Collaborator

@bendhouseart bendhouseart left a comment

Choose a reason for hiding this comment

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

Looked over the changed files and managed to build and install locally w/ setup.py 👍. I'd call it good to go.

Python 3.9.9 (main, Nov 21 2021, 03:22:47)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import schemacode
>>>

@bendhouseart
Copy link
Collaborator

CircleCI disagrees, but eh.

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.

Looks good. A couple bits of code caught my eye as likely able to be simplified. I haven't tested though...

tools/schemacode/schemacode/schema.py Outdated Show resolved Hide resolved
tools/schemacode/schemacode/schema.py Outdated Show resolved Hide resolved
tools/schemacode/schemacode/schema.py Outdated Show resolved Hide resolved
tsalo and others added 2 commits January 5, 2022 12:32
Thanks for the suggestions!

Co-authored-by: Chris Markiewicz <[email protected]>
@tsalo
Copy link
Member Author

tsalo commented Jan 5, 2022

The built site looks good to me, as does the PDF. Now that we have two approvals, is this alright to merge or do we want to wait 5 days?

Also, thank you to @effigies and @bendhouseart for your reviews!

@effigies effigies merged commit 9d31e2d into bids-standard:master Jan 5, 2022
@effigies
Copy link
Collaborator

effigies commented Jan 5, 2022

The 5 days is more for semantic changes than infrastructure.

@tsalo tsalo deleted the schema-package branch January 5, 2022 17:55
@tsalo tsalo added the schema-code Updates or changes to the code used to parse, filter, and render the schema. label Apr 11, 2022
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. schema-code Updates or changes to the code used to parse, filter, and render the schema.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants