3

Want to create python source distribution by running python setup.py sdist from a directory outside of the one I want to package up. Can't seem to find a way to do this. I have a script that generates a setup.py and MANIFEST.in dynamically, and I'd like to tell python to use those files to create an sdist of the source in a different directory "over there".

What I'm doing is creating a script that lets a user create an sdist w/o any setup.py etc. They just say "package up this directory and everything under it". So I generate a setup.py and MANIFEST.in (with recursive-include * to grab all files) in a python tempfile.mkdtemp directory (in an unrelated file path like /tmp/whatever) that I can clean up afterwards...but I can't seem to use those to package their directory. I don't want to create those files in their source dir.

chacmool
  • 1,163
  • 2
  • 13
  • 19

2 Answers2

1

You can use setuptools's, --dist-dir=DIR / -d DIR option to specify where the otherwise default dist/-folder is made. In other words, this changes the output directory.

E.g.:

python setup.py sdist -d /tmp/whatever

If you are using distutils.core: Instead of using from distutils.core import setup you can use from setuptools import setup.

In order to define where the source directories come from, I think you can add the directory to sys.path and then setup() will discover the content files automatically:

import sys
from os import path
# ...

# Add other folders to sys.path
sys.path.append('/tmp/whatever')
sys.path.append(path.join(path.abspath('..'), 'some', 'folder'))
Thomas Fauskanger
  • 2,037
  • 20
  • 35
  • That just specifies where the output dist file is put right? I need to be able to say "package the source files from dir X over there using these setup.py and MANIFEST.in files over here". – chacmool Dec 23 '17 at 02:48
  • Yes, I've updated the answer with details on how to add other folders to look for files in ``setup()`` in _setup.py_. Does this help you? – Thomas Fauskanger Dec 23 '17 at 23:55
  • Thanks, I'll try this out and see if it works! Will update here when able. – chacmool Dec 24 '17 at 15:46
1

Sort of a hack, but this worked for me. Right before running setup(), use os.chdir() to change the directory to that of the base path where setup.py would normally run. To specify where the distribution packages go, I use the arguments to setup.py, specifically:

python setup.py sdist --formats=gztar -d 'directory_for_the_distribution' egg_info --egg-base 'directory_for_the_egg_info'

Thus you can run setuptools from a directory other than at the base of the package directories and the distribution and temp egg directories go wherever you want.