Skip to content

Commit 54a1f49

Browse files
committed
add pruned-down version of setup.py for pure Python projects
1 parent 290b167 commit 54a1f49

1 file changed

Lines changed: 196 additions & 0 deletions

File tree

setup-purepython.py

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
"""setuptools-based setup.py template.
4+
5+
Pruned-down version of the Cython template, for pure Python projects (no Cython).
6+
7+
Supports Python 2.7 and 3.4.
8+
9+
Usage as usual with setuptools:
10+
python setup.py build
11+
python setup.py sdist
12+
python setup.py bdist_wheel --universal # use --universal for projects that work on both py2/py3 as-is
13+
python setup.py install
14+
15+
For details, see
16+
http://setuptools.readthedocs.io/en/latest/setuptools.html#command-reference
17+
or
18+
python setup.py --help
19+
python setup.py --help-commands
20+
python setup.py --help bdist_wheel # or any command
21+
"""
22+
23+
from __future__ import division, print_function, absolute_import
24+
25+
try:
26+
# Python 3
27+
MyFileNotFoundError = FileNotFoundError
28+
except: # FileNotFoundError does not exist in Python 2.7
29+
# Python 2.7
30+
# - open() raises IOError
31+
# - remove() (not currently used here) raises OSError
32+
MyFileNotFoundError = (IOError, OSError)
33+
34+
#########################################################
35+
# General config
36+
#########################################################
37+
38+
# Name of the top-level package of your library.
39+
#
40+
# This is also the top level of its source tree, relative to the top-level project directory setup.py resides in.
41+
#
42+
libname="mylibrary"
43+
44+
# Short description for package list on PyPI
45+
#
46+
SHORTDESC="yet another setuptools template for Python projects"
47+
48+
# Long description for package homepage on PyPI
49+
#
50+
DESC="""yet another setuptools-based setup.py template for Python projects.
51+
52+
This is a pruned-down version of the Cython template, for pure Python projects (no Cython).
53+
54+
Supports Python 2.7 and 3.4.
55+
"""
56+
57+
# Set up data files for packaging.
58+
#
59+
# Directories (relative to the top-level directory where setup.py resides) in which to look for data files.
60+
datadirs = ("test",)
61+
62+
# File extensions to be considered as data files. (Literal, no wildcards.)
63+
dataexts = (".py", ".sh", ".lyx", ".tex", ".txt", ".pdf")
64+
65+
# Standard documentation to detect (and package if it exists).
66+
#
67+
standard_docs = ["README", "LICENSE", "TODO", "CHANGELOG", "AUTHORS"] # just the basename without file extension
68+
standard_doc_exts = [".md", ".rst", ".txt", ""] # commonly .md for GitHub projects, but other projects may use .rst or .txt (or even blank).
69+
70+
71+
#########################################################
72+
# Init
73+
#########################################################
74+
75+
# check for Python 2.7 or later
76+
# http://stackoverflow.com/questions/19534896/enforcing-python-version-in-setup-py
77+
import sys
78+
if sys.version_info < (2,7):
79+
sys.exit('Sorry, Python < 2.7 is not supported')
80+
81+
import os
82+
83+
from setuptools import setup
84+
85+
86+
# Gather user-defined data files
87+
#
88+
# http://stackoverflow.com/questions/13628979/setuptools-how-to-make-package-contain-extra-data-folder-and-all-folders-inside
89+
#
90+
datafiles = []
91+
getext = lambda filename: os.path.splitext(filename)[1]
92+
for datadir in datadirs:
93+
datafiles.extend( [(root, [os.path.join(root, f) for f in files if getext(f) in dataexts])
94+
for root, dirs, files in os.walk(datadir)] )
95+
96+
97+
# Add standard documentation (README et al.), if any, to data files
98+
#
99+
detected_docs = []
100+
for docname in standard_docs:
101+
for ext in standard_doc_exts:
102+
filename = "".join( (docname, ext) ) # relative to the directory in which setup.py resides
103+
if os.path.isfile(filename):
104+
detected_docs.append(filename)
105+
datafiles.append( ('.', detected_docs) )
106+
107+
108+
# Extract __version__ from the package __init__.py
109+
# (since it's not a good idea to actually run __init__.py during the build process).
110+
#
111+
# http://stackoverflow.com/questions/2058802/how-can-i-get-the-version-defined-in-setup-py-setuptools-in-my-package
112+
#
113+
import ast
114+
init_py_path = os.path.join(libname, '__init__.py')
115+
version = '0.0.unknown'
116+
try:
117+
with open(init_py_path) as f:
118+
for line in f:
119+
if line.startswith('__version__'):
120+
version = ast.parse(line).body[0].value.s
121+
break
122+
else:
123+
print( "WARNING: Version information not found in '%s', using placeholder '%s'" % (init_py_path, version), file=sys.stderr )
124+
except MyFileNotFoundError:
125+
print( "WARNING: Could not find file '%s', using placeholder version information '%s'" % (init_py_path, version), file=sys.stderr )
126+
127+
128+
#########################################################
129+
# Call setup()
130+
#########################################################
131+
132+
setup(
133+
name = "mylibrary",
134+
version = version,
135+
author = "Juha Jeronen",
136+
author_email = "[email protected]",
137+
url = "https://github.com/Technologicat/setup-template-cython",
138+
139+
description = SHORTDESC,
140+
long_description = DESC,
141+
142+
# CHANGE THIS
143+
license = "Unlicense",
144+
145+
# free-form text field; http://stackoverflow.com/questions/34994130/what-platforms-argument-to-setup-in-setup-py-does
146+
platforms = ["Linux"],
147+
148+
# See
149+
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
150+
#
151+
# for the standard classifiers.
152+
#
153+
# Remember to configure these appropriately for your project, especially license!
154+
#
155+
classifiers = [ "Development Status :: 4 - Beta",
156+
"Environment :: Console",
157+
"Intended Audience :: Developers",
158+
"Intended Audience :: Science/Research",
159+
"License :: Unlicense", # not a standard classifier; CHANGE THIS
160+
"Operating System :: POSIX :: Linux",
161+
"Programming Language :: Python",
162+
"Programming Language :: Python :: 2",
163+
"Programming Language :: Python :: 2.7",
164+
"Programming Language :: Python :: 3",
165+
"Programming Language :: Python :: 3.4",
166+
"Topic :: Scientific/Engineering",
167+
"Topic :: Scientific/Engineering :: Mathematics",
168+
"Topic :: Software Development :: Libraries",
169+
"Topic :: Software Development :: Libraries :: Python Modules"
170+
],
171+
172+
# See
173+
# http://setuptools.readthedocs.io/en/latest/setuptools.html
174+
#
175+
setup_requires = ["numpy"],
176+
install_requires = ["numpy"],
177+
provides = ["setup_template_nocython"],
178+
179+
# keywords for PyPI (in case you upload your project)
180+
#
181+
# e.g. the keywords your project uses as topics on GitHub, minus "python" (if there)
182+
#
183+
keywords = ["setuptools template example"],
184+
185+
# Declare packages so that python -m setup build will copy .py files (especially __init__.py).
186+
#
187+
# This **does not** automatically recurse into subpackages, so they must also be declared.
188+
#
189+
packages = ["mylibrary"],
190+
191+
zip_safe = True, # no Cython extensions
192+
193+
# Custom data files not inside a Python package
194+
data_files = datafiles
195+
)
196+

0 commit comments

Comments
 (0)