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

[ENH] Add filename template legend #1219

Closed
wants to merge 29 commits into from

Conversation

Remi-Gau
Copy link
Collaborator

@Remi-Gau Remi-Gau commented Aug 17, 2022

closes #1198
fixes #1220

unrelated

  • update install of bidsschema tool via requirements
  • add black, import sort and flake8 to pre-commit config
  • run black and import sort on non schema code python
  • add setup.cfg with flake8 config in root folder to tell pre-commit what config to use

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.

could you please also remove:

pip install ~/project/tools/schemacode/[render]

and re:

maybe there is a way to make the JSON pre-commit hook ignore certain files?

@Remi-Gau
Copy link
Collaborator Author

and re:

* #1120

maybe there is a way to make the JSON pre-commit hook ignore certain files?

not for this specific hook, but will exclude the file globally in the pre-commit config
https://github.com/pre-commit/pre-commit-hooks#check-json

@codecov
Copy link

codecov bot commented Aug 17, 2022

Codecov Report

Merging #1219 (86a7c30) into master (db4b0f5) will decrease coverage by 0.06%.
The diff coverage is 81.81%.

❗ Current head 86a7c30 differs from pull request most recent head 25574bd. Consider uploading reports for the commit 25574bd to get more accurate results

@@            Coverage Diff             @@
##           master    #1219      +/-   ##
==========================================
- Coverage   88.23%   88.16%   -0.07%     
==========================================
  Files           6        6              
  Lines        1020     1031      +11     
==========================================
+ Hits          900      909       +9     
- Misses        120      122       +2     
Impacted Files Coverage Δ
tools/schemacode/bidsschematools/render.py 92.87% <81.81%> (-0.31%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Remi-Gau
Copy link
Collaborator Author

weird note: running black . (blacK 22.6) to lint all files reformat some files and this will be undone by the black pre-commit hook.

Most likely not ideal but probably best to investigate somewhere else than in this PR

Example ``` datalad run -m 'run black on all files' 'black .' [INFO ] == Command start (output follows) ===== Skipping .ipynb files as Jupyter dependencies are not installed. You can fix this by running ``pip install black[jupyter]`` reformatted tools/schemacode/bidsschematools/tests/test_rules.py reformatted tools/schemacode/bidsschematools/tests/test_render.py reformatted tools/schemacode/bidsschematools/utils.py reformatted tools/schemacode/bidsschematools/schema.py reformatted tools/schemacode/bidsschematools/tests/test_validator.py reformatted tools/schemacode/bidsschematools/render.py reformatted tools/schemacode/bidsschematools/validator.py

All done! ✨ 🍰 ✨
7 files reformatted, 18 files left unchanged.
[INFO ] == Command exit (modification check follows) =====
add(ok): tools/schemacode/bidsschematools/render.py (file)
add(ok): tools/schemacode/bidsschematools/schema.py (file)
add(ok): tools/schemacode/bidsschematools/tests/test_render.py (file)
add(ok): tools/schemacode/bidsschematools/tests/test_rules.py (file)
add(ok): tools/schemacode/bidsschematools/tests/test_validator.py (file)
add(ok): tools/schemacode/bidsschematools/utils.py (file)
add(ok): tools/schemacode/bidsschematools/validator.py (file)
Total: 0%| | 0.00/1.00 [00:00<?, ? datasets/s]CommandError: 'git -c diff.ignoreSubmodules=none commit -m '[DATALAD RUNCMD] run black on all files

=== Do not change lines below ===
{
"chain": [],
"cmd": "black .",
"exit": 0,
"extra_inputs": [],
"inputs": [],
"outputs": [],
"pwd": "."
}
^^^ Do not change lines above ^^^
' --' failed with exitcode 1 under /home/remi/github/BIDS-specification
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check json...........................................(no files to check)Skipped
check python ast.........................................................Passed
check for added large files..............................................Passed
check for case conflicts.................................................Passed
black....................................................................Failed

  • hook id: black
  • files were modified by this hook

reformatted tools/schemacode/bidsschematools/tests/test_rules.py
reformatted tools/schemacode/bidsschematools/tests/test_render.py
reformatted tools/schemacode/bidsschematools/utils.py
reformatted tools/schemacode/bidsschematools/schema.py
reformatted tools/schemacode/bidsschematools/tests/test_validator.py
reformatted tools/schemacode/bidsschematools/validator.py
reformatted tools/schemacode/bidsschematools/render.py

All done! ✨ 🍰 ✨
7 files reformatted.

flake8...................................................................Passed

</details>

@Remi-Gau
Copy link
Collaborator Author

@tsalo
when you have time could you check this weird horror that this PR is doing?

https://bids-specification--1219.org.readthedocs.build/en/1219/04-modality-specific-files/03-electroencephalography.html#eeg-recording-data

Now the filename templates include ALL datatypes everytime and the legend is rendered as codeblock. I must be missing something obvious but I can't see what.

Screenshot from 2022-08-17 11-35-27

@Remi-Gau
Copy link
Collaborator Author

Now the filename templates include ALL datatypes every time

hum this seems to actually already be the case in the live latest version:

https://bids-specification.readthedocs.io/en/latest/04-modality-specific-files/01-magnetic-resonance-imaging-data.html#anatomy-imaging-data

@tsalo
Copy link
Member

tsalo commented Aug 17, 2022

Latest looks fine to me. Never mind, I was looking at stable! 🤦 I'll try to figure out what's going on.

EDIT: My first guess is that the filter_schema function doesn't work with the new Namespace objects (see #1113).

@tsalo
Copy link
Member

tsalo commented Aug 17, 2022

I think I have the problem pinned down, but I don't have a solution yet.

The problem is that filter_schema checks for dict objects, instead of Namespace objects (which the schema now is). Changing dict below to Mapping addresses that problem.

new_schema = deepcopy(schema)
if isinstance(new_schema, dict):
# Reduce values in dict to only requested
for k, v in kwargs.items():
if k in new_schema.keys():
filtered_item = deepcopy(new_schema[k])
if isinstance(filtered_item, dict):
filtered_item = {k1: v1 for k1, v1 in filtered_item.items() if k1 in v}
else:
filtered_item = [i for i in filtered_item if i in v]
new_schema[k] = filtered_item
for k2, v2 in new_schema.items():
new_schema[k2] = filter_schema(new_schema[k2], **kwargs)
elif isinstance(new_schema, list):
for i, item in enumerate(new_schema):
if isinstance(item, dict):
new_schema[i] = filter_schema(item, **kwargs)
return new_schema

The next problem is that Namespace objects do not support item assignment, and filter_schema relies heavily on item assignment (e.g., new_schema[k] = filtered_item) to build the filtered version of the schema. I haven't figured out how to work around this. @effigies do you have any ideas for how to address the item assignment problem?

@Remi-Gau
Copy link
Collaborator Author

Thanks for looking into this.

Should we add a test to catch this in ci rather than having to manually check the rendering?

Also because running mkdocs serves takes "ages" to run locally which does not incentive to check.

@tsalo
Copy link
Member

tsalo commented Aug 17, 2022

Chris had some ideas for fixing the filter that we talked about briefly on Zoom. I'll be trying them out once I finish up with a call I'm on.

Should we add a test to catch this in ci rather than having to manually check the rendering?

We do have #788 that seems similar, but I never figured out how to actually implement it. Otherwise, I think we'll need to write unit tests for the rendering functions. I think Horea added some, but they must not be strict enough to catch this new problem.

@effigies
Copy link
Collaborator

I'll try to make a quick fix.

@effigies
Copy link
Collaborator

See #1223

@Remi-Gau
Copy link
Collaborator Author

Thanks @tsalo @effigies for looking into this and fixing all of that.

@tsalo did I miss them or are the label and index definition not in the glossary?

@Remi-Gau
Copy link
Collaborator Author

We do have #788 that seems similar, but I never figured out how to actually implement it. Otherwise, I think we'll need to write unit tests for the rendering functions. I think Horea added some, but they must not be strict enough to catch this new problem.

I may have a look into this see if I can think of something. Don't hold your breath.

@Remi-Gau Remi-Gau requested a review from effigies August 24, 2022 13:04
@Remi-Gau
Copy link
Collaborator Author

PDF and HTML now look good to me.

@Remi-Gau Remi-Gau force-pushed the add_legend branch 2 times, most recently from 1e34204 to ec9e7d8 Compare August 24, 2022 15:59
- repo: https://github.com/asottile/reorder_python_imports
rev: "v3.8.2"
hooks:
- id: reorder-python-imports
Copy link
Member

Choose a reason for hiding this comment

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

why do you prefer this over the more standard isort?

.pre-commit-config.yaml Outdated Show resolved Hide resolved
# this config is mostly there to help with the use of pre-commit
max-line-length = 110
ignore = E203,E402,E722,W503,F841
docstring-convention = numpy
Copy link
Member

Choose a reason for hiding this comment

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

I think for this to work we would need https://pypi.org/project/flake8-docstrings/ ... correct?

We could add it to requirements.txt and then also add it to the pre-commit hook like here: https://github.com/sappelhoff/pyprep/blob/25b91e098d0055f14b5cbcae54b5ee9e0739aa62/.pre-commit-config.yaml#L27

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hum...

I have been "wasting" some time because the linting rules of precommit and those of the ci the bidsschematools clashed, so more than happy to try to make them agree.

However I know hate this PR because it does too. Many. Things.

So I will remove all changes that are not related to the title of this PR and put them in a different one.

Copy link
Member

Choose a reason for hiding this comment

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

It's also fine with me to merge this as is and then iterate, no worries.

Copy link
Collaborator

Choose a reason for hiding this comment

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

setup.cfg is really meant for Python packages, which this isn't. If we're going to have it at the root, I would rather call it .flake8. See https://flake8.pycqa.org/en/latest/user/configuration.html

@Remi-Gau
Copy link
Collaborator Author

Yeah but it bothers me.

So expect a force push.

@Remi-Gau
Copy link
Collaborator Author

Yeah but it bothers me.

So expect a force push.

OK I changed my mind: no force push. With several merge of master into this, reset and sorting what belongs to this PR or to another is going to be a pain.

So I would prefer merging and fix the pre-commit config in another PR. (pragmatism beats clean commit history on this one)

@sappelhoff
Copy link
Member

So I would prefer merging and fix the pre-commit config in another PR. (pragmatism beats clean commit history on this one)

yes 👍 especially because we can squash and merge it

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.

Just to clarify - are you ready to have this merged @Remi-Gau ?

@Remi-Gau
Copy link
Collaborator Author

Just to clarify - are you ready to have this merged @Remi-Gau ?

yup if @tsalo and @effigies are OK with it

Copy link
Member

@tsalo tsalo left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. I'm happy with this as-is.

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.

TBH I'm finding this hard to review because of bundling process changes with semantic changes. I made a couple small comments regarding the render, which seems fine, and the contributing guide. If everything else is just process, that's fine.

tools/schemacode/bidsschematools/render.py Outdated Show resolved Hide resolved
tools/schemacode/bidsschematools/render.py Outdated Show resolved Hide resolved
@@ -4,4 +4,4 @@ pymdown-extensions>=7.0.0
mkdocs-branchcustomization-plugin~=0.1.3
mkdocs-macros-plugin
numpy
tools/schemacode/[render]
-e tools/schemacode/[render]
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 I suggested this, but I disagree now. This is part of the build process in RTD, and we shouldn't rely on -e.

Suggested change
-e tools/schemacode/[render]
tools/schemacode/[render]

@@ -302,7 +302,6 @@ is to use the `requirements.txt` file contained in this repository as follows:
```bash
pip install -U pip
pip install -r requirements.txt
pip install -e tools/schemacode/
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this should be restored.

@@ -24,11 +23,12 @@

def run_shell_cmd(command):
"""Run shell/bash commands passed as a string using subprocess module."""
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
process = subprocess.Popen(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are there changes in this file? Style rerender?

# this config is mostly there to help with the use of pre-commit
max-line-length = 110
ignore = E203,E402,E722,W503,F841
docstring-convention = numpy
Copy link
Collaborator

Choose a reason for hiding this comment

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

setup.cfg is really meant for Python packages, which this isn't. If we're going to have it at the root, I would rather call it .flake8. See https://flake8.pycqa.org/en/latest/user/configuration.html

@Remi-Gau
Copy link
Collaborator Author

@effigies
I can close this and start a cleaner PR, if you prefer.
This thing has become a headache to review and to work with TBF. Sorry. :-(

@effigies
Copy link
Collaborator

Sorry, I hate to be annoying, but I really would prefer to keep these things separate. If it would save you trouble, I'd be happy to unsentimentally squash what I think are the relevant changes into a single commit with you as author, and you can just review that.

@Remi-Gau
Copy link
Collaborator Author

Sorry, I hate to be annoying, but I really would prefer to keep these things separate. If it would save you trouble, I'd be happy to unsentimentally squash what I think are the relevant changes into a single commit with you as author, and you can just review that.

No worries. I was getting annoyed at how this PR was started to mix things that were unrelated but I think I gave up too quickly to sort it.

Will close and open separate PRs.

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.

broken JSON does not play well with pre-commit Add legend below filename templates
4 participants