Skip to content

🔧 Centralise sphinx env data access (and add schemas) #987

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

Merged
merged 2 commits into from
Aug 28, 2023

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Aug 25, 2023

The sphinx-needs data stored on the Sphinx BuildEnvironment is currently difficult to interpret and work with,
since the dynamic nature of BuildEnvironment provides no type safety or static introspection.

This PR intends to centralise access to sphinx-needs data, via sphinx_needs.data.SphinxNeedsData, which is a thin wrapper around the sphinx BuildEnvironment, to define and provide type safe access to the sphinx-need specific data.

TypedDict are used to type annotate the dictionary keys for the different data types,
and thus sphinx_needs.data essentially provides a schema for the data that sphinx-needs stores.

This is a non-breaking change, since all data can still be accessed via the sphinx BuildEnvironment, (although this is now discouraged).


Note, this is intended as a step toward making the package type checked, since at present, although mypy is used, almost every module is set to be ignored (see pyproject.toml)

@chrisjsewell chrisjsewell marked this pull request as ready for review August 25, 2023 20:13
@chrisjsewell chrisjsewell requested a review from danwos August 25, 2023 20:15
@chrisjsewell chrisjsewell changed the title 🔧 Centralise sphinx environment data access 🔧 Centralise sphinx env data access (and add schemas) Aug 26, 2023
Copy link
Member

@danwos danwos left a comment

Choose a reason for hiding this comment

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

Wow, that is not a small change.
Thanks for it. Looks good for me. 👍

@chrisjsewell chrisjsewell merged commit 9ca4e23 into master Aug 28, 2023
@chrisjsewell chrisjsewell deleted the typing1 branch August 28, 2023 06:21
chrisjsewell added a commit that referenced this pull request Aug 29, 2023
This PR adds strict typing to most of the package, building on #987 and #998 to try to confine use of dynamic types to a small surface area.
This hopefully makes it easier for developers to navigate the code base, and lessens the potential for bugs arising from type mismatches.

---

There are still some open questions, particularly around `NeedsInfoType`, which

1. has some dynamic fields (such as user defined links/options) and,
2. has some fields which are only set after post-transforms (such `process_need_nodes`)
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