8000 Cleanup metadata.py by danielhollas · Pull Request #526 · aiidalab/aiidalab · GitHub
[go: up one dir, main page]

Skip to content

Cleanup metadata.py - #526

Merged
danielhollas merged 14 commits into
mainfrom
cleanup-citations
Sep 30, 2026
Merged

danielhollas merged 14 commits into
mainfrom
cleanup-citations

Conversation

@danielhollas
@danielhollas danielhollas commented Aug 18, 2026 •
Copy link
Copy Markdown
Contributor

A bit of a refactor of metadata.py, mostly for the purpose of better type safety (utilizing MetadataDict type more).

@danielhollas danielhollas self-assigned this Aug 18, 2026
@danielhollas danielhollas added the bug Something isn't working label Aug 18, 2026
@codecov
codecov Bot commented Aug 18, 2026 •
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.35%. Comparing base (2bd167c) to head (42b86a0).

Files with missing lines Patch % Lines
aiidalab/app.py 33.33% 2 Missing ⚠️
aiidalab/utils.py 60.00% 2 Missing ⚠️
aiidalab/__main__.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #526      +/-   ##
==========================================
+ Coverage   74.09%   74.35%   +0.26%     
==========================================
  Files          18       18              
  Lines        1733     1735       +2     
==========================================
+ Hits         1284     1290       +6     
+ Misses        449      445       -4     
Flag Coverage Δ
py-3.12 74.35% <91.66%> (+0.26%) ⬆️
py-3.9 74.35% <91.66%> (+0.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread aiidalab/metadata.py
10000
yield key.strip(), value.strip()


@dataclass
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These dataclasses were just moved up

@danielhollas danielhollas changed the title WIP: Improve citations metadata validation Cleanup metadata.py Aug 27, 2026
@danielhollas danielhollas removed the bug Something isn't working label Aug 27, 2026
Comment thread aiidalab/metadata.py Resolved
Comment thread aiidalab/metadata.py Resolved
@danielhollas
danielhollas commented Sep 24, 2026 •
Copy link
Copy Markdown
Contributor Author

@edan-bainglass this is still a draft because I want to add a bunch of tests, but could you please review? Also, could you try initiating a review from copilot, I am curious.

Note, this is just a refactor PR. In a follow-up I'd like to improve the citations parsing / validation.

@edan-bainglass edan-bainglass left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@edan-bainglass
Copy link
Copy Markdown
Member

Hmm, there may be a regression after all. Have a closer look at the change from Metadata.parse() to Metadata.from_path(). Metadata.from_path() now raises ValueError when the repo exists but no setup.cfg is present, while the old Metadata.parse() path tolerated that case and returned empty/default metadata. In parse_app_repo() the error is only caught as TypeError (aiidalab/utils.py:102-107), so parsing a valid repo without metadata can now crash instead of falling back to metadata_fallback.

@danielhollas
danielhollas marked this pull request as ready for review September 29, 2026 15:36
Comment thread aiidalab/metadata.py
yield "categories", categories

citations = aiidalab.get("citations", metadata_pep426.get("citations"))
citation_string = aiidalab.get("citations", metadata_pep426.get("citations"))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

citations field is specific to AiiDAlab, I don't think we should be trying to read it from metadata table (setuptools would probably not be happy with that). I'll fix this in a separate PR.

@danielhollas
Copy link
Copy Markdown
Contributor Author

Hmm, there may be a regression after all. Have a closer look at the change from Metadata.parse() to Metadata.from_path(). Metadata.from_path() now raises ValueError when the repo exists but no setup.cfg is present, while the old Metadata.parse() path tolerated that case and returned empty/default metadata. In parse_app_repo() the error is only caught as TypeError (aiidalab/utils.py:102-107), so parsing a valid repo without metadata can now crash instead of falling back to metadata_fallback.

So this was more subtle and took me a while to disentagle. I don't think the original code handled the case of no setup.cfg, it would raise TypeError because the returned empty dict was being passed to the Metadata constructor, and "title" and "description" fields are not optional.

I've had Claude to write a bunch of unit tests, and then I ran them on main branch to ensure they pass, and fixed things accordingly. We now do raise a ValueError instead of TypeError when no setup.cfg is present, but I made sure all callers catch it (and there was an error path raising ValueError already so they already should have been doing that).

The new tests also uncovered some strange edge cases which I don't think are handled correctly, but I'll handle them in follow-up PRs.

@edan-bainglass please take a look.

@edan-bainglass edan-bainglass left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @danielhollas! This is very nice! Better typing, metadata parsing/validation, and exception handling (e.g., missing config file). I truly hope this is the last we here of this part of the code for some time (other than the already stacked #540) 😅

@danielhollas
danielhollas merged commit 663f9d4 into main Sep 30, 2026
9 checks passed
@danielhollas
danielhollas deleted the cleanup-citations branch September 30, 2026 10:08
@edan-bainglass
Copy link
Copy Markdown
Member

Hi @danielhollas. Sorry, having a closer look at this as a reference for another matter, and I'm noticing that the citation dataclasses are no longer being used in the code? Is this correct? I see that they are still used for validation in the schemas. Could you clarify? 🙂🙏

@danielhollas
Copy link
Copy Markdown
Contributor Author

What do you mean by "no longer"? They were not used even before this PR --- this is what I was mentioning that the citations are not being validated when read from setup.cfg. the schema validation only happens during registry build (afaik).

I will fix this in a follow up, hopefully today.

@edan-bainglass
Copy link
Copy Markdown
Member

What do you mean by "no longer"? They were not used even before this PR --- this is what I was mentioning that the citations are not being validated when read from setup.cfg. the schema validation only happens during registry build (afaik).

I will fix this in a follow up, hopefully today.

Sorry, yes, Not "no longer" 😅 They were used only to generate the schemas, which remains now. But as a validation in the code itself. I was under the impression that was part of the work. But if this is reserved for a follow up, or clearly deemed as not required, no problem 🙂

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.

2 participants

0