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

✨ Add ids option for needimport #1292

Merged
merged 2 commits into from
Sep 13, 2024
Merged

✨ Add ids option for needimport #1292

merged 2 commits into from
Sep 13, 2024

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Sep 10, 2024

A more performant alternative to the filter option.

This PR also adds some other performance optimisations;
caching the schema load and not reading the import file twice (during validation)

Also, add to and improve the needimport tests

@chrisjsewell chrisjsewell requested a review from danwos September 10, 2024 10:45
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.86%. Comparing base (4e10030) to head (f5acade).
Report is 91 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1292      +/-   ##
==========================================
- Coverage   86.87%   86.86%   -0.02%     
==========================================
  Files          56       60       +4     
  Lines        6532     6914     +382     
==========================================
+ Hits         5675     6006     +331     
- Misses        857      908      +51     
Flag Coverage Δ
pytests 86.86% <100.00%> (-0.02%) ⬇️

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

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

A more performant alternative to the `filter` option.

Also, add and to improve the `needimport` tests
try:
with open(correct_need_import_path) as needs_file:
needs_import_list = json.load(needs_file)
except json.JSONDecodeError as e:
Copy link
Member

Choose a reason for hiding this comment

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

OSError should also be caught, but there is already a TODO

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member Author

Choose a reason for hiding this comment

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

(knowing what exceptions to handle is always a pain, I was reading this with interest recently https://discuss.python.org/t/extend-type-hints-to-cover-exceptions/23788/51)

@@ -146,6 +143,13 @@ def run(self) -> Sequence[nodes.Node]:

needs_config = NeedsSphinxConfig(self.config)
data = needs_import_list["versions"][version]

if ids := self.options.get("ids"):
id_list = [i.strip() for i in ids.split(",") if i.strip()]
Copy link
Member

Choose a reason for hiding this comment

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

Can IDs contain a dynamic function, so you would have to use the 'split with dyn' function?

Copy link
Member Author

@chrisjsewell chrisjsewell Sep 13, 2024

Choose a reason for hiding this comment

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

oh no definitely not, no dynamic functions here; this is intended for fast filtering

need["tags"] = need["tags"] + tags
if tags := [
tag.strip()
for tag in re.split("[;,]", self.options.get("tags", ""))
Copy link
Member

Choose a reason for hiding this comment

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

same here, the new function should be used (or is that in a different open PR?)

Copy link
Member Author

Choose a reason for hiding this comment

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

this was already existing, but again no dynamic functions.
I feel you are confusing this directive with a need declaration directive, that is the only place we use dynamic functions in the directive options

Copy link
Member

@ubmarco ubmarco left a comment

Choose a reason for hiding this comment

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

Thanks for the PR

@chrisjsewell chrisjsewell merged commit 2ff14e7 into master Sep 13, 2024
18 checks passed
@chrisjsewell chrisjsewell deleted the needimport-ids branch September 13, 2024 12:59
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