Skip to content

Commit 5d7841f

Browse files
committed
Minimal updates to work with Python 3.8+
1 parent 8e21a55 commit 5d7841f

File tree

5 files changed

+60
-25
lines changed

5 files changed

+60
-25
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.x, pypy2, pypy3]
22+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', 'pypy3']
2323

2424
steps:
2525
- uses: actions/checkout@v2

.github/workflows/release.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
pypi-publish:
10+
if: startsWith(github.ref, 'refs/tags')
11+
name: Upload release to PyPI
12+
runs-on: ubuntu-latest
13+
environment:
14+
name: pypi
15+
url: https://pypi.org/p/cpppo
16+
permissions:
17+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
- name: Build
24+
run: |
25+
python -m pip install --upgrade pip
26+
python -m pip install -r setuptools build wheel
27+
python -m build .
28+
- name: Publish package distributions to PyPI
29+
uses: pypa/gh-action-pypi-publish@release/v1

misc.py

+27-15
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,18 @@ def change_function( function, **kwds ):
151151
152152
153153
"""
154-
# Enumerate all the __code__ attributes in the same order; types.CodeTypes
155-
# doesn't accept keyword args, only position.
156-
attrs = [ "co_argcount" ]
157-
if sys.version_info[0] >= 3:
158-
attrs += [ "co_kwonlyargcount" ]
159-
if sys.version_info[1] >= 8:
160-
attrs += [ "co_posonlyargcount" ]
161-
attrs += [ "co_nlocals",
154+
if hasattr( function.__code__, 'replace' ):
155+
function.__code__ = function.__code__.replace( **kwds )
156+
return
157+
158+
# Enumerate all the __code__ attributes in the same order; types.CodeTypes doesn't accept
159+
# keyword args, only positional. This must be updated if new releases of Python have additional
160+
# parameters, but should be backward-compatible (the positional ordering should be consistent
161+
# for any parameters in use by a version)
162+
attrs = [ "co_argcount",
163+
"co_posonlyargcount",
164+
"co_kwonlyargcount",
165+
"co_nlocals",
162166
"co_stacksize",
163167
"co_flags",
164168
"co_code",
@@ -167,16 +171,24 @@ def change_function( function, **kwds ):
167171
"co_varnames",
168172
"co_filename",
169173
"co_name",
174+
"co_qualname",
170175
"co_firstlineno",
171176
"co_lnotab",
177+
"co_exceptiontable",
172178
"co_freevars",
173-
"co_cellvars" ]
174-
175-
assert all( k in attrs for k in kwds ), \
176-
"Invalid function keyword(s) supplied: %s" % ( ", ".join( kwds.keys() ))
177-
178-
# Alter the desired function attributes, and update the function's __code__
179-
modi_args = [ kwds.get( a, getattr( function.__code__, a )) for a in attrs ]
179+
"co_cellvars", ]
180+
181+
assert all( k in attrs and hasattr( function.__code__, k ) for k in kwds ), \
182+
"Invalid function keyword(s) supplied: %s" % ( ", ".join( kwds ))
183+
184+
# Alter the desired function attributes w/ any supplied keywaords, and update the function's
185+
# __code__. Deduces what positional args are required by which attrs exist in this function's
186+
# code object
187+
modi_args = [
188+
kwds.get( a, getattr( function.__code__, a ))
189+
for a in attrs
190+
if hasattr( function.__code__, a )
191+
]
180192
modi_code = types.CodeType( *modi_args )
181193
modi_func = types.FunctionType( modi_code, function.__globals__ )
182194
function.__code__ = modi_func.__code__

setup.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,8 @@
8383
classifiers = [
8484
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
8585
"License :: Other/Proprietary License",
86-
"Programming Language :: Python :: 2.6",
87-
"Programming Language :: Python :: 2.7",
88-
"Programming Language :: Python :: 3.3",
89-
"Programming Language :: Python :: 3.4",
90-
"Programming Language :: Python :: 3.5",
91-
"Programming Language :: Python :: 3.6",
92-
"Programming Language :: Python :: 3.7",
93-
"Programming Language :: Python :: 3.8",
86+
"Programming Language :: Python :: 2",
87+
"Programming Language :: Python :: 3",
9488
"Development Status :: 5 - Production/Stable",
9589
"Intended Audience :: Developers",
9690
"Environment :: Console",

version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version_info__ = ( 4, 4, 2 )
1+
__version_info__ = ( 4, 4, 3 )
22
__version__ = '.'.join( map( str, __version_info__ ))

0 commit comments

Comments
 (0)