77except ImportError :
88 from distutils .core import setup
99import sys
10- import subprocess
10+ from subprocess import check_call
11+ from io import open as io_open
12+
1113# For Makefile parsing
1214import shlex
1315try : # pragma: no cover
1719 # Python 3 compatibility
1820 import configparser as ConfigParser
1921 import io as StringIO
20- import io
2122import re
2223
23-
2424__author__ = None
2525__licence__ = None
2626__version__ = None
2727main_file = os .path .join (os .path .dirname (__file__ ), 'argopt' , '_argopt.py' )
28- for l in io . open (main_file , mode = 'r' ):
28+ for l in io_open (main_file , mode = 'r' ):
2929 if any (l .startswith (i ) for i in ('__author__' , '__licence__' )):
3030 exec (l )
3131version_file = os .path .join (os .path .dirname (__file__ ), 'argopt' , '_version.py' )
32- with io . open (version_file , mode = 'r' ) as fd :
32+ with io_open (version_file , mode = 'r' ) as fd :
3333 exec (fd .read ())
3434
35-
36- # # Makefile auxiliary functions # #
37-
35+ # Makefile auxiliary functions #
3836
3937RE_MAKE_CMD = re .compile ('^\t (@\+?)(make)?' , flags = re .M )
4038
@@ -50,7 +48,7 @@ def parse_makefile_aliases(filepath):
5048 # -- Parsing the Makefile using ConfigParser
5149 # Adding a fake section to make the Makefile a valid Ini file
5250 ini_str = '[root]\n '
53- with io . open (filepath , mode = 'r' ) as fd :
51+ with io_open (filepath , mode = 'r' ) as fd :
5452 ini_str = ini_str + RE_MAKE_CMD .sub ('\t ' , fd .read ())
5553 ini_fp = StringIO .StringIO (ini_str )
5654 # Parse using ConfigParser
@@ -126,16 +124,17 @@ def execute_makefile_commands(commands, alias, verbose=False):
126124 if verbose :
127125 print ("Running command: " + cmd )
128126 # Launch the command and wait to finish (synchronized call)
129- subprocess .check_call (parsed_cmd )
127+ check_call (parsed_cmd ,
128+ cwd = os .path .dirname (os .path .abspath (__file__ )))
130129
131130
132- # # Main setup.py config # #
131+ # Main setup.py config #
133132
134133
135134# Executing makefile commands if specified
136135if sys .argv [1 ].lower ().strip () == 'make' :
137136 # Filename of the makefile
138- fpath = 'Makefile'
137+ fpath = os . path . join ( os . path . dirname ( __file__ ), 'Makefile' )
139138 # Parse the makefile, substitute the aliases and extract the commands
140139 commands = parse_makefile_aliases (fpath )
141140
@@ -162,11 +161,11 @@ def execute_makefile_commands(commands, alias, verbose=False):
162161 sys .exit (0 )
163162
164163
165- # # Python package config # #
166-
164+ # Python package config #
167165
168- README_rst = None
169- with io .open ('README.rst' , mode = 'r' , encoding = 'utf-8' ) as fd :
166+ README_rst = ''
167+ fndoc = os .path .join (os .path .dirname (__file__ ), 'README.rst' )
168+ with io_open (fndoc , mode = 'r' , encoding = 'utf-8' ) as fd :
170169 README_rst = fd .read ()
171170
172171setup (
@@ -182,6 +181,7 @@ def execute_makefile_commands(commands, alias, verbose=False):
182181 platforms = ['any' ],
183182 packages = ['argopt' ],
184183 install_requires = ['argparse' ],
184+ package_data = {'' : ['LICENCE' ]},
185185 classifiers = [
186186 # Trove classifiers
187187 # (https://pypi.python.org/pypi?%3Aaction=list_classifiers)
0 commit comments