Skip to content

Commit

Permalink
python setup.py makefile supports quoted strings + better build commands
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen L. <lrq3000@gmail.com>
  • Loading branch information
lrq3000 committed Nov 7, 2015
1 parent 6421fa9 commit 11ecc25
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
34 changes: 22 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# IMPORTANT: for compatibility with `python setup.py make [alias]`, ensure:
# 1. A line return after every alias
# 2. One command per line
# E.g.:
# ```
# all:
# @make test
# @make install
# test:
# nosetest
# install:
# python setup.py install
# ```
# 1. Every alias is preceded by @make (eg: @make alias)
# 2. Add a line return after every @make alias (ie, cannot put multiple alias calls on one line)
# 3. One command per line
# 4. Every line shifts is using TABs and not SPACEs
#
# Sample makefile compatible with `python setup.py make`:
#```
#all:
# @make test
# @make install
#test:
# nosetest
#install:
# python setup.py install
#```

.PHONY:
alltests
Expand Down Expand Up @@ -63,6 +66,8 @@ install:
python setup.py install

build:
python -c "import shutil; shutil.rmtree('build', True)"
python -c "import shutil; shutil.rmtree('dist', True)"
python setup.py sdist --formats=gztar,zip bdist_wininst
python setup.py sdist bdist_wheel

Expand All @@ -72,5 +77,10 @@ pypimeta:
pypi:
twine upload dist/*

buildupload:
@make build
@make pypimeta
@make pypi

none:
# used for unit testing
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import subprocess
# For Makefile parsing
import shlex
try: # pragma: no cover
import ConfigParser
import StringIO
Expand Down Expand Up @@ -105,9 +106,14 @@ def parse_makefile_aliases(filepath):
def execute_makefile_commands(commands, alias, verbose=False):
cmds = commands[alias]
for cmd in cmds:
if verbose:
print("Running command: " + cmd)
subprocess.check_call(cmd.split())
# Parse string in a shell-like fashion using shlex (allows to easily parse quoted strings and comments)
parsed_cmd = shlex.split(cmd, comments=True)
# Execute command if not empty (ie, not just a comment)
if parsed_cmd:
if verbose:
print("Running command: " + cmd)
# Launch the command and wait to finish (synchronized call)
subprocess.check_call(parsed_cmd)


""" Main setup.py config """
Expand Down

0 comments on commit 11ecc25

Please sign in to comment.