Skip to content

Commit

Permalink
Minimal updates to work with Python 3.8+
Browse files Browse the repository at this point in the history
  • Loading branch information
pjkundert committed Nov 22, 2024
1 parent 8e21a55 commit 5d7841f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.x, pypy2, pypy3]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', 'pypy3']

steps:
- uses: actions/checkout@v2
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

on:
push:
tags:
- '*'

jobs:
pypi-publish:
if: startsWith(github.ref, 'refs/tags')
name: Upload release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/cpppo
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- name: Build
run: |
python -m pip install --upgrade pip
python -m pip install -r setuptools build wheel
python -m build .
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
42 changes: 27 additions & 15 deletions misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,18 @@ def change_function( function, **kwds ):
"""
# Enumerate all the __code__ attributes in the same order; types.CodeTypes
# doesn't accept keyword args, only position.
attrs = [ "co_argcount" ]
if sys.version_info[0] >= 3:
attrs += [ "co_kwonlyargcount" ]
if sys.version_info[1] >= 8:
attrs += [ "co_posonlyargcount" ]
attrs += [ "co_nlocals",
if hasattr( function.__code__, 'replace' ):
function.__code__ = function.__code__.replace( **kwds )
return

# Enumerate all the __code__ attributes in the same order; types.CodeTypes doesn't accept
# keyword args, only positional. This must be updated if new releases of Python have additional
# parameters, but should be backward-compatible (the positional ordering should be consistent
# for any parameters in use by a version)
attrs = [ "co_argcount",
"co_posonlyargcount",
"co_kwonlyargcount",
"co_nlocals",
"co_stacksize",
"co_flags",
"co_code",
Expand All @@ -167,16 +171,24 @@ def change_function( function, **kwds ):
"co_varnames",
"co_filename",
"co_name",
"co_qualname",
"co_firstlineno",
"co_lnotab",
"co_exceptiontable",
"co_freevars",
"co_cellvars" ]

assert all( k in attrs for k in kwds ), \
"Invalid function keyword(s) supplied: %s" % ( ", ".join( kwds.keys() ))

# Alter the desired function attributes, and update the function's __code__
modi_args = [ kwds.get( a, getattr( function.__code__, a )) for a in attrs ]
"co_cellvars", ]

assert all( k in attrs and hasattr( function.__code__, k ) for k in kwds ), \
"Invalid function keyword(s) supplied: %s" % ( ", ".join( kwds ))

# Alter the desired function attributes w/ any supplied keywaords, and update the function's
# __code__. Deduces what positional args are required by which attrs exist in this function's
# code object
modi_args = [
kwds.get( a, getattr( function.__code__, a ))
for a in attrs
if hasattr( function.__code__, a )
]
modi_code = types.CodeType( *modi_args )
modi_func = types.FunctionType( modi_code, function.__globals__ )
function.__code__ = modi_func.__code__
Expand Down
10 changes: 2 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,8 @@
classifiers = [
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"License :: Other/Proprietary License",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Environment :: Console",
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version_info__ = ( 4, 4, 2 )
__version_info__ = ( 4, 4, 3 )
__version__ = '.'.join( map( str, __version_info__ ))

0 comments on commit 5d7841f

Please sign in to comment.