Skip to content

Commit

Permalink
Fix incompatibility with Python 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldoussoren committed Sep 24, 2022
1 parent 5ab33ae commit 4d1b791
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
5 changes: 5 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Release history
===============

0.19.3
------

* Fix incompatibility with Python 3.11

0.19.2
------

Expand Down
2 changes: 1 addition & 1 deletion modulegraph/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.19.2"
__version__ = "0.19.3"
8 changes: 7 additions & 1 deletion modulegraph/modulegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2209,8 +2209,14 @@ def _replace_paths_in_code(self, co):
if isinstance(consts[i], type(co)):
consts[i] = self._replace_paths_in_code(consts[i])

code_func = type(co)

if hasattr(co, "replace"):
# New in 3.8
return co.replace(
co_filename=new_filename,
co_consts=tuple(consts))

code_func = type(co)
if hasattr(co, "co_posonlyargcount"):
return code_func(
co.co_argcount,
Expand Down
5 changes: 3 additions & 2 deletions modulegraph_tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def setUp(self):
self.mf = modulegraph.ModuleGraph(path=[ root ] + sys.path)
self.mf.run_script(os.path.join(root, 'script.py'))

@unittest.skipUnless(sys.version_info[:2] < (3,11), "Doesn't work with 3.11")
@unittest.skipUnless(not hasattr(sys, 'real_prefix'), "Test doesn't work in virtualenv")
def testRegr1(self):
node = self.mf.findNode('mypkg.distutils')
Expand All @@ -402,9 +403,9 @@ def testRegr1(self):
self.assertIsInstance(node, modulegraph.SourceModule)
self.assertStartswith(node.filename, os.path.dirname(__file__))

# The calls to os.path.realpath are needed due to way
# The calls to os.path.realpath are needed due to way
# my (Ronald's) test machine is set up, sys.prefix is
# a symlink to make it easier to test both macOS installer
# a symlink to make it easier to test both macOS installer
# variants on python.org.
import distutils.sysconfig, distutils.ccompiler
node = self.mf.findNode('distutils.ccompiler')
Expand Down
2 changes: 1 addition & 1 deletion modulegraph_tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_package_version(self):
fn = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
'setup.cfg')
with open(fn, 'rU') as fp:
with open(fn, 'r') as fp:
for ln in fp:
if ln.startswith('version'):
version = ln.split('=')[-1].strip()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
Metadata-Version: 2.1
Name: nspkg
Version: 1.0
Summary: UNKNOWN
Home-page: UNKNOWN
License: UNKNOWN
Platform: UNKNOWN

UNKNOWN

3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[x-metadata]
name = modulegraph
version = 0.19.2
version = 0.19.3
description = Python module dependency analysis tool
long_description_file =
README.rst
Expand All @@ -19,6 +19,7 @@ classifiers =
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Software Development :: Build Tools
author = Ronald Oussoren
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = isort,black,py27,py37,py38,py39,py310,flake8,coverage-report
envlist = isort,black,py27,py37,py38,py39,py310,py311,flake8,coverage-report

[testenv]
commands = {envbindir}/python -m coverage run --parallel setup.py test --verbosity=3
Expand Down

0 comments on commit 4d1b791

Please sign in to comment.