Skip to content

RO-crate content appear in the nf-core lint warning if there is a TODO #3493

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

Open
wants to merge 58 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
f9ab845
rocrate readme sync
ningyuxin1999 Mar 17, 2025
e2e5285
merge branch 'main' into dev-sync
ningyuxin1999 Mar 17, 2025
a728a47
final test done
ningyuxin1999 Mar 24, 2025
7b23550
Merge branch 'dev' into dev-sync
ningyuxin1999 Mar 24, 2025
4989b14
failing tests
ningyuxin1999 Mar 24, 2025
51e183c
Merge remote-tracking branch 'upstream/dev' into dev-sync
ningyuxin1999 Mar 24, 2025
70cc699
Merge branch 'dev-sync' of https://github.com/ningyuxin1999/tools int…
ningyuxin1999 Mar 24, 2025
c76713d
fix the script
ningyuxin1999 Mar 24, 2025
409f75c
api update
ningyuxin1999 Mar 24, 2025
e76ec56
prettier
ningyuxin1999 Mar 24, 2025
eb0dd5b
Merge branch 'dev' into dev-sync
ningyuxin1999 Mar 24, 2025
bcd16e1
test
ningyuxin1999 Mar 24, 2025
36a75ea
format
ningyuxin1999 Mar 24, 2025
0e04e7f
testscript
ningyuxin1999 Mar 24, 2025
21c5c8d
raise error when script fails
ningyuxin1999 Mar 24, 2025
3f98c1d
Merge branch 'dev' into dev-sync
ningyuxin1999 Mar 25, 2025
338f2c1
json error
ningyuxin1999 Mar 25, 2025
cd83b0d
Update nf_core/pipelines/lint/pipeline_todos.py
ningyuxin1999 Mar 25, 2025
1699e58
Update nf_core/pipelines/lint/rocrate_readme_sync.py
ningyuxin1999 Mar 25, 2025
7949ccf
Update nf_core/pipelines/lint/rocrate_readme_sync.py
ningyuxin1999 Mar 25, 2025
1f3d232
Update nf_core/pipelines/lint/rocrate_readme_sync.py
ningyuxin1999 Mar 25, 2025
8a7791c
comments
ningyuxin1999 Mar 25, 2025
4f31887
Merge branch 'dev' into dev-sync
ningyuxin1999 Mar 25, 2025
4738e75
test update
ningyuxin1999 Mar 25, 2025
71ad2f2
testupdate
ningyuxin1999 Mar 25, 2025
e4d17d0
Merge branch 'dev' into dev-sync
ningyuxin1999 Mar 26, 2025
7c2ac08
Merge branch 'dev' into dev-sync
ningyuxin1999 Apr 8, 2025
5edf7ea
add fixed, could_fix vars
ningyuxin1999 Apr 9, 2025
5f491fc
precommit
ningyuxin1999 Apr 9, 2025
0a52fe5
Update docs/api/_src/pipeline_lint_tests/rocrate_readme_sync.md
ningyuxin1999 Apr 10, 2025
9e9a963
Update CHANGELOG.md
ningyuxin1999 Apr 10, 2025
fe2e66c
precommit
ningyuxin1999 Apr 10, 2025
38c2e96
Merge branch 'dev-sync' of https://github.com/ningyuxin1999/tools int…
ningyuxin1999 Apr 10, 2025
266d11a
Update nf_core/pipelines/lint/rocrate_readme_sync.py
ningyuxin1999 Apr 10, 2025
1432568
add non-empty rocrate
ningyuxin1999 Apr 10, 2025
1ebfa9a
name
ningyuxin1999 Apr 10, 2025
6aff97e
option
ningyuxin1999 Apr 10, 2025
7fc6fda
fixignore
ningyuxin1999 Apr 10, 2025
91e6914
fixlabel
ningyuxin1999 Apr 10, 2025
ea586e7
fix
ningyuxin1999 Apr 11, 2025
5358d84
add test to utils
ningyuxin1999 Apr 15, 2025
7c29f9b
Merge branch 'dev' into dev-sync
mashehu Apr 15, 2025
43df8a3
Update nf_core/pipelines/lint/rocrate_readme_sync.py
ningyuxin1999 Apr 16, 2025
644553a
Update nf_core/pipelines/lint/rocrate_readme_sync.py
ningyuxin1999 Apr 16, 2025
43f030d
Update nf_core/pipelines/lint/rocrate_readme_sync.py
ningyuxin1999 Apr 16, 2025
ec9cbc4
Update nf_core/pipelines/lint/rocrate_readme_sync.py
ningyuxin1999 Apr 16, 2025
5e6eb12
Update nf_core/pipelines/lint/rocrate_readme_sync.py
ningyuxin1999 Apr 16, 2025
108f659
Merge branch 'dev' into dev-sync
ningyuxin1999 Apr 16, 2025
146e68b
add test, remove --fix in git action
ningyuxin1999 Apr 16, 2025
7e26eec
add description directly when there is no description key found
ningyuxin1999 Apr 16, 2025
1ffc229
restructure
ningyuxin1999 Apr 17, 2025
4df9af0
test
ningyuxin1999 Apr 17, 2025
4713d10
Merge branch 'dev' into dev-sync
ningyuxin1999 Apr 17, 2025
975f834
Update tests/pipelines/lint/test_rocrate_readme_sync.py
ningyuxin1999 Apr 17, 2025
5d8045a
json load in test scripts
ningyuxin1999 Apr 17, 2025
fefac22
no need add the ro-crate manually
mashehu Apr 24, 2025
6f3bb3b
fix sed command to handle TODO statements inside singe-line json entries
mashehu Apr 24, 2025
5b2f18f
Merge branch 'dev' into dev-sync
mashehu Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
- Fix: linting with comments after the input directive ([#3458](https://github.com/nf-core/tools/pull/3458))
- EDAM ontology fixes ([#3460](https://github.com/nf-core/tools/pull/3460))
- Fix default linting of nf-core components when `nf-core pipelines lint` is ran ([#3480](https://github.com/nf-core/tools/pull/3480))
- Fix the unexpected warning and sychronize the README.md and RO-crate-metadata.json
([#3493](https://github.com/nf-core/tools/pull/3493))
- Adapt the linter to the new notation used to include the centralized nf-core configs ([#3491](https://github.com/nf-core/tools/pull/3491))

### Modules
Expand Down
1 change: 1 addition & 0 deletions docs/api/_src/pipeline_lint_tests/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [pipeline_todos](./pipeline_todos/)
- [plugin_includes](./plugin_includes/)
- [readme](./readme/)
- [rocrate_readme_sync](./rocrate_readme_sync/)
- [schema_description](./schema_description/)
- [schema_lint](./schema_lint/)
- [schema_params](./schema_params/)
Expand Down
5 changes: 5 additions & 0 deletions docs/api/_src/pipeline_lint_tests/rocrate_readme_sync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# rocrate_readme_sync

```{eval-rst}
.. automethod:: nf_core.pipelines.lint.PipelineLint.rocrate_readme_sync
```
4 changes: 4 additions & 0 deletions nf_core/pipelines/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from .pipeline_todos import pipeline_todos
from .plugin_includes import plugin_includes
from .readme import readme
from .rocrate_readme_sync import rocrate_readme_sync
from .schema_description import schema_description
from .schema_lint import schema_lint
from .schema_params import schema_params
Expand Down Expand Up @@ -104,6 +105,8 @@ class PipelineLint(nf_core.utils.Pipeline):
schema_lint = schema_lint
schema_params = schema_params
system_exit = system_exit
rocrate_readme_sync = rocrate_readme_sync

template_strings = template_strings
version_consistency = version_consistency
included_configs = included_configs
Expand Down Expand Up @@ -160,6 +163,7 @@ def _get_all_lint_tests(release_mode):
"base_config",
"modules_config",
"nfcore_yml",
"rocrate_readme_sync",
] + (["version_consistency", "included_configs"] if release_mode else [])

def _load(self) -> bool:
Expand Down
3 changes: 2 additions & 1 deletion nf_core/pipelines/lint/pipeline_todos.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def pipeline_todos(self, root_dir=None):
if root_dir is None:
root_dir = self.wf_path

ignore = [".git"]
# Ignore ro-crate-metadata.json to avoid warnings when TODOs are not deleted.
ignore = [".git", "ro-crate-metadata.json"]
if Path(root_dir, ".gitignore").is_file():
with open(Path(root_dir, ".gitignore"), encoding="latin1") as fh:
for line in fh:
Expand Down
70 changes: 70 additions & 0 deletions nf_core/pipelines/lint/rocrate_readme_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import json
import logging
from pathlib import Path

log = logging.getLogger(__name__)


def rocrate_readme_sync(self):
"""
Check if the RO-Crate description in ro-crate-metadata.json matches the README.md content.
If the --fix is set, the RO-Crate description will be updated to match the README.md content.
"""

passed = []
failed = []
ignored = []
fixed = []
could_fix: bool = False

# Check if the file exists before trying to load it
metadata_file = Path(self.wf_path, "ro-crate-metadata.json")
readme_file = Path(self.wf_path, "README.md")

# Only proceed if both files exist
if not (metadata_file.exists() and readme_file.exists()):
if not metadata_file.exists():
ignored.append("`ro-crate-metadata.json` not found")
if not readme_file.exists():
ignored.append("`README.md` not found")
return {"passed": passed, "failed": failed, "ignored": ignored}

try:
metadata_content = metadata_file.read_text(encoding="utf-8")
metadata_dict = json.loads(metadata_content)
except json.JSONDecodeError as e:
log.error("Failed to decode JSON from `ro-crate-metadata.json`: %s", e)
ignored.append("Invalid JSON in ro-crate-metadata.json")
return {"passed": passed, "failed": failed, "ignored": ignored}

graph = metadata_dict.get("@graph")
if not graph or not isinstance(graph, list) or not graph[0] or not isinstance(graph[0], dict):
ignored.append("Invalid RO-Crate metadata structure.")
else:
# Check if the 'description' key is present
if "description" not in graph[0]:
ignored.append(
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 not true that the test is ignored if there isn't a description no? If I am following correctly you assign an empty string and the test will run and fail if the README has a description

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for mentioning that! I changed it to simply coping the content from the readme file to the ro-crate-metadata if there's no 'description' key. Another general question would be how to handle these failed tests when it failed the ignored tests? For example this one:

Run no-core --verbose --log-file log.txt --hide-progress pipelines lint --dir nf-core-testpipeline --fail-ignored --fail-warned

Copy link
Member

Choose a reason for hiding this comment

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

In the tests we are creating an empty ro-crate file (here). I think if we run nf-core pipelines ro-crate instead, the tests will pass

"No description found in ro-crate-metadata.json, add a description to the RO-Crate metadata."
)
graph[0]["description"] = " "
rc_description_graph = metadata_dict.get("@graph", [{}])[0].get("description")

readme_content = readme_file.read_text(encoding="utf-8")

# Compare the two strings and add a linting error if they don't match
if readme_content != rc_description_graph:
# If the --fix flag is set, you could overwrite the RO-Crate description with the README content:
if "rocrate_readme_sync" in self.fix:
metadata_dict.get("@graph")[0]["description"] = readme_content
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
metadata_dict.get("@graph")[0]["description"] = readme_content
if "description" not in graph[0]:
graph[0]["description"] = readme_content
fixed.append(
"Fixed: add the same description from `README.md` to the RO-Crate metadata."
)
return {"passed": passed, "failed": failed, "ignored": ignored, "fixed": fixed, "could_fix": could_fix}
metadata_dict.get("@graph")[0]["description"] = readme_content

with metadata_file.open("w", encoding="utf-8") as f:
json.dump(metadata_dict, f, indent=4)
passed.append("RO-Crate description matches the README.md.")
fixed.append("Mismatch fixed: RO-Crate description updated from README.md.")
else:
failed.append(
"The RO-Crate descriptions do not match the README.md content. Use `nf-core lint --fix` to update."
)
could_fix = True
else:
passed.append("RO-Crate descriptions are in sync with README.md.")
return {"passed": passed, "failed": failed, "ignored": ignored, "fixed": fixed, "could_fix": could_fix}
26 changes: 26 additions & 0 deletions tests/pipelines/lint/test_rocrate_readme_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pathlib import Path

from ..test_lint import TestLint


class TestLintROcrateReadmeSync(TestLint):
def test_rocrate_readme_sync_pass(self):
self.lint_obj._load()
results = self.lint_obj.rocrate_readme_sync()
assert len(results.get("warned", [])) == 0
assert len(results.get("failed", [])) == 0
assert len(results.get("passed", [])) > 0

def test_rocrate_readme_sync_fail(self):
self.lint_obj._load()

json_path = Path(self.lint_obj.wf_path, "ro-crate-metadata.json")
with open(json_path, "w") as f:
f.write("{}")

results = self.lint_obj.rocrate_readme_sync()
assert len(results.get("failed", [])) == 1
assert (
"The RO-Crate descriptions do not match the README.md content. Use `nf-core lint --fix` to update."
in results.get("failed", [])
)
Loading