2

The task is simple: I have a file with extension other than py, which needs to be distributed with the package. For the purpose of this example, let's call it .config.json.

I tried putting it in MANIFEST.in as include .config.json - this had no effect.

I tried package_data={'': ['.config.json']} - this has no effect either.

I also tried data_files=[('', '.config.json')] - this breaks with unrelated error: error: can't copy '.': doesn't exist or not a regular file

Short of just writing a build command myself, I cannot find anything I could do to make this work. And, yes, I've seen tons of similar questions on SO, on GitHub in bug trackers, etc. I know that both setuptools and distutils are essentially hopelessly broken, but maybe there is some sensible way to make this work? I cannot believe that something this simple hadn't been solved yet...


As requested, setup.py:

#!/usr/bin/env python3 # -*- coding: utf-8 -*- from setuptools import setup, find_packages setup( name='project_name', version='0.1.0', description='Project Name in Caps', author='My Company', author_email=','.join( '{}@domain.com'.format(name) for name in list_of_names ), url='https://somewhere', packages=find_packages(), # package_data={ # '': ['.config.json'], # }, # data_files=[('', '.config.json')], install_requires=[ 'pytest >= 3.4.2', ... ], ) 
4
  • What do you mean with "top-level directory"? Do you want to install the file into site-packages/ or site-packages/mypackage/? Commented Mar 20, 2018 at 11:20
  • @phd site-packages/package-version.egg Commented Mar 20, 2018 at 11:46
  • Are you able to post your setup.py? Commented Mar 20, 2018 at 13:07
  • @WillKeeling updated with the setup.py. Commented Mar 21, 2018 at 9:10

2 Answers 2

1

In `setup.py:

package_data={'package': ['../.config.json']} 

The problem with this approach is that the egg will install .config.json into site-packages/ which is hardly what you want and certainly not what users expect of packages.

PS. MANIFEST.in didn't help because it's only for source distribution (python setup.py sdist).

Sign up to request clarification or add additional context in comments.

3 Comments

"You need to put the file .config.json to package/" - No, I don't. It ends up in the wrong place if I do this (instead of site-package/package-version.egg/.config.json it is sent to site-package/package-version.egg/package/.config.json.)
OK, this actually did it. Thank you. But, what do you mean by "egg will install" - egg is not a program, it's a format. When I run setup.py install, the result is not what you describe. So, what is this about?
I think I can now answer my own question: whl and egg formats are incompatible in that how they treat source location. So, if I run setup.py install, It installs correctly, but if I do setup.py bdist_wheel && pip install ./bdist/*.whl, I get different results. I knew Python packaging was garbage, but this is really low...
1

data_files is what you want, but you need to ensure that the filename is enclosed in a list:

data_files=[('', ['.config.json'])], 

That works for me when I run your setup.py.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.