-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Remove namespace packaging and hardcode elements #4767
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
197f8ae
Remove namespace packaging and hardcode elements
mtreinish 605e5bd
Fix lint
mtreinish addb6c0
Merge branch 'master' into namespace-no-more
mtreinish c76ac8d
Merge branch 'master' into namespace-no-more
mtreinish 90ba8c9
Merge branch 'master' into namespace-no-more
mtreinish 15d81af
Merge branch 'master' into namespace-no-more
mtreinish f1653ae
Fix lint
mtreinish 83e1be7
Handle missing ibmq in job watcher
mtreinish f757def
Suppress packaging warnings in docs job
mtreinish 76a2494
Merge branch 'master' into namespace-no-more
mtreinish 4007660
Use find_spec instead of find_module
mtreinish 033c455
Merge branch 'master' into namespace-no-more
mtreinish 7b0286e
Fix lint and remove deprecated module_repr method
mtreinish 8d77a11
Merge branch 'master' into namespace-no-more
mtreinish 4381905
Add back module_repr, pylint wants it there because of abc
mtreinish f98a159
Merge branch 'namespace-no-more' of github.com:mtreinish/qiskit-core …
mtreinish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2020. | ||
| # | ||
| # This code is licensed under the Apache License, Version 2.0. You may | ||
| # obtain a copy of this license in the LICENSE.txt file in the root directory | ||
| # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
| # | ||
| # Any modifications or derivative works of this code must retain this | ||
| # copyright notice, and modified files need to carry a notice indicating | ||
| # that they have been altered from the originals. | ||
|
|
||
| # pylint: disable=unused-argument | ||
|
|
||
| """Module for utilities to manually construct qiskit namespace""" | ||
|
|
||
| import sys | ||
| from importlib.abc import MetaPathFinder, Loader | ||
| import importlib | ||
|
|
||
|
|
||
| class QiskitLoader(Loader): | ||
| """Load qiskit element as a namespace package.""" | ||
| def __init__(self, new_package, old_namespace): | ||
| super().__init__() | ||
| self.new_package = new_package | ||
| self.old_namespace = old_namespace | ||
|
|
||
| def module_repr(self, module): | ||
| return repr(module) | ||
|
|
||
| def load_module(self, fullname): | ||
| old_name = fullname | ||
| names = fullname.split(".") | ||
| new_namespace_names = self.new_package.split('.') | ||
| old_namespace_names = self.old_namespace.split('.') | ||
| fullname = ".".join( | ||
| new_namespace_names + names[len(old_namespace_names):]) | ||
| module = importlib.import_module(fullname) | ||
| sys.modules[old_name] = module | ||
| return module | ||
|
|
||
|
|
||
| class QiskitElementImport(MetaPathFinder): | ||
| """Meta importer to enable unified qiskit namespace.""" | ||
| def __init__(self, new_package, old_namespace): | ||
| super().__init__() | ||
| self.new_package = new_package | ||
| self.old_namespace = old_namespace | ||
|
|
||
| def find_spec(self, fullname, path=None, target=None): | ||
| """Return the ModuleSpec for Qiskit element.""" | ||
| if fullname.startswith(self.old_namespace): | ||
| return importlib.util.spec_from_loader( | ||
| fullname, | ||
| QiskitLoader(self.new_package, self.old_namespace), | ||
| origin='qiskit') | ||
| return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.