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

Document public API for tuf.api and tuf.ngclient #2234

Closed
wants to merge 1 commit into from

Conversation

fridex
Copy link
Contributor

@fridex fridex commented Dec 18, 2022

Description of the changes being introduced by the pull request:

Document public API for tuf.api and tuf.ngclient by declaring __all__.

@fridex
Copy link
Contributor Author

fridex commented Dec 18, 2022

It looks like this circular import causes the reported issue:

# pylint: disable=cyclic-import
# ... to allow de/serializing Metadata and Signed objects here, while also
# creating default de/serializers there (see metadata local scope imports).
# NOTE: A less desirable alternative would be to add more abstraction layers.

This will also break consumers. Moving to draft, feel free to let me know if this is something worth to have and worth to invest time.

@fridex fridex marked this pull request as draft December 18, 2022 14:06
@jku
Copy link
Member

jku commented Dec 19, 2022

I agree that there are cases where our public API is not as well defined as it could be. I don't agree with this premise: Document public API for tuf.api and tuf.ngclient by declaring __all__: I haven't checked any python best practices but this is my understanding: Defining __all__ does not define the public API. It only defines what happens when you do from <mod> import *. Things that are not part of __all__ are 100% still part of the public API, they're just not part of "*".

So:

  • I don't object to defining __all__ (I won't use it myself but nothing against it): but this does not define the python-tuf public API
  • that said, the default value for from <mod> import * is everything in the module... so is e.g. the ngclient change useful if it changes nothing?
  • we could also be more strict about what is public API in api/metadata by first defining __init__.py with the things we consider public, and later making the actual metadata.py submodule internal

@lukpueh
Copy link
Member

lukpueh commented Dec 19, 2022

@jku and I just recently talked about the lack of explicitness in our public API (secure-systems-lab/securesystemslib#456 (comment)). I am all for being more explicit.

@jku
Copy link
Member

jku commented Dec 19, 2022

Maybe a good first step is to file an issue -- as lukas said there is some consensus that API could be more strictly defined -- and maybe make proposal of the actual change (how does the API change? or are we just declaring existing API more specifically?)

@fridex
Copy link
Contributor Author

fridex commented Dec 19, 2022

__all__ is indeed used with star imports. Also, PEP-8 discusses about using it to be explicit about public interfaces, python docs talk about import statements considering also __all__.

Maybe a good first step is to file an issue

Done in #2235

@jku
Copy link
Member

jku commented Dec 27, 2022

Status update

tuf

I think we don't want anything importable at top level (apart from the modules) and nothing in __all__.

tuf.ngclient

ngclient __init__.py defines the API but the internal modules are not prefixed with an underscore so it's not crystal clear... possible further improvements:

  • export TargetFile along with Updater in ngclient/__init__.py (as it's a major part of Updater API and requires the user to do another import for no good reason)
  • rename updater.py into _updater.py (abd rename the other files as well) to make the API crystal clear

the first of those seems clearly a good idea, second is debatable: it would break someone who is now doing from tuf.ngclient.updater import Updater. Still think both are likely good ideas.

tuf.api.metadata

TODO: someone could write a proper proposal for a api/metadata/__init__.py (or maybe even api/__init__.py ?!)

tuf.repository

This small component was just added -- I did not pay too much attention on __init__.py yet

@fridex
Copy link
Contributor Author

fridex commented Jan 26, 2023

Closing this as changes in tuf.ngclient were separated in #2233 and #2279. Relevant discussion continues in #2235.

@fridex fridex closed this Jan 26, 2023
@fridex fridex deleted the public-api branch January 26, 2023 15:03
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.

3 participants