Upgrade to Python 3.12
Recipe ID
org.openrewrite.python.migrate.UpgradeToPython312Artifactopenrewrite-migrate-pythonMigrate deprecated and removed APIs for Python 3.12 compatibility. This includes detecting usage of the removed imp module and other legacy modules that were removed in Python 3.12.
Composite recipepythonmigration3.12Proprietary
Usage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.python.migrate.UpgradeToPython312If the recipe isn’t available locally, install it with:
mod config recipes pip install openrewrite-migrate-pythonDefinition
This recipe runs the following recipes in order.
- Upgrade to Python 3.11
org.openrewrite.python.migrate.UpgradeToPython311 - Replace
datetime.utcnow()withdatetime.now(UTC)org.openrewrite.python.migrate.ReplaceDatetimeUtcNow - Replace
datetime.utcfromtimestamp()withdatetime.fromtimestamp(ts, UTC)org.openrewrite.python.migrate.ReplaceDatetimeUtcFromTimestamp - Replace deprecated calendar constants with uppercase
org.openrewrite.python.migrate.ReplaceCalendarConstants - Change import
org.openrewrite.python.ChangeImport - Find deprecated imp module usage
org.openrewrite.python.migrate.FindImpUsage - Replace deprecated distutils.version usage
org.openrewrite.python.migrate.ReplaceDistutilsVersion - Find deprecated distutils module usage
org.openrewrite.python.migrate.FindDistutilsUsage - Replace
pkgutil.find_loader()withimportlib.util.find_spec()org.openrewrite.python.migrate.ReplacePkgutilFindLoader - Replace
pkgutil.get_loader()withimportlib.util.find_spec()org.openrewrite.python.migrate.ReplacePkgutilGetLoader - Find deprecated
Path.link_to()usageorg.openrewrite.python.migrate.FindPathlibLinkTo - Find modules removed in Python 3.12
org.openrewrite.python.migrate.FindRemovedModules312 - Find deprecated
ssl.match_hostname()org.openrewrite.python.migrate.FindSslMatchHostname - Find deprecated
os.popen()usageorg.openrewrite.python.migrate.FindOsPopen - Find deprecated
os.spawn*()usageorg.openrewrite.python.migrate.FindOsSpawn - Find deprecated
shutil.rmtree(onerror=...)parameterorg.openrewrite.python.migrate.FindShutilRmtreeOnerror - Replace
sys.last_type/sys.last_value/sys.last_tracebackwithsys.last_excorg.openrewrite.python.migrate.ReplaceSysLastExcInfo - org.openrewrite.python.migrate.UpgradePythonVersionTo312
org.openrewrite.python.migrate.UpgradePythonVersionTo312