Skip to content

Potential fix for imports #1167

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

Closed
wants to merge 4 commits into from
Closed

Conversation

jku
Copy link
Member

@jku jku commented Oct 7, 2020

Maybe fixes issue #1165 ?

This style of import:
import tuf.download
is incompatible with vendoring tool (typically vendoring modifies from X import Y into from vendored.path.X import Y but this can't be succesfully done with our style).

So I'd like to talk about changing the import style. Unfortunately just switching to the style from tuf import download means massive code churn as the local name changes from tuf.download to download: at least 700 lines of change and significant chance of namespace collision.

This PR is a exploration of another way: using package imports to keep the code mostly as is.

Description of the changes being introduced by the pull request:

  • Removes all cases of import tuf.something
  • Introduces package level default imports tuf and tuf.client, so a plain "import tuf" or "from tuf import client" is enough to get the basic imports in place with minimal changes to source code
  • Leaves repository_tool, repository_lib, developer_tool and unittest_toolbox as they are: not part of a default import set
  • leaves log out of the default import set because importing it has side-effects, and fixes the local naming issues resulting from that

This should be 100% backwards compatible: all import styles still work.
The important changes in functionality are:

  • importing any tuf module typically ends up importing one or both default sets
  • tuf.log is no longer imported uselessly in a lot of places (this should be a good thing)

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

Jussi Kukkonen added 3 commits October 7, 2020 17:43
The end goal is to get rid of imports style
    import package.module
as that is incompatible with vendoring. The secondary goal is to
preserve the ability to fully namespace things (so to use
tuf.module.something in the code).

This commit defines the basic set of library imports.
 exceptions
 formats
 keydb
 roledb
 settings
 import sig
These will be available under tuf namespace after "import tuf"

There's also a set of client imports
 download
 mirrors
These will be available under client namespace after
"from tuf import client".

These sets do not include
 log (because importing it has side effects)
 repository_tool
 repository_lib
 developer_tool

Signed-off-by: Jussi Kukkonen <[email protected]>
These changes are not required: the old forms work fine but these
changes get the tests inline with the rest of the code.

Signed-off-by: Jussi Kukkonen <[email protected]>
Importing the log module has side-effects so it does not happen
as part of the default set in __init__.py: Remove unused log imports and
update the remaining uses to "from tuf import log as tuf_log".

Signed-off-by: Jussi Kukkonen <[email protected]>
updater module cannot be included in 'client' default modules
if updater module also loads 'client' (as python2 fails to import it).

We do want to load client default modules in updater to be able to use
namespacing, e.g. client.download.safe_download().

So don't include updater in default modules: this means the examples
should use e.g.
  from tuf.client import updater
or
  from tuf.client.updater import Updater

Signed-off-by: Jussi Kukkonen <[email protected]>
@jku
Copy link
Member Author

jku commented Oct 15, 2020

closing this: it was useful as a test for the workaround I'm going to use in pip , but will never be a real solution we'd want to merge

@jku jku closed this Oct 15, 2020
@jku jku deleted the imports branch December 30, 2024 09:07
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.

1 participant