Building on Jfs' Answer, if like me you had a directory structure already established that you didn't want to/couldn't change for other reasons, one solution is to temporary copy all of the code to be packaged and then build that.
Here's a makefile with targets which copies all the files across in src to a temp location, and then calls setup.py to build the package, before finally cleaning up after itself.
SRC_DIR='src'
TEMP_PACKAGE_DIR='your_shiny_package'
package: prepare_package_dir build_package deploy_package remove_package_dir
# I'm using gemfury, your deployment will probably look different
deploy_package:
twine upload --repository fury dist/* --verbose
clean_package:
rm -r dist || echo 'dist removed'
rm -r ${TEMP_PACKAGE_DIR}.egg-info || echo 'egg-info removed'
build_package: clean_package
python setup.py sdist
prepare_package_dir:
mkdir ${TEMP_PACKAGE_DIR}
cp -R ${SRC_DIR}/* ${TEMP_PACKAGE_DIR}/
mv ${TEMP_PACKAGE_DIR} ${SRC_DIR}/${TEMP_PACKAGE_DIR}
remove_package_dir:
rm -rf ${SRC_DIR}/${TEMP_PACKAGE_DIR}
and then a setup.py which looks a bit like this:
setup(
name='your_shiny_package',
version=version,
description='some great package...',
long_description=readme,
url='https://whereever',
author='you',
packages=['src/your_shiny_package'],
install_requires=parse_all_requirements(),
zip_safe=False,
include_package_data=True)
Might not be the most efficient, but saves you having to restructure your whole repo permanently.
Usage: just call make package
either as part of your build pipeline or manually.
proj/src/proj
to work as expected? Seems so inefficient. Or am I doing something inefficient here? – Toxin