Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python setup.py include .json files in the egg

I want to package .json files as well in the python egg file.

For example: boto package has endpoints.json file. But when I run python setup.py bdist_egg it does not include the json file in the egg. How do I include the Json file in the egg?

How do I include *.json file in the egg?

Below is the setup.py code

from setuptools import setup, find_packages, Extension

setup(
  name='X-py-backend',
  version='tip',
  description='X Python backend tools',
  author='meme',
  packages=find_packages('python'),
  package_dir={'': 'python'},
  data_files=[('boto', ['python/boto/endpoints.json'])],
  namespace_packages = ['br'],
  zip_safe=True,
)

setup(
  name='X-py-backend',
  version='tip',
  packages=find_packages('protobuf/target/python'),
  package_dir={'': 'protobuf/target/python'},
  namespace_packages = ['br'],
  zip_safe=True,
)
like image 346
Bourne Avatar asked May 11 '15 09:05

Bourne


1 Answers

You only need to list the file on data_files parameter. Here is the example.

setup(
  name='X-py-backend',
  version='tip',
  description='XXX Python backend tools',
  author='meme',
  packages=find_packages('python'),
  package_dir={'': 'python'},
  data_files=[('boto', ['boto/*.json'])]
  namespace_packages = ['br'],
  zip_safe=True
)

You can see the details here. https://docs.python.org/2/distutils/setupscript.html#installing-additional-files

Another way to do this is to use MANIFEST.in files. you need to create a MANIFEST.in file in your project root. Here is the example.

include python/boto/endpoints.json

Please visit here for more information.https://docs.python.org/2/distutils/sourcedist.html#manifest-template

like image 186
Edwin Lunando Avatar answered Sep 30 '22 17:09

Edwin Lunando