Skip to content

Instantly share code, notes, and snippets.

@hartsock
Created May 14, 2021 18:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hartsock/26385ffaec274b2afe79f1dee6f48afe to your computer and use it in GitHub Desktop.
Save hartsock/26385ffaec274b2afe79f1dee6f48afe to your computer and use it in GitHub Desktop.
A super generic Python3 setup.py
import io
import os
from setuptools import find_packages, setup
# Author @hartsock
#
# Why: copy into a directory with some python scripts you want to call a "library"
# How: pip3 install -e .
#
# I often run into piles of Python scripts that _could_ be used as a python library. These often aren't
# enough to warrant a WHOLE separate python library project, but it's nice to setup a Python3 venv to
# have these simple hacky "library" scripts available.
#
# This is a version of a very super generic python setup.py that I use in these weird little corner cases.
# optionally allow for a requirements file if folks feel like it.
def read(*names, **kwargs):
try:
return io.open(
os.path.join(os.path.dirname(__file__), *names),
encoding=kwargs.get('encoding', 'utf8')
).read()
except FileNotFoundError:
return ""
# don't package and ship python test code in this library
packages = [item for item in find_packages('.', exclude=['test']) if not str(item).startswith('test')]
setup(
# allow for package name to be determined by wherever we are
name=os.path.basename(os.path.dirname(__file__)),
packages=packages,
# we scoop the installer requirements into the packager's definition here
install_requires=read('requirements.txt').splitlines(),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment