Skip to content

Commit

Permalink
WIP Python 3.12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
moreati committed Feb 8, 2024
1 parent fc3e788 commit 56b354a
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 652 deletions.
12 changes: 0 additions & 12 deletions ansible_mitogen/module_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
from __future__ import unicode_literals
__metaclass__ = type

import collections
import imp
import os

import mitogen.master
Expand All @@ -40,16 +38,6 @@
PREFIX = 'ansible.module_utils.'


# Analog of `importlib.machinery.ModuleSpec` or `pkgutil.ModuleInfo`.
# name Unqualified name of the module.
# path Filesystem path of the module.
# kind One of the constants in `imp`, as returned in `imp.find_module()`
# parent `ansible_mitogen.module_finder.Module` of parent package (if any).
#
# FIXME Python 3.12 removed `imp`, leaving no constants for `Module.kind`.
Module = collections.namedtuple('Module', 'name path kind parent')


def get_fullname(module):
"""
Reconstruct a Module's canonical path by recursing through its parents.
Expand Down
3 changes: 1 addition & 2 deletions ansible_mitogen/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
__metaclass__ = type

import atexit
import imp
import json
import os
import re
Expand Down Expand Up @@ -522,7 +521,7 @@ def load_module(self, fullname):
source = ansible_mitogen.target.get_small_file(self._context, path)
code = compile(source, path, 'exec', 0, 1)
# FIXME Python 3.12 removed `imp`
mod = sys.modules.setdefault(fullname, imp.new_module(fullname))
mod = sys.modules.setdefault(fullname, types.ModuleType(fullname))
mod.__file__ = "master:%s" % (path,)
mod.__loader__ = self
if is_pkg:
Expand Down
Loading

0 comments on commit 56b354a

Please sign in to comment.