Skip to content

Commit

Permalink
Don't hardcode /usr/bin/python
Browse files Browse the repository at this point in the history
Determine the shebang for bin/cryptosite at
make time (so that it will work with either
Python 2 or Python 3). Use sys.executable
in Python code rather than /usr/bin/python so
that we respect the configured Python version.
  • Loading branch information
benmwebb committed Oct 14, 2019
1 parent bde9fb3 commit ae9cbb3
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 20 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
include Makefile.include

.PHONY: install test
.PHONY: install test bin clean

install:
bin:
${MAKE} -C bin

clean:
${MAKE} -C bin clean

install: bin
${MAKE} -C data install
${MAKE} -C data/ligands install
${MAKE} -C bin install
${MAKE} -C lib/cryptosite install
${MAKE} -C lib/cryptosite/config install

test:
test: bin
nosetests --processes=-1 test
1 change: 1 addition & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PREFIX=/usr/local
DATADIR=${PREFIX}/share/data/cryptosite
BINDIR=${PREFIX}/bin
PYTHON=python
PYTHONDIR=${PREFIX}/python
UNIPROT=/usr/share/databases/uniprot
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cryptosite
8 changes: 7 additions & 1 deletion bin/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
include ../Makefile.include

.PHONY: install
.PHONY: install clean

cryptosite: cryptosite.in
FULL_PYTHON=`which ${PYTHON}`; sed -e "s^#!.*^#!$$FULL_PYTHON^" $< > $@ && chmod a+x $@

FILES=${BINDIR}/cryptosite

install: ${FILES}

clean:
rm -f cryptosite

${BINDIR}/%: %
@if [ ! -d ${BINDIR} ]; then mkdir -p ${BINDIR}; fi
install $< $@
File renamed without changes.
2 changes: 2 additions & 0 deletions doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ will get all of these dependencies.
Building
========

Use ``make PYTHON=python3`` or ``make PYTHON=python2`` to build the library
(depending on which version of Python you want to use).
Use ``make test`` to test the library, and ``make install`` to install it.
In most cases you will need to tell ``make`` where to install (if running on
a Linux cluster, CryptoSite will need to be installed on a network-accessible
Expand Down
2 changes: 1 addition & 1 deletion test/test_am_bmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_bad(self):
for args in (['x'],):
out = utils.check_output(['cryptosite', 'am_bmi'] + args,
stderr=subprocess.STDOUT, retcode=2)
out = utils.check_output(['python', '-m',
out = utils.check_output([sys.executable, '-m',
'cryptosite.am_bmi'] + args,
stderr=subprocess.STDOUT, retcode=2)

Expand Down
2 changes: 1 addition & 1 deletion test/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_bad(self):
for args in ([],):
out = utils.check_output(['cryptosite', 'analysis'] + args,
stderr=subprocess.STDOUT, retcode=2)
out = utils.check_output(['python', '-m',
out = utils.check_output([sys.executable, '-m',
'cryptosite.analysis'] + args,
stderr=subprocess.STDOUT, retcode=2)

Expand Down
2 changes: 1 addition & 1 deletion test/test_chimera.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_bad(self):
for args in ([], ['x'] * 4):
out = utils.check_output(['cryptosite', 'chimera'] + args,
stderr=subprocess.STDOUT, retcode=2)
out = utils.check_output(['python', '-m',
out = utils.check_output([sys.executable, '-m',
'cryptosite.chimera'] + args,
stderr=subprocess.STDOUT, retcode=2)

Expand Down
2 changes: 1 addition & 1 deletion test/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_bad(self):
for args in ([], ['x'] * 4):
out = utils.check_output(['cryptosite', 'gather'] + args,
stderr=subprocess.STDOUT, retcode=2)
out = utils.check_output(['python', '-m',
out = utils.check_output([sys.executable, '-m',
'cryptosite.gather'] + args,
stderr=subprocess.STDOUT, retcode=2)

Expand Down
12 changes: 6 additions & 6 deletions test/test_patch_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ def mock_patch_dock_lig_score():
os.mkdir(subdir)
fname = os.path.join(subdir, 'patch_dock.Linux')
with open(fname, 'w') as fh:
fh.write("""#!/usr/bin/env python
fh.write("""#!%s
with open('ligands.ids') as fh:
ligands = [l.rstrip('\\r\\n') for l in fh.readlines()]
for i, lig in enumerate(ligands):
with open('test.pdb%d.res' % i, 'w') as fh:
with open('test.pdb%%d.res' %% i, 'w') as fh:
fh.write("receptorPdb (Str) test.pdb\\n")
fh.write("ligandPdb (Str) %s\\n" % lig)
fh.write("ligandPdb (Str) %%s\\n" %% lig)
fh.write(" # | score | pen. | Area | as1 | as2 | as12 | ACE | hydroph | Energy |cluster| dist. || Ligand Transformation\\n")
if i == 13:
fh.write(" 1 | 684 | -0.61 | 72.40 | 0 | 0 | 0 | -63.66 | 0.00 | 0.00 | 0 | 0.00 || -0.21078 -0.07140 0.71339 1.12228 -7.44875 0.86045\\n")
fh.write("Best Rmsd Result: 100000000.00 rank -1\\n")
fh.write("Best Rank Result: 100000000.00 rank 100000\\n")
""")
""" % sys.executable)
os.chmod(fname, 0o755)

fname = os.path.join(subdir, 'ligand_score_multiple')
with open(fname, 'w') as fh:
fh.write("""#!/usr/bin/env python
fh.write("""#!%s
import sys, os
pdb, ligand, trans = sys.argv[1:]
if not os.path.exists(pdb) or not os.path.exists(ligand):
Expand All @@ -45,7 +45,7 @@ def mock_patch_dock_lig_score():
with open('mol2_score.res', 'w') as fh:
if tr:
fh.write("Score for ISB.pdb trans 0 is -0.41\\n")
""")
""" % sys.executable)
os.chmod(fname, 0o755)

oldpath = os.environ['PATH']
Expand Down
2 changes: 1 addition & 1 deletion test/test_pockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_bad(self):
for args in (['x'],):
out = utils.check_output(['cryptosite', 'pockets'] + args,
stderr=subprocess.STDOUT, retcode=2)
out = utils.check_output(['python', '-m',
out = utils.check_output([sys.executable, '-m',
'cryptosite.pockets'] + args,
stderr=subprocess.STDOUT, retcode=2)

Expand Down
2 changes: 1 addition & 1 deletion test/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_bad(self):
for args in (['x', 'y'], []):
out = utils.check_output(['cryptosite', 'predict'] + args,
stderr=subprocess.STDOUT, retcode=2)
out = utils.check_output(['python', '-m',
out = utils.check_output([sys.executable, '-m',
'cryptosite.predict'] + args,
stderr=subprocess.STDOUT, retcode=2)

Expand Down
4 changes: 2 additions & 2 deletions test/test_seq_conservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def mock_usearch():
os.mkdir(subdir)
fname = os.path.join(subdir, 'usearch')
with open(fname, 'w') as fh:
fh.write("""#!/usr/bin/env python
fh.write("""#!%s
import sys
outf = sys.argv[4]
with open(outf, 'w') as fh:
Expand All @@ -31,7 +31,7 @@ def mock_usearch():
'EX70_12567', '*\\n']))
fh.write('\\t'.join(['H', '1', '292', '98.2', '+', '0', '0', '292M',
'AH70_12410', 'EX70_12567\\n']))
""")
""" % sys.executable)
os.chmod(fname, 0o755)

oldpath = os.environ['PATH']
Expand Down
2 changes: 1 addition & 1 deletion test/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_bad(self):
for args in (['x'], ['x']*3):
out = utils.check_output(['cryptosite', 'setup'] + args,
stderr=subprocess.STDOUT, retcode=2)
out = utils.check_output(['python', '-m',
out = utils.check_output([sys.executable, '-m',
'cryptosite.setup'] + args,
stderr=subprocess.STDOUT, retcode=2)

Expand Down
2 changes: 1 addition & 1 deletion test/test_soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_bad(self):
for args in (['x'],):
out = utils.check_output(['cryptosite', 'soap'] + args,
stderr=subprocess.STDOUT, retcode=2)
out = utils.check_output(['python', '-m',
out = utils.check_output([sys.executable, '-m',
'cryptosite.soap'] + args,
stderr=subprocess.STDOUT, retcode=2)

Expand Down

0 comments on commit ae9cbb3

Please sign in to comment.