-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces deprecated module reference. We are coming up to a couple of module refactors, e.g. `cirq.experiments` -> `cirq.qcvv` and `cirq.google` -> `cirq_google`. With the functionality introduced here, we can achieve backwards compatible reference by adding a similar snippet to the one below to the original parent module's `__init__.py` file: ``` from cirq import _compat _compat.deprecated_submodule( new_module_name="cirq.experiments", old_parent="cirq", old_child="qcvv", deadline="v0.20", create_attribute=True, ) ``` Callers of all types will get a single deprecation warning. Design doc: https://tinyurl.com/cirq-deep-aliasing Extensive testing was done on the full `cirq.google` extraction - all the interesting edge cases were captured as unit tests here. Disclaimers: - the tests need to run in a separate subprocess to ensure that the import system is unaffected (I tried resetting sys.modules, and all the other entry points as a pytest fixture, but it didn't really work due to some side-effects I couldn't figure out) - thus I rolled a mechanism that plays nicely within pytest, using multiprocessing. - there is a g3 specific problem with par files as there is a specific Loader used internally for which the wrapping had to be adjusted (see _compat.py:358) - testing this proved to be hard as one would have to create a legacy module loader which provenly works - but I couldn't. So here, the testing is internal only... - while user code will still execute, PyCharm and other IDEs will likely not recognize the deprecated module references - the deprecated submodules won't show up in code completion and will look like they don't exist. Beyond maintainer review, I will also get some python experts to look at this PR and provide feedback to get a bit more confidence that this is not completely unrecommended. TODO: - [x] fix CI (coverage needs to be worked out with the subprocess separation) - [x] split out improvements to the `cirq.testing.assert_deprecated` and `_warn_or_error` method to a separate PR (done #3919) - [x] get python expert review
- Loading branch information
Showing
20 changed files
with
858 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
Oops, something went wrong.