Skip to content

Commit

Permalink
Python 3.12 support / imp module deleted (#1669)
Browse files Browse the repository at this point in the history
* Add python 3.12 to CI matrix

Signed-off-by: Evan Blaudy <[email protected]>

* Stop using imp module it's deprecated since python 3.4 and removed in python 3.12

Signed-off-by: Evan Blaudy <[email protected]>

* Fix AttributeError: 'VendorImporter' object has no attribute '_path' in Python 3.12 for autogen_serialized_datamodel.py

Signed-off-by: Evan Blaudy <[email protected]>

* Update pybind11 submodule to latest tag (v2.11.1)

Signed-off-by: Evan Blaudy <[email protected]>

* Fix opentimelineio.url_utils.filepath_from_url for windows URL in python 3.12

Signed-off-by: Evan Blaudy <[email protected]>

* In python-package.yml workflow upgrade pypa/cibuildwheel to v2.16.2 to support python 3.12

Signed-off-by: Evan Blaudy <[email protected]>

---------

Signed-off-by: Evan Blaudy <[email protected]>
  • Loading branch information
EvanBldy authored Jan 24, 2024
1 parent d98f657 commit 7302ff1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
include:
- { os: ubuntu-latest, shell: bash }
- { os: macos-latest, shell: bash }
Expand Down Expand Up @@ -163,12 +163,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-build: ['cp37*', 'cp38*', 'cp39*', 'cp310*', 'cp311*']
python-build: ['cp37*', 'cp38*', 'cp39*', 'cp310*', 'cp311*', 'cp312*']
steps:
- uses: actions/checkout@v3

- name: Build wheels (Python 3)
uses: pypa/cibuildwheel@v2.11.1
uses: pypa/cibuildwheel@v2.16.2
with:
output-dir: wheelhouse
env:
Expand Down
2 changes: 1 addition & 1 deletion src/deps/pybind11
Submodule pybind11 updated 75 files
+72 −16 .github/workflows/ci.yml
+13 −5 .github/workflows/configure.yml
+3 −0 .github/workflows/format.yml
+5 −0 .github/workflows/labeler.yml
+6 −2 .github/workflows/pip.yml
+15 −11 .github/workflows/upstream.yml
+54 −50 .pre-commit-config.yaml
+7 −5 CMakeLists.txt
+1 −1 MANIFEST.in
+1 −1 README.rst
+13 −0 SECURITY.md
+7 −3 docs/advanced/cast/strings.rst
+1 −1 docs/advanced/embedding.rst
+98 −4 docs/changelog.rst
+14 −0 docs/classes.rst
+6 −3 docs/compiling.rst
+2 −1 docs/faq.rst
+6 −4 docs/release.rst
+14 −0 docs/upgrade.rst
+14 −2 include/pybind11/attr.h
+16 −1 include/pybind11/buffer_info.h
+35 −3 include/pybind11/cast.h
+17 −7 include/pybind11/detail/common.h
+2 −2 include/pybind11/detail/init.h
+2 −1 include/pybind11/detail/internals.h
+184 −26 include/pybind11/detail/type_caster_base.h
+9 −0 include/pybind11/eigen/common.h
+13 −0 include/pybind11/eigen/matrix.h
+5 −0 include/pybind11/eigen/tensor.h
+12 −6 include/pybind11/numpy.h
+14 −6 include/pybind11/pybind11.h
+99 −29 include/pybind11/pytypes.h
+4 −4 include/pybind11/stl.h
+5 −3 include/pybind11/stl_bind.h
+61 −0 include/pybind11/type_caster_pyobject_ptr.h
+1 −1 pybind11/_version.py
+4 −9 pybind11/setup_helpers.py
+11 −8 pyproject.toml
+1 −0 setup.cfg
+1 −1 setup.py
+8 −7 tests/CMakeLists.txt
+3 −0 tests/extra_python_package/test_files.py
+1 −1 tests/requirements.txt
+35 −0 tests/test_buffers.cpp
+57 −0 tests/test_buffers.py
+1 −1 tests/test_class.cpp
+0 −3 tests/test_cmake_build/CMakeLists.txt
+4 −4 tests/test_cmake_build/installed_embed/CMakeLists.txt
+4 −4 tests/test_cmake_build/installed_function/CMakeLists.txt
+4 −4 tests/test_cmake_build/installed_target/CMakeLists.txt
+4 −4 tests/test_cmake_build/subdirectory_embed/CMakeLists.txt
+4 −4 tests/test_cmake_build/subdirectory_function/CMakeLists.txt
+4 −4 tests/test_cmake_build/subdirectory_target/CMakeLists.txt
+238 −0 tests/test_copy_move.cpp
+28 −8 tests/test_exceptions.py
+29 −29 tests/test_iostream.py
+34 −0 tests/test_methods_and_attributes.cpp
+9 −0 tests/test_methods_and_attributes.py
+26 −0 tests/test_numpy_array.cpp
+71 −0 tests/test_numpy_array.py
+9 −0 tests/test_pytypes.cpp
+14 −1 tests/test_pytypes.py
+6 −3 tests/test_stl.py
+44 −0 tests/test_stl_binders.cpp
+18 −0 tests/test_stl_binders.py
+130 −0 tests/test_type_caster_pyobject_ptr.cpp
+104 −0 tests/test_type_caster_pyobject_ptr.py
+38 −0 tests/test_unnamed_namespace_a.cpp
+34 −0 tests/test_unnamed_namespace_a.py
+13 −0 tests/test_unnamed_namespace_b.cpp
+5 −0 tests/test_unnamed_namespace_b.py
+54 −0 tests/test_vector_unique_ptr_member.cpp
+14 −0 tests/test_vector_unique_ptr_member.py
+18 −8 tools/pybind11Common.cmake
+3 −1 tools/pybind11Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def _generate_model_for_module(mod, classes, modules):
if (
inspect.ismodule(thing)
and thing not in modules
and "opentimelineio" in thing.__name__
and all(not thing.__name__.startswith(t) for t in SKIP_MODULES)
)
),
Expand Down
30 changes: 16 additions & 14 deletions src/py-opentimelineio/opentimelineio/plugins/python_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"""Base class for OTIO plugins that are exposed by manifests."""

import os
import imp
import inspect
import collections
import copy
import importlib.util

from .. import (
core,
Expand Down Expand Up @@ -107,21 +107,23 @@ def module_abs_path(self):
def _imported_module(self, namespace):
"""Load the module this plugin points at."""

pyname = os.path.splitext(os.path.basename(self.module_abs_path()))[0]
pydir = os.path.dirname(self.module_abs_path())

(file_obj, pathname, description) = imp.find_module(pyname, [pydir])

with file_obj:
# this will reload the module if it has already been loaded.
mod = imp.load_module(
f"opentimelineio.{namespace}.{self.name}",
file_obj,
pathname,
description
module_name = f"opentimelineio.{namespace}.{self.name}"
try:
# Attempt to import the module using importlib first
mod = importlib.import_module(module_name)
except ImportError:
# If the module couldn't be imported, import it manually
pyname = os.path.splitext(os.path.basename(self.module_abs_path()))[0]
pydir = os.path.dirname(self.module_abs_path())
spec = importlib.util.spec_from_file_location(
module_name,
os.path.join(pydir, f"{pyname}.py"),
)

return mod
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)

return mod

def module(self):
"""Return the module object for this adapter. """
Expand Down
13 changes: 7 additions & 6 deletions src/py-opentimelineio/opentimelineio/url_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
request
)
from pathlib import (
Path,
PureWindowsPath
PurePath,
PureWindowsPath,
PurePosixPath
)


Expand All @@ -21,7 +22,7 @@ def url_from_filepath(fpath):
try:
# appears to handle absolute windows paths better, which are absolute
# and start with a drive letter.
return urlparse.unquote(Path(fpath).as_uri())
return urlparse.unquote(PurePath(fpath).as_uri())
except ValueError:
# scheme is "file" for absolute paths, else ""
scheme = "file" if os.path.isabs(fpath) else ""
Expand Down Expand Up @@ -56,16 +57,16 @@ def filepath_from_url(urlstr):
parsed_result = urlparse.urlparse(urlstr)

# Convert the parsed URL to a path
filepath = Path(request.url2pathname(parsed_result.path))
filepath = PurePath(request.url2pathname(parsed_result.path))

# If the network location is a window drive, reassemble the path
if PureWindowsPath(parsed_result.netloc).drive:
filepath = Path(parsed_result.netloc + parsed_result.path)
filepath = PurePath(parsed_result.netloc + parsed_result.path)

# Otherwise check if the specified index is a windows drive, then offset the path
elif PureWindowsPath(filepath.parts[1]).drive:
# Remove leading "/" if/when `request.url2pathname` yields "/S:/path/file.ext"
filepath = filepath.relative_to(filepath.root)
filepath = PurePosixPath(*filepath.parts[1:])

# Convert "\" to "/" if needed
return filepath.as_posix()

0 comments on commit 7302ff1

Please sign in to comment.