我有一个setup.py
脚本(请参见下文),用于对我的python软件包进行cythonize。我也有一个meta.yaml
(见下文)来构建一个conda包。
如何避免.py
和.pyc
文件捆绑在conda软件包(.tar.bz2
)中?
我已经尝试了相关堆栈溢出问题的一些建议:
MANIFEST.in
的{{1}} exclude *.py
替换packages=find_packages()
中的setup.py
欢迎提出任何建议!
setup.py
packages=find_packages(exclude=['*.py.'])
meta.yaml
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}
)