[Distutils] a package with is a module

Paul Moore p.f.moore at gmail.com
Mon Oct 27 15:04:38 CET 2014

On 27 October 2014 13:47, Ethan Furman <ethan at stoneleaf.us> wrote:
> So I have multiple problems:
>   - how do I tell PyPI that this file is for Python2.4 - 2.6, this other
> file is for 2.7, and this other other file is for 3.3+ ?
>   - if I have to stick it all in one archive, how do I tell setup.py which
> to install?
>   - is it possible to have all three source files as, say, .txt files, and
> then have some Python code before the setup() call which renames the correct
> one to dbf.py?  How do I know where the .txt files are at to rename them?

For a source distribution, you could play clever games in setup.py to
put the right file in place, with the right name. But that's messy and
it means that if you distribute wheels (not that there's much point in
doing so) you need separate wheels for 2.6-, 2.7 and 3.3+.

Alternatively, you could distribute all 3 files, as

  - __init__.py
  - dbf_26.py
  - dbf_27.py
  - dbf_3.py

Then in __init__.py do

if sys.version_info[0] == 3:
  from .dbf_3 import *
elif sys.version_info[:2] == (2, 7):
  from .dbf_27 import *
  from .dbf_26 import *


More information about the Distutils-SIG mailing list