initial tests
This commit is contained in:
42
swig/python/README.rst
Normal file
42
swig/python/README.rst
Normal file
@@ -0,0 +1,42 @@
|
||||
osu! pp and difficulty calculator. automatically generated C bindings for
|
||||
https://github.com/Francesco149/oppai-ng
|
||||
|
||||
usage
|
||||
===========
|
||||
.. code-block:: sh
|
||||
|
||||
pip install oppai
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from oppai import *
|
||||
|
||||
ez = ezpp_new()
|
||||
ezpp(ez, sys.argv[1])
|
||||
print("%g pp" % ezpp_pp(ez))
|
||||
ezpp_free(ez)
|
||||
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
./example.py /path/to/file.osu
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
python -c 'help("oppai")'
|
||||
|
||||
for a list of functions, or just read the top of oppai.c for better doc
|
||||
|
||||
|
||||
limitations
|
||||
===========
|
||||
for some reason, python3 doesn't provide a persisting pointer to strings
|
||||
you pass to c code even if you aren't doing anything with them, so if you
|
||||
want to reuse the handle at all you have to use ezpp_dup and ezpp_data_dup,
|
||||
which create a copy of the strings you pass in. this is inefficient so
|
||||
it's recommended to use autocalc mode and only call ezpp_dup or
|
||||
ezpp_data_dup when you're actually changing map
|
10
swig/python/build.sh
Executable file
10
swig/python/build.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf ./dist
|
||||
cp ../../oppai.c .
|
||||
cp ../oppai.i .
|
||||
swig -python -includeall oppai.i || exit
|
||||
for img in quay.io/pypa/manylinux2010_x86_64 quay.io/pypa/manylinux2010_i686; do
|
||||
docker run --user 1000:1000 --rm -v $(pwd):/io -w /io $img \
|
||||
./build_wheels.sh || exit
|
||||
done
|
15
swig/python/build_wheels.sh
Executable file
15
swig/python/build_wheels.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
# this is meant to be used from docker
|
||||
|
||||
for pybin in /opt/python/*/bin
|
||||
do
|
||||
rm *.so
|
||||
"$pybin/pip" wheel . -w dist/ || exit
|
||||
done
|
||||
|
||||
"$pybin/python" ./setup.py sdist || exit
|
||||
|
||||
for w in dist/*linux_*.whl; do
|
||||
auditwheel repair "$w" -w dist/ || exit
|
||||
done
|
||||
rm dist/*linux_*.whl
|
9
swig/python/examples/basic.py
Executable file
9
swig/python/examples/basic.py
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from oppai import *
|
||||
|
||||
ez = ezpp_new()
|
||||
ezpp(ez, sys.argv[1])
|
||||
print("%g pp" % ezpp_pp(ez))
|
||||
ezpp_free(ez)
|
16
swig/python/examples/reuse.py
Executable file
16
swig/python/examples/reuse.py
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from oppai import *
|
||||
|
||||
ez = ezpp_new()
|
||||
ezpp_set_autocalc(ez, 1)
|
||||
for osufile in sys.argv[1:]:
|
||||
ezpp_dup(ez, osufile)
|
||||
print("%s - %s [%s]" % (ezpp_artist(ez), ezpp_title(ez), ezpp_version(ez)))
|
||||
print("%g stars" % ezpp_stars(ez))
|
||||
for acc in range(95, 101):
|
||||
ezpp_set_accuracy_percent(ez, acc)
|
||||
print("%g%% -> %g pp" % (acc, ezpp_pp(ez)))
|
||||
print("")
|
||||
ezpp_free(ez)
|
38
swig/python/examples/reuse_mem.py
Executable file
38
swig/python/examples/reuse_mem.py
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from oppai import *
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
# hack to force utf-8 on py < 3
|
||||
reload(sys)
|
||||
sys.setdefaultencoding("utf-8")
|
||||
|
||||
def mods_str(mods):
|
||||
mods_str = "+"
|
||||
if mods == 0:
|
||||
mods_str += "nomod"
|
||||
else:
|
||||
if mods & MODS_HD: mods_str += "hd"
|
||||
if mods & MODS_DT: mods_str += "dt"
|
||||
if mods & MODS_HR: mods_str += "hr"
|
||||
return mods_str
|
||||
|
||||
ez = ezpp_new()
|
||||
ezpp_set_autocalc(ez, 1)
|
||||
for osufile in sys.argv[1:]:
|
||||
# by providing the map in memory we can speed up subsequent re-parses
|
||||
f = open(osufile, 'r')
|
||||
data = f.read()
|
||||
f.close()
|
||||
ezpp_data_dup(ez, data, len(data.encode('utf-8')))
|
||||
print("%s - %s [%s]" % (ezpp_artist(ez), ezpp_title(ez), ezpp_version(ez)))
|
||||
print("%g stars" % ezpp_stars(ez))
|
||||
for mods in [ 0, MODS_HR, MODS_HD | MODS_HR, MODS_DT, MODS_HD | MODS_DT ]:
|
||||
print(mods_str(mods))
|
||||
ezpp_set_mods(ez, mods)
|
||||
for acc in range(95, 101):
|
||||
ezpp_set_accuracy_percent(ez, acc)
|
||||
print("%g%% -> %g pp" % (acc, ezpp_pp(ez)))
|
||||
print("")
|
||||
ezpp_free(ez)
|
14
swig/python/examples/timing.py
Executable file
14
swig/python/examples/timing.py
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from oppai import *
|
||||
|
||||
# prints timing points (just a test for this interface)
|
||||
ez = ezpp_new()
|
||||
ezpp(ez, sys.argv[1])
|
||||
for i in range(ezpp_ntiming_points(ez)):
|
||||
time = ezpp_timing_time(ez, i)
|
||||
ms_per_beat = ezpp_timing_ms_per_beat(ez, i)
|
||||
change = ezpp_timing_change(ez, i)
|
||||
print("%f | %f beats per ms | change: %d" % (time, ms_per_beat, change))
|
||||
ezpp_free(ez)
|
3
swig/python/publish.sh
Executable file
3
swig/python/publish.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
twine upload dist/*
|
25
swig/python/python.yml
Normal file
25
swig/python/python.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
environment:
|
||||
TWINE_USERNAME: lolisamurai
|
||||
TWINE_PASSWORD:
|
||||
secure: DTyX4L2loxFxlsbPYAwuga0DyOlGiOnJyEwi/j08gba0NyNx21TvRFMHpITIqcfg
|
||||
cache:
|
||||
- C:\ProgramData\chocolatey\bin
|
||||
- C:\ProgramData\chocolatey\lib
|
||||
- C:\Users\appveyor\AppData\Local\pip\Cache
|
||||
install:
|
||||
- IF NOT EXIST C:\ProgramData\chocolatey\bin\swig.exe choco install swig --version 3.0.12 --yes --limit-output
|
||||
- python -m pip install twine
|
||||
- python -m pip install cibuildwheel==0.10.1
|
||||
build_script:
|
||||
- cd swig/python
|
||||
- copy ..\..\oppai.c .
|
||||
- copy ..\oppai.i .
|
||||
- swig -python -includeall oppai.i
|
||||
- cibuildwheel --output-dir wheelhouse
|
||||
- ps: >-
|
||||
if ($env:APPVEYOR_REPO_TAG -eq "true") {
|
||||
Invoke-Expression "python -m twine upload --skip-existing wheelhouse/*.whl"
|
||||
}
|
||||
artifacts:
|
||||
- path: "swig\\python\\wheelhouse\\*.whl"
|
||||
name: wheels
|
2
swig/python/setup.cfg
Normal file
2
swig/python/setup.cfg
Normal file
@@ -0,0 +1,2 @@
|
||||
[build_ext]
|
||||
swig-opts=-includeall
|
58
swig/python/setup.py
Normal file
58
swig/python/setup.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
def parse_version_str():
|
||||
import re
|
||||
version_re = re.compile('^#define OPPAI_VERSION_(MAJOR|MINOR|PATCH)')
|
||||
version = []
|
||||
with open('oppai.c', 'r') as f:
|
||||
for line in f:
|
||||
if version_re.match(line):
|
||||
version.append(str(int(line.split(' ')[2])))
|
||||
return '.'.join(version)
|
||||
|
||||
try:
|
||||
from setuptools import setup, Extension
|
||||
except ImportError:
|
||||
from distutils.core import setup, Extension
|
||||
|
||||
try:
|
||||
from oppai import oppai_version_str
|
||||
except Exception:
|
||||
def oppai_version_str():
|
||||
try:
|
||||
return parse_version_str()
|
||||
except Exception:
|
||||
return "INVALID"
|
||||
|
||||
oppai_classifiers = [
|
||||
"Programming Language :: Python :: 2",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: Public Domain",
|
||||
"Topic :: Software Development :: Libraries",
|
||||
"Topic :: Utilities",
|
||||
]
|
||||
|
||||
f = open("README.rst", "r")
|
||||
oppai_readme = f.read()
|
||||
f.close()
|
||||
|
||||
oppai_sources=['oppai.i']
|
||||
if os.system('swig') != 0:
|
||||
oppai_sources=['oppai_wrap.c', 'oppai.c']
|
||||
|
||||
setup(
|
||||
name="oppai",
|
||||
version=oppai_version_str(),
|
||||
author="Franc[e]sco",
|
||||
author_email="lolisamurai@tfwno.gf",
|
||||
url="https://github.com/Francesco149/oppai-ng",
|
||||
ext_modules=[Extension('_oppai', oppai_sources)],
|
||||
py_modules=["oppai"],
|
||||
description="osu! pp and difficulty calculator, C bindings",
|
||||
long_description=oppai_readme,
|
||||
license="Unlicense",
|
||||
classifiers=oppai_classifiers,
|
||||
keywords="osu! osu"
|
||||
)
|
Reference in New Issue
Block a user