cape.convert1to2: Utilities to modify CAPE 1.x scripts to 2.0¶
This module provides utilities to modify programs that used the CAPE 1.x API to ones that will work with CAPE 2.0 and beyond. The primary change between the two versions of CAPE is that many modules have been renamed in order to simplify the structure of the package.
The upgrade from CAPE 1.2 to 2.0 does not actually entail a major change in the underlying function and code of the package, but programs (e.g. what CAPE calls “hooks”) may fail without changing many import statements.
- cape.convert1to2.rewrite_imports(infile: str, modnames: dict, outfile: str | None = None)¶
Rewrite imports for a collection of module name changes
- cape.convert1to2.sub_imports(content: str, modnames: dict) str¶
Rewrite imports for a collection of module name changes
- cape.convert1to2.sub_modname(content: str, mod1: str, mod2: str) str¶
Replace imports of mod1 with imports of mod2
There are some imports that will not get updated properly when mod1 and mod2 are not of the same depth. For example, updating
cape.cntl->cape.cfdx.cntlwill work for most imports, but it won’t proper changefrom ..cntl import Cntl
to
from ..cfdx.cntl import Cntl
Such cases should be limited to CAPE-internal functions, so this limitation should not affect external users’ hook functions or other scripts and modules.
- cape.convert1to2.upgrade1to2()¶
Recursively update imports in Python files found w/i current dir
- Call:
>>> upgrade1to2()