Python 在构建cythonized conda包时,如何排除.py和.pyc文件?
我有一个Python 在构建cythonized conda包时,如何排除.py和.pyc文件?,python,conda,cythonize,Python,Conda,Cythonize,我有一个setup.py脚本(见下文),用于对python包进行Cythonization。我还有一个meta.yaml(见下文)来构建一个conda包 如何避免将.py和.pyc文件捆绑在conda包(.tar.bz2)中 我已经尝试了一些有关堆栈溢出问题的建议: 添加包含排除*.py的清单.in 将setup.py中的packages=find_packages()替换为packages=find_packages(exclude=['*.py.]) 欢迎提出任何建议 setup.py
setup.py
脚本(见下文),用于对python包进行Cythonization。我还有一个meta.yaml
(见下文)来构建一个conda包
如何避免将.py
和.pyc
文件捆绑在conda包(.tar.bz2
)中
我已经尝试了一些有关堆栈溢出问题的建议:
- 添加包含
的排除*.py
清单.in
- 将
setup.py中的
替换为packages=find_packages()
packages=find_packages(exclude=['*.py.])
from setuptools import setup, find_packages
import os
import sys
from distutils.extension import Extension
import fnmatch
from Cython.Distutils import build_ext
def find_files(directory, pattern, exclude_dirs=None):
"""
Recurse through a directory and find all files matching a pattern, excluding the directories from the list
exclude_dirs.
"""
exclude_dirs = exclude_dirs or []
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename, pattern):
if all(ex_dir not in root for ex_dir in exclude_dirs):
filename = os.path.join(root, basename)
# For module name, remove leading ./, replace / with . and omit .py extension
modname = filename.replace('/', '.')[2:-3]
yield (modname, filename)
def make_extension(extension_name, extension_path):
"""
Generate an Extension object from its dotted name and path.
"""
return Extension(extension_name, [extension_path], extra_compile_args=["-O3", "-Wall"], extra_link_args=['-g'])
# Build list of c extensions to be compiled, exclude detector ideas, test and legacy code
extension_paths = find_files('./my_package', '*.py')
extensions = [make_extension(extension_name, extension_path) for extension_name, extension_path in extension_paths]
setup(
name="my-package",
version="0.2.dev",
packages=find_packages(),
test_suite="tests",
install_requires=[
'cython',
'numpy',
'pyyaml',
'matplotlib',
],
ext_modules=extensions,
cmdclass={'build_ext': build_ext}
)
package:
name: my-package
version: "0.2.dev"
source:
path: .
build:
number: {{ environ.get('BUILD_NUMBER', 0) }}
script: python setup.py install --single-version-externally-managed --record=record.txt
include_recipe: False
preserve_egg_dir: True
requirements:
build:
- python
- cython
run:
- python
- numpy
- pyyaml
- matplotlib