File size: 2,291 Bytes
884b8f8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # setup.py
import os
from setuptools import setup, Extension, find_packages
from Cython.Build import cythonize
import numpy as np
# ------------------------------------------------------------------------------
# 一、定义 Cython 扩展信息
# - name: 必须与 import 路径保持一致
# - sources: .pyx 文件路径
# - include_dirs: 指定 NumPy 头文件位置
# ------------------------------------------------------------------------------
ext_modules = [
Extension(
name="marble.tasks.GTZANBeatTracking.madmom.hmm",
sources=[os.path.join("marble", "tasks", "GTZANBeatTracking", "madmom", "hmm.pyx")],
include_dirs=[np.get_include()],
language="c", # 若想启用 C++,改成 "c++"
)
]
# ------------------------------------------------------------------------------
# 二、交给 cythonize 编译 .pyx
# - language_level="3": 使用 Python 3 语法解析 Cython 文件
# ------------------------------------------------------------------------------
cythonized_extensions = cythonize(
ext_modules,
compiler_directives={"language_level": "3"},
annotate=False,
)
# ------------------------------------------------------------------------------
# 三、调用 setuptools.setup() 填写项目元数据及扩展模块
# ------------------------------------------------------------------------------
setup(
name="marble", # 跟 pyproject.toml 中 [project].name 保持一致
version="0.2.0", # 跟 pyproject.toml 中 [project].version 保持一致
description="Marble: a framework for SSL-based audio tasks",
author="Ruibin Yuan",
python_requires=">=3.7", # 这里由 pyproject.toml 标记为 dynamic 字段
packages=find_packages(where="."), # 自动查找所有包含 __init__.py 的子包
install_requires=[
# 这些是运行时及编译时至少需要的基础包。大依赖(torch, lightning 等)已在 pyproject.toml 中列出
"numpy>=1.19",
"cython>=0.29",
"scipy>=1.5",
],
setup_requires=[
# 在执行 build_ext 之前,会先安装这两个包
"cython>=0.29",
"numpy>=1.19",
],
ext_modules=cythonized_extensions,
include_package_data=True,
zip_safe=False,
)
|