How to add package data recursively in Python setup.py?

后端 未结 8 1903
深忆病人
深忆病人 2020-12-13 17:20

I have a new library that has to include a lot of subfolders of small datafiles, and I\'m trying to add them as package data. Imagine I have my library as so:



        
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 17:53

    1. Use Setuptools instead of distutils.
    2. Use data files instead of package data. These do not require __init__.py.
    3. Generate the lists of files and directories using standard Python code, instead of writing it literally:

      data_files = []
      directories = glob.glob('data/subfolder?/subfolder??/')
      for directory in directories:
          files = glob.glob(directory+'*')
          data_files.append((directory, files))
      # then pass data_files to setup()
      

提交回复
热议问题