Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
overfl0 committed May 5, 2024
2 parents 103ce65 + 4b5dd11 commit 6c75b3e
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 41 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install testing framework
run: python -m pip install pytest
Expand All @@ -27,20 +27,21 @@ jobs:
run: pytest

- name: Run performance test
run: python testconfig.py
run: python tests/testconfig.py

make_sdist:
needs: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Make Sdist
run: python setup.py sdist

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: artifact-source
path: dist/*.tar.gz

build_wheels:
Expand All @@ -53,10 +54,14 @@ jobs:
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Used to host cibuildwheel
- uses: actions/setup-python@v3
- uses: actions/setup-python@v5
with:
python-version: '3.10'
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1

- name: Install cibuildwheel
run: python -m pip install cibuildwheel
Expand All @@ -68,12 +73,23 @@ jobs:
CIBW_SKIP: pp*
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: pytest {project}
CIBW_TEST_SKIP: "cp38-macosx_arm64"


- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: artifact-${{ matrix.os }}
path: ./wheelhouse/*.whl

merge_artifacts:
runs-on: ubuntu-latest
needs: [make_sdist, build_wheels]
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: armaclass
pattern: artifact-*

# upload_all:
# needs: [ build_wheels, make_sdist ]
# runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Lukasz Taczuk
Copyright (c) 2024 Lukasz Taczuk
Copyright (c) 2018 Moritz Schmidt (original JavaScript code)

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
49 changes: 40 additions & 9 deletions armaclass/Shadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import absolute_import

# Possible version formats: "3.1.0", "3.1.0a1", "3.1.0a1.dev0"
__version__ = "3.0.0b2"
__version__ = "3.0.10"

try:
from __builtin__ import basestring
Expand Down Expand Up @@ -110,22 +110,35 @@ class _Optimization(object):

annotation_typing = returns = wraparound = boundscheck = initializedcheck = \
nonecheck = embedsignature = cdivision = cdivision_warnings = \
always_allows_keywords = profile = linetrace = infer_types = \
unraisable_tracebacks = freelist = \
always_allow_keywords = profile = linetrace = infer_types = \
unraisable_tracebacks = freelist = auto_pickle = cpow = trashcan = \
auto_cpdef = c_api_binop_methods = \
allow_none_for_extension_args = callspec = show_performance_hints = \
cpp_locals = py2_import = iterable_coroutine = remove_unreachable = \
lambda _: _EmptyDecoratorAndManager()

# Note that fast_getattr is untested and undocumented!
fast_getattr = lambda _: _EmptyDecoratorAndManager()

exceptval = lambda _=None, check=True: _EmptyDecoratorAndManager()

overflowcheck = lambda _: _EmptyDecoratorAndManager()
optimize = _Optimization()

overflowcheck.fold = optimize.use_switch = \

embedsignature.format = overflowcheck.fold = optimize.use_switch = \
optimize.unpack_method_calls = lambda arg: _EmptyDecoratorAndManager()

final = internal = type_version_tag = no_gc_clear = no_gc = total_ordering = _empty_decorator
final = internal = type_version_tag = no_gc_clear = no_gc = total_ordering = \
ufunc = _empty_decorator

binding = lambda _: _empty_decorator

class warn:
undeclared = unreachable = maybe_uninitialized = unused = \
unused_arg = unused_result = \
lambda _: _EmptyDecoratorAndManager()


_cython_inline = None
def inline(f, *args, **kwds):
Expand Down Expand Up @@ -216,6 +229,7 @@ def __exit__(self, exc_class, exc, tb):

nogil = _nogil()
gil = _nogil()
with_gil = _nogil() # Actually not a context manager, but compilation will give the right error.
del _nogil


Expand Down Expand Up @@ -437,6 +451,8 @@ def _specialized_from_args(signatures, args, kwargs):
'Py_hash_t',
'Py_ssize_t',
'size_t',
'ssize_t',
'ptrdiff_t',
]
float_types = [
'longdouble',
Expand Down Expand Up @@ -477,7 +493,7 @@ def _specialized_from_args(signatures, args, kwargs):
for name in int_types:
reprname = to_repr(name, name)
gs[name] = typedef(py_int, reprname)
if name not in ('Py_UNICODE', 'Py_UCS4') and not name.endswith('size_t'):
if name not in ('Py_UNICODE', 'Py_UCS4', 'Py_hash_t', 'ptrdiff_t') and not name.endswith('size_t'):
gs['u'+name] = typedef(py_int, "unsigned " + reprname)
gs['s'+name] = typedef(py_int, "signed " + reprname)

Expand All @@ -491,10 +507,19 @@ def _specialized_from_args(signatures, args, kwargs):
void = typedef(None, "void")
Py_tss_t = typedef(None, "Py_tss_t")

for t in int_types + float_types + complex_types + other_types:
for t in int_types:
for i in range(1, 4):
gs["%s_%s" % ('p'*i, t)] = gs[t]._pointer(i)
if 'u'+t in gs:
gs["%s_u%s" % ('p'*i, t)] = gs['u'+t]._pointer(i)
gs["%s_s%s" % ('p'*i, t)] = gs['s'+t]._pointer(i)

for t in float_types + complex_types + other_types:
for i in range(1, 4):
gs["%s_%s" % ('p'*i, t)] = gs[t]._pointer(i)

del t, i

NULL = gs['p_void'](0)

# looks like 'gs' has some users out there by now...
Expand Down Expand Up @@ -550,7 +575,6 @@ def __getattr__(self, attr):
sys.modules['cython.%s' % self.__name__] = mod
return getattr(mod, attr)


class CythonCImports(object):
"""
Simplistic module mock to make cimports sort-of work in Python code.
Expand All @@ -564,7 +588,14 @@ def __init__(self, module):
def __getattr__(self, item):
if item.startswith('__') and item.endswith('__'):
raise AttributeError(item)
return __import__(item)
try:
return __import__(item)
except ImportError:
import sys
ex = AttributeError(item)
if sys.version_info >= (3, 0):
ex.__cause__ = None
raise ex


import math, sys
Expand Down
14 changes: 9 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import glob
import os
import subprocess
from itertools import chain
from pathlib import Path

armaclass_path = 'armaclass'
armaclass_path = Path('armaclass')
types = ('*.html', '*.c', '*.cpp', '*.pyd', '*.so')
files_to_delete = chain(*(glob.glob(os.path.join(armaclass_path, file_type)) for file_type in types))

files_to_delete = []
for file_type in types:
files_to_delete.extend(armaclass_path.glob(file_type))

for file_path in files_to_delete:
print('Deleting', file_path)
os.remove(file_path)

subprocess.run('python setup_cython.py build_ext --inplace --force', shell=True, check=True)
subprocess.run('pytest -x -s', shell=True, check=True)
subprocess.run('python testconfig.py', shell=True, check=True)
subprocess.run('python tests/testconfig.py', shell=True, check=True)
2 changes: 1 addition & 1 deletion requirements-cython.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Cython~=3.0b
Cython~=3.0
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import platform
import sys
from pathlib import Path

from setuptools import setup

# read the contents of your README file
this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
this_directory = Path(__file__).parent
long_description = (this_directory / 'README.md').read_text(encoding='utf-8')

ext_modules = None
if not any(arg in sys.argv for arg in ['clean', 'check']) and \
Expand All @@ -23,7 +23,7 @@
compiler_directives['linetrace'] = True

ext_modules = cythonize(
os.path.join('armaclass', 'parser.py'),
str(this_directory / 'armaclass' / 'parser.py'),
language_level=3,
compiler_directives=compiler_directives,
)
Expand All @@ -44,7 +44,7 @@

classifiers=[
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 4 - Beta',
'Development Status :: 5 - Production/Stable',

# Indicate who your project is intended for
'Intended Audience :: Developers',
Expand All @@ -56,6 +56,7 @@
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',

'License :: OSI Approved :: MIT License',
],
Expand Down
8 changes: 5 additions & 3 deletions setup_cython.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
from pathlib import Path

from setuptools import setup
from Cython.Build import cythonize
from setuptools import setup

this_directory = Path(__file__).parent

setup(
ext_modules=cythonize(os.path.join('armaclass', 'parser.py'),
ext_modules=cythonize(str(this_directory / 'armaclass' / 'parser.py'),
language_level=3,
annotate=True,
),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 14 additions & 9 deletions testconfig.py → tests/testconfig.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import json
import lzma
import os
import sys
import time
from itertools import zip_longest
from pathlib import Path

import armaclass
current_dir = Path(__file__).parent
sys.path.insert(0, str(current_dir.parent))

CONFIG_CPP = os.path.join('config_data', 'config.cpp')
CONFIG_JSON = os.path.join('config_data', 'config.json')
import armaclass # noqa

if not os.path.exists(CONFIG_CPP):
data = lzma.open(CONFIG_CPP + '.xz').read()
CONFIG_CPP = current_dir / 'config_data' / 'config.cpp'
CONFIG_JSON = current_dir / 'config_data' / 'config.json'

if not CONFIG_CPP.exists():
data = lzma.open(str(CONFIG_CPP) + '.xz').read()
with open(CONFIG_CPP, 'wb') as f:
f.write(data)

if not os.path.exists(CONFIG_JSON):
data = lzma.open(CONFIG_JSON + '.xz').read()
if not CONFIG_JSON.exists():
data = lzma.open(str(CONFIG_JSON) + '.xz').read()
with open(CONFIG_JSON, 'wb') as f:
f.write(data)

Expand All @@ -39,7 +43,7 @@
raise


import pstats, cProfile
import pstats, cProfile # noqa

# import pyximport
# pyximport.install()
Expand Down Expand Up @@ -123,5 +127,6 @@ def compare_lists_equal(model, current, path=''):
error = f'{path}[{i}] == {item_current} instead of {item_model}'
raise ValueError(error)


# COMPARE HERE
compare_dicts_equal(model, parsed)

0 comments on commit 6c75b3e

Please sign in to comment.