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

♻️ Store unset extra options as Undefined and remove from needs.json #1125

Closed
wants to merge 1 commit into from

Conversation

chrisjsewell
Copy link
Member

As discussed in more detail at #1082 (comment),
at present every stored need (dict) item in a project is required to have every key present.
In particular this is required so that filter strings (which are evaluated as Python code) can be evaluated for all needs; for example "xxx == 1 " would raise a NameError if xxx was not a key of the need.

As discussed also in #1122 (comment),
this has meant that currently all fields added to NEEDS_CONFIG.extra_options, are added to every need item, with a default of "".
Storing as a "" makes it difficult to tell if this was specifically set by the user or not, and consequently whether it can be removed from the needs.json

By contrast, jinja2 has the concept of https://jinja.palletsprojects.com/en/3.0.x/api/#undefined-types, by default assigned to any variable not provided as part of the context.

This PR changes the default to an Undefined instance and, when writing to a needs.json, removes and keys with this value.
As can be seen from the tests, for a standard need item, this removes 18 fields.

This solution should be "minmally breaking", in that mainly Undefined acts the same as "".
Although there may some rare exceptions, for example, the calc_sum filter function expected float(value) to raise a ValueError, but it now raises an UndefinedError.

Copy link

codecov bot commented Feb 22, 2024

Codecov Report

Attention: Patch coverage is 89.18919% with 8 lines in your changes missing coverage. Please review.

Project coverage is 85.90%. Comparing base (cf5598f) to head (2d3e785).
Report is 37 commits behind head on master.

Files Patch % Lines
sphinx_needs/api/need.py 85.71% 7 Missing ⚠️
sphinx_needs/data.py 94.73% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1125   +/-   ##
=======================================
  Coverage   85.90%   85.90%           
=======================================
  Files          56       56           
  Lines        6511     6557   +46     
=======================================
+ Hits         5593     5633   +40     
- Misses        918      924    +6     
Flag Coverage Δ
pytests 85.90% <89.18%> (+<0.01%) ⬆️

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.

@chrisjsewell
Copy link
Member Author

superceded by #1232

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