Search code examples
python-3.xsetup.pypython-wheel

Is it possible to set top_level for bdist_wheel?


I have a project with a structure similar to this:

project_name
  |_ module_1
    |_ submodule1
    |_ file1.py
  |_ module_2
  |_ filea.py
  |_ fileb.py
  |_ setup.py

If I create a bdist_wheel from it, when installing I will get the files and module folder directly under site-packages.

I can add another level to the tree, like so:

project_name
  some_name
    |_ module_1
      |_ submodule1
      |_ file1.py
    |_ module_2
    |_ filea.py
    |_ fileb.py
    |_ setup.py

and then I get everything installed under some_name in site-packages.

Question is, can I achieve the same by somehow setting top_level or by other means that doesn't require adding another folder to the hierarchy (code is like in former in GIT)?


Solution

  • Maybe something like the following could work, but I am not sure (haven't tested it), it might also be required to exclude setup.py somehow, I would not recommend it anyway:

    import setuptools
    
    setuptools.setup(
        packages=['some_name', 'some_name.module_1'],
        package_dir={'some_name': '../project_name'},
        # ...
    )
    

    References: