Skip to content

Commit

Permalink
use pip to install dependencies first
Browse files Browse the repository at this point in the history
- to avoid having to run `setup.py` twice manually, which can go unnoticed if this package is being installed as a dependency.
- because `setup_requires` only downloads packages, w/o installing them
- because the combination of `setup_requires` with `install_requires` do not work as expected under all circumstances [1].
- even if they did work as desired, some intermediate callback would have to be passed to `setuptools.setup`, to be called between `setup_requires` and what follows. This approach is nested, thus against PEP 20.
- so better flat, i.e., first install the necessary dependencies, then build the parser table, then call `setuptools.setup`
- requires that `pip` be present, but not having `pip` is a bad idea anyway -- avoid using `easy_install` (which is available as `setuptools.command.easy_install`)
- a branch tarball is downloaded from github to avoid cloning the whole repository, which is what `pip` does if given a git repo
- so using `pip` isn't strictly necessary, but if we did fetch from a repo, it would be necessary, because that's not possible with vanilla `setuptools`.
- it also simplifies code by not having to try-except, just let `pip` skip dependencies that are already met.
- if the table generation fails for some reason other than absence of `ply`, that will not go unnoticed any more.

[1] https://bitbucket.org/pypa/setuptools/issue/209/setup_requires-and-install_requires-dont
  • Loading branch information
johnyf committed Feb 12, 2015
1 parent ad0fc6d commit 34f7d3f
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pip
from setuptools import setup


Expand All @@ -15,19 +16,22 @@
"version = '{version}'\n").format(version=version)


def build_parser_table():
from promela import yacc
tabmodule = yacc.TABMODULE.split('.')[-1]
outputdir = 'promela/'
parser = yacc.Parser()
parser.build(tabmodule, outputdir=outputdir, write_tables=True)


if __name__ == '__main__':
pip.main(['install', 'ply == 3.4'])
pip.main(['install',
'--allow-unverified', 'networkx>=2.0dev',
'https://github.com/networkx/networkx/archive/master.zip'])
build_parser_table()
with open(VERSION_FILE, 'w') as f:
f.write(s)
# build parser table
try:
from promela import yacc
tabmodule = yacc.TABMODULE.split('.')[-1]
outputdir = 'promela/'
parser = yacc.Parser()
parser.build(tabmodule, outputdir=outputdir, write_tables=True)
plytable_build_failed = False
except AssertionError:
plytable_build_failed = True
setup(
name='promela',
version=version,
Expand All @@ -42,7 +46,3 @@
tests_require=['nose'],
packages=['promela'],
package_dir={'promela': 'promela'})
if plytable_build_failed:
print(
'ERROR: failed to build parser table.'
'Please run setup.py again.')

0 comments on commit 34f7d3f

Please sign in to comment.