pymatio 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pymatio-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.1
2
+ Name: pymatio
3
+ Version: 0.1.0
4
+ Summary:
5
+ License: GPL
6
+ Author: zhengmy
7
+ Author-email: zhengmy@ion.ac.cn
8
+ Requires-Python: >=3.9,<3.13
9
+ Classifier: License :: Other/Proprietary License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Description-Content-Type: text/markdown
16
+
17
+ [中文](./README.md) [English](./README_en.md)
18
+
19
+ # 背景
20
+
21
+ Python 中始终没有一个一站式读取 mat 文件的库,mat5 总是依赖 scipy.io, mat7.3 总是依赖 h5py,h5py 直接读取 mat 文件又需要很多手动转换,有一个 mat73 转换,但是核心逻辑是纯 Python 写的,又非常慢。
22
+
23
+ 恰巧 C 中有一个库 [matio](https://github.com/tbeu/matio),我就想用 pybind11 做一个绑定。
24
+
25
+ # 路线
26
+
27
+ - [x] 完成基本函数的绑定
28
+ - [x] 使用 xmake 在 Windows 和 Linux 上编译通过
29
+ - [x] 打包为 whl 文件
30
+ - [x] 添加关于构建成功的基本测试
31
+ - [ ] 添加 cibuildwheel 和 Github Action
32
+ - [ ] 吸取 https://github.com/pybind/scikit_build_example 中的优势
33
+ - [x] 编译扩展时自动处理虚拟环境
34
+ - [ ] 添加更 Pythonic 的调用接口
35
+ - [ ] 添加 benchmark
36
+ - [ ] 导入 scio 的测试和 mat73 的测试
37
+
38
+ # 使用
39
+
40
+ 当前还没有打包到 whl,如需试用需安装 [xmake](https://github.com/xmake-io/xmake/),这是一个基于 lua 的构建系统,非常轻量。
41
+
42
+ ```bash
43
+ git clone https://github.com/myuanz/pymatio
44
+ xmake
45
+ ```
46
+
47
+ 之后即可在`build`目录下见对应平台的 Python 扩展,hdf5 和 matio 之依赖会自动处理。
48
+
49
+ # 样例
50
+
51
+ ```python
52
+ import pymatio as pm
53
+
54
+ print(pm.get_library_version())
55
+ print(pm.log_init('pymatio'))
56
+ print(pm.set_debug(1))
57
+ pm.critical("abcdefg%d,%d\n" % (234, 456,))
58
+ mat = pm.create_ver('test.mat', None, pm.MatFt.MAT73)
59
+
60
+ var1 = pm.var_create('var1', pm.MatioClasses.DOUBLE, pm.MatioTypes.DOUBLE, 2, (2, 3,), (1, 2, 3, 4, 5, 6,), 0)
61
+ pm.var_write(mat, var1, pm.MatioCompression.NONE)
62
+ pm.var_free(var1)
63
+ print(mat.filename, mat.version, mat.fp, mat.header, mat.byte_swap, mat.mode, mat.bof, mat.next_index, mat.num_datasets, mat.refs_id, mat.dir)
64
+ ```
65
+
66
+ 输出:
67
+
68
+ ```
69
+ (1, 5, 26)
70
+ 0
71
+ None
72
+ -E- abcdefg234,456
73
+ : abcdefg234,456
74
+
75
+ test.mat 512 <capsule object NULL at 0x7f85197b3fc0> MATLAB 7.3 MAT-file, Platform: x86_64-pc-Linux, Created by: libmatio v1.5.26 on Tue Dec 26 15:49:00 2023
76
+ HDF5 sche 0 MatAcc.RDWR 128 0 1 -1 []
77
+ ```
@@ -0,0 +1,61 @@
1
+ [中文](./README.md) [English](./README_en.md)
2
+
3
+ # 背景
4
+
5
+ Python 中始终没有一个一站式读取 mat 文件的库,mat5 总是依赖 scipy.io, mat7.3 总是依赖 h5py,h5py 直接读取 mat 文件又需要很多手动转换,有一个 mat73 转换,但是核心逻辑是纯 Python 写的,又非常慢。
6
+
7
+ 恰巧 C 中有一个库 [matio](https://github.com/tbeu/matio),我就想用 pybind11 做一个绑定。
8
+
9
+ # 路线
10
+
11
+ - [x] 完成基本函数的绑定
12
+ - [x] 使用 xmake 在 Windows 和 Linux 上编译通过
13
+ - [x] 打包为 whl 文件
14
+ - [x] 添加关于构建成功的基本测试
15
+ - [ ] 添加 cibuildwheel 和 Github Action
16
+ - [ ] 吸取 https://github.com/pybind/scikit_build_example 中的优势
17
+ - [x] 编译扩展时自动处理虚拟环境
18
+ - [ ] 添加更 Pythonic 的调用接口
19
+ - [ ] 添加 benchmark
20
+ - [ ] 导入 scio 的测试和 mat73 的测试
21
+
22
+ # 使用
23
+
24
+ 当前还没有打包到 whl,如需试用需安装 [xmake](https://github.com/xmake-io/xmake/),这是一个基于 lua 的构建系统,非常轻量。
25
+
26
+ ```bash
27
+ git clone https://github.com/myuanz/pymatio
28
+ xmake
29
+ ```
30
+
31
+ 之后即可在`build`目录下见对应平台的 Python 扩展,hdf5 和 matio 之依赖会自动处理。
32
+
33
+ # 样例
34
+
35
+ ```python
36
+ import pymatio as pm
37
+
38
+ print(pm.get_library_version())
39
+ print(pm.log_init('pymatio'))
40
+ print(pm.set_debug(1))
41
+ pm.critical("abcdefg%d,%d\n" % (234, 456,))
42
+ mat = pm.create_ver('test.mat', None, pm.MatFt.MAT73)
43
+
44
+ var1 = pm.var_create('var1', pm.MatioClasses.DOUBLE, pm.MatioTypes.DOUBLE, 2, (2, 3,), (1, 2, 3, 4, 5, 6,), 0)
45
+ pm.var_write(mat, var1, pm.MatioCompression.NONE)
46
+ pm.var_free(var1)
47
+ print(mat.filename, mat.version, mat.fp, mat.header, mat.byte_swap, mat.mode, mat.bof, mat.next_index, mat.num_datasets, mat.refs_id, mat.dir)
48
+ ```
49
+
50
+ 输出:
51
+
52
+ ```
53
+ (1, 5, 26)
54
+ 0
55
+ None
56
+ -E- abcdefg234,456
57
+ : abcdefg234,456
58
+
59
+ test.mat 512 <capsule object NULL at 0x7f85197b3fc0> MATLAB 7.3 MAT-file, Platform: x86_64-pc-Linux, Created by: libmatio v1.5.26 on Tue Dec 26 15:49:00 2023
60
+ HDF5 sche 0 MatAcc.RDWR 128 0 1 -1 []
61
+ ```
@@ -0,0 +1,61 @@
1
+ import os
2
+ import shutil
3
+ import subprocess
4
+ import sysconfig
5
+ from pathlib import Path
6
+ import logging
7
+
8
+ from setuptools import Extension
9
+ from setuptools.command.build_ext import build_ext
10
+
11
+
12
+ class XmakeBuildExt(build_ext):
13
+ def run(self):
14
+ self.xmake_build()
15
+ self.copy_output_file()
16
+
17
+ def xmake_build(self):
18
+ platform = sysconfig.get_platform()
19
+ xmake_archs = {
20
+ 'win-amd64': 'x64',
21
+ 'win32': 'x86',
22
+ 'linux-x86_64': 'x86_64',
23
+ 'linux-i686': 'i386',
24
+ 'darwin-x86_64': 'x86_64',
25
+ 'darwin-arm64': 'arm64',
26
+ }
27
+ curr_arch = xmake_archs.get(platform)
28
+ if curr_arch is None:
29
+ raise Exception(f'Unsupported platform: {platform}, allowed: {xmake_archs}')
30
+ logging.debug(f"{curr_arch=} {platform=}")
31
+ # 检查xmake是否存在
32
+ if not shutil.which("xmake"):
33
+ raise EnvironmentError("xmake is not installed or not found in PATH. \nTo install xmake, please refer to https://xmake.io/#/guide/installation")
34
+ subprocess.run(["xmake", "config", "-c", "-a", curr_arch, "-v", "-D", '-y'])
35
+ subprocess.run(["xmake", "build", '-y', '-v', '-D'])
36
+
37
+
38
+ def copy_output_file(self):
39
+ ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
40
+ built_files = list(Path('build').glob(f'**/libpymatio{ext_suffix}'))
41
+ if not built_files:
42
+ raise FileNotFoundError(f"No libpymatio file found after xmake build @ {Path('build').absolute()}")
43
+ built_file = str(built_files[0])
44
+ logging.info(f"Found built library: {built_file} @ {Path('.').absolute()}")
45
+
46
+ self.mkpath(os.path.join(self.build_lib, 'pymatio'))
47
+ self.copy_file(built_file, os.path.join(self.build_lib, 'pymatio'))
48
+ self.copy_extensions_to_source()
49
+
50
+
51
+ def build(setup_kwargs):
52
+ print(setup_kwargs)
53
+ setup_kwargs.update({
54
+ 'ext_modules': [Extension('pymatio.libpymatio', sources=[])],
55
+ 'cmdclass': {'build_ext': XmakeBuildExt},
56
+ 'package_data': {
57
+ 'pymatio': [f'libpymatio{sysconfig.get_config_var("EXT_SUFFIX")}'],
58
+ },
59
+ })
60
+
61
+ print(setup_kwargs)
@@ -0,0 +1,22 @@
1
+ import importlib
2
+ import importlib.util
3
+ import sys
4
+ from pathlib import Path
5
+ import sysconfig
6
+
7
+ EXT_SUFFIX = sysconfig.get_config_var("EXT_SUFFIX")
8
+
9
+ target_dll = Path(__file__).parent / f'libpymatio{EXT_SUFFIX}'
10
+ try:
11
+
12
+ spec = importlib.util.spec_from_file_location("libpymatio", target_dll)
13
+ libpymatio = importlib.util.module_from_spec(spec)
14
+ sys.modules["libpymatio"] = libpymatio
15
+ spec.loader.exec_module(libpymatio)
16
+ except Exception as e:
17
+ import traceback
18
+ traceback.print_exc()
19
+ raise
20
+
21
+ from libpymatio import get_library_version
22
+ from libpymatio import *
@@ -0,0 +1,38 @@
1
+ [tool.poetry]
2
+ name = "pymatio"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = ["zhengmy <zhengmy@ion.ac.cn>"]
6
+ license = "GPL"
7
+ readme = "README.md"
8
+ packages = [{include = "pymatio"}, {include = "xmake.lua"}, {include = "src"}]
9
+
10
+ [tool.poetry.build]
11
+ script = "build_arg.py"
12
+ generate-setup-file = true
13
+
14
+ [tool.poetry.dependencies]
15
+ python = ">=3.9,<3.13"
16
+
17
+
18
+ [tool.poetry.group.dev.dependencies]
19
+ setuptools = "^69.0.3"
20
+ pybind11 = "^2"
21
+ cibuildwheel = "^2.16.2"
22
+ pytest = "^7.4.3"
23
+
24
+ [build-system]
25
+ requires = ["poetry-core", "setuptools"]
26
+ build-backend = "poetry.core.masonry.api"
27
+
28
+ [tool.cibuildwheel]
29
+ build = ["cp39-*", "cp310-*", "cp311-*", "cp312-*"]
30
+ archs = "auto64"
31
+ # TODO: support x86 or i386, it seems that xmake `find python` can't find x86 python
32
+
33
+ build-verbosity = 3
34
+ build-frontend = "build"
35
+ test-requires = "pytest"
36
+ test-command = "pytest {project}/tests"
37
+
38
+ linux.before-all = "tools/prepare_linux.bash"
pymatio-0.1.0/setup.py ADDED
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ from setuptools import setup
3
+
4
+ packages = \
5
+ ['pymatio', 'src']
6
+
7
+ package_data = \
8
+ {'': ['*']}
9
+
10
+ modules = \
11
+ ['xmake']
12
+ setup_kwargs = {
13
+ 'name': 'pymatio',
14
+ 'version': '0.1.0',
15
+ 'description': '',
16
+ 'long_description': '[中文](./README.md) [English](./README_en.md)\n\n# 背景\n\nPython 中始终没有一个一站式读取 mat 文件的库,mat5 总是依赖 scipy.io, mat7.3 总是依赖 h5py,h5py 直接读取 mat 文件又需要很多手动转换,有一个 mat73 转换,但是核心逻辑是纯 Python 写的,又非常慢。\n\n恰巧 C 中有一个库 [matio](https://github.com/tbeu/matio),我就想用 pybind11 做一个绑定。\n\n# 路线\n\n- [x] 完成基本函数的绑定\n- [x] 使用 xmake 在 Windows 和 Linux 上编译通过\n- [x] 打包为 whl 文件\n- [x] 添加关于构建成功的基本测试\n- [ ] 添加 cibuildwheel 和 Github Action\n- [ ] 吸取 https://github.com/pybind/scikit_build_example 中的优势\n- [x] 编译扩展时自动处理虚拟环境\n- [ ] 添加更 Pythonic 的调用接口\n- [ ] 添加 benchmark\n- [ ] 导入 scio 的测试和 mat73 的测试\n\n# 使用\n\n当前还没有打包到 whl,如需试用需安装 [xmake](https://github.com/xmake-io/xmake/),这是一个基于 lua 的构建系统,非常轻量。\n\n```bash\ngit clone https://github.com/myuanz/pymatio\nxmake\n```\n\n之后即可在`build`目录下见对应平台的 Python 扩展,hdf5 和 matio 之依赖会自动处理。\n\n# 样例\n\n```python\nimport pymatio as pm\n\nprint(pm.get_library_version())\nprint(pm.log_init(\'pymatio\'))\nprint(pm.set_debug(1))\npm.critical("abcdefg%d,%d\\n" % (234, 456,))\nmat = pm.create_ver(\'test.mat\', None, pm.MatFt.MAT73)\n\nvar1 = pm.var_create(\'var1\', pm.MatioClasses.DOUBLE, pm.MatioTypes.DOUBLE, 2, (2, 3,), (1, 2, 3, 4, 5, 6,), 0)\npm.var_write(mat, var1, pm.MatioCompression.NONE)\npm.var_free(var1)\nprint(mat.filename, mat.version, mat.fp, mat.header, mat.byte_swap, mat.mode, mat.bof, mat.next_index, mat.num_datasets, mat.refs_id, mat.dir)\n```\n\n输出:\n\n```\n(1, 5, 26)\n0\nNone\n-E- abcdefg234,456\n: abcdefg234,456\n\ntest.mat 512 <capsule object NULL at 0x7f85197b3fc0> MATLAB 7.3 MAT-file, Platform: x86_64-pc-Linux, Created by: libmatio v1.5.26 on Tue Dec 26 15:49:00 2023\n HDF5 sche 0 MatAcc.RDWR 128 0 1 -1 []\n ```',
17
+ 'author': 'zhengmy',
18
+ 'author_email': 'zhengmy@ion.ac.cn',
19
+ 'maintainer': 'None',
20
+ 'maintainer_email': 'None',
21
+ 'url': 'None',
22
+ 'packages': packages,
23
+ 'package_data': package_data,
24
+ 'py_modules': modules,
25
+ 'python_requires': '>=3.9,<3.13',
26
+ }
27
+ from build_arg import *
28
+ build(setup_kwargs)
29
+
30
+ setup(**setup_kwargs)
File without changes