Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does an empty string key for package_dir do in setup.py?

I have a setup.py file that looks like this:

import setuptools

from distgradle import GradleDistribution

setuptools.setup(
  distclass=GradleDistribution,
  package_dir={'': 'src'},
  packages=setuptools.find_packages('src'),
  include_package_data=True,
  namespace_packages=['foo'],
  entry_points={
    'console_scripts': [
      'first = foo.something.first:main',
      'second = foo.somethingelse.second:main',
    ],
  },
)

What is the significance of package_dir={'': 'src'}? Why do we have an empty string as the key?

like image 607
codeforester Avatar asked Jul 25 '19 19:07

codeforester


People also ask

What does Python setup py Bdist_wheel do?

What is python setup py bdist_wheel? python setup.py bdist_wheel. This will build any C extensions in the project and then package those and the pure Python code into a . whl file in the dist directory.

What should setup py contain?

The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.

What can I use instead of distutils?

Most Python users will not want to use this module directly, but instead use the cross-version tools maintained by the Python Packaging Authority. In particular, setuptools is an enhanced alternative to distutils that provides: support for declaring project dependencies.


1 Answers

When you have multiple directories at the root level and under one directory the modules reside, then you can define that directory as root package and then all packages provided to packages named argument would be looked up inside that dir. Python's official documentation describes this very well:

https://docs.python.org/3/distutils/setupscript.html#listing-whole-packages

Here, if code resides under lib directory then defining package_dir = {'': 'lib'} & packages = ['foo'] would mean that you are telling that system to look for foo module under lib i.e. lib/foo/__init__.py exists.

like image 175
akazuko Avatar answered Sep 27 '22 22:09

akazuko