Skip to content

Commit

Permalink
Fixed setuptools so that cython works nicely in the modern era. pytho…
Browse files Browse the repository at this point in the history
…n setup.py install actually installs now, while python setup.py build_ext --inplace builds the cython scripts
  • Loading branch information
SCMusson committed May 20, 2022
1 parent 33d2eff commit e59556d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Biobox requires Python3.x and the following packages:
* scikit-learn
* cython

Biobox can be installed with: `pip install biobox`. Biobox can otherwise be installed manually typing the followin command in the Biobox folder: `python setup.py install`. Please make sure the folder where Biobox is located is in your PYTHONPATH.
Biobox can be installed with: `pip install biobox`. Biobox can otherwise be installed manually typing the followin command in the Biobox folder: `python setup.py build_ext --inplace` followed by `python setup.py install`. Please make sure the folder where Biobox is located is in your PYTHONPATH.

Optional external software:
* CCS calculation relies on a call to [IMPACT](
Expand Down
51 changes: 14 additions & 37 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,23 @@
from Cython.Build import cythonize


class InstallCommand(build_ext):

def run(self):

build_ext.run(self)

try:
for root, dirnames, filenames in os.walk("build"):
for filename in filenames:
extension = filename.split(".")[-1]
if extension in ["pyd", "so"]:
os.rename(os.path.join(root, filename), filename)

except Exception:
print("files already exist, skipping...")

shutil.rmtree("build")

os.chdir(f"src{os.sep}biobox{os.sep}lib")

# small hack to get around a problem in older cython versions, i.e.
# an infinite dependencies loop when __init__.py file is in the same folder as pyx
#if os.path.exists("__init__.py"):
# os.rename("__init__.py", "tmp")


packages=find_packages(where='src')
print('packages being: ', packages)
pyx_files = []
for package in packages:
package_path = f'src{os.sep}{os.sep.join(package.split("."))}'
for file in os.listdir(package_path):
if file.split('.')[-1]=='pyx':
pyx_files.append(f'{package_path}{os.sep}{file}')
setup(
name = 'biobox',
version='1.0.0',
#authors='Many Handsome People',
#license = '',
version='1.1.0',
include_dirs=[np.get_include()],
ext_modules=cythonize(
"*.pyx",
pyx_files,#"*.pyx",
include_path=[np.get_include()],
compiler_directives={'boundscheck': False, 'wraparound': False}),
cmdclass={'install': InstallCommand},
#packages=['biobox'],
packages=find_packages(where='src'),
compiler_directives={'boundscheck': False, 'wraparound': False}),
package_data={"":["*.dat"]},
packages=packages,
package_dir={"":"src"},
)

# continuation of the small hack
#os.rename("tmp", "__init__.py")
File renamed without changes.
File renamed without changes.
21 changes: 15 additions & 6 deletions src/biobox/test/test_biobox.py → test/test_biobox.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import unittest
import sys, os

sys.path.append(os.sep.join(os.getcwd().split(os.sep)[:-2]))
if 'CONDA_BUILD_STATE' in os.environ and os.environ['CONDA_BUILD_STATE']=='TEST':
pass
else:
sys.path.append(os.sep.join(os.getcwd().split(os.sep)[:-1])+os.sep+'src')
import biobox as bb

class test_density(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -74,8 +76,11 @@ def test_SASA(self):


def test_monomer_CCS(self):

print("\n> testing CCS")
if 'IMPACTPATH' in os.environ:
print("\n> testing CCS")
else:
print("\n\n> IMPACTPATH not set therefore can't test CCS. \n WARNING: If you want CCS calculations you need to set IMPACTPATH")
return

try:
ccs1 = bb.ccs(self.M)
Expand All @@ -91,8 +96,12 @@ def test_monomer_CCS(self):


def test_multimer_CCS(self):
if 'IMPACTPATH' in os.environ:
print("\n> testing multimer CCS")
else:
print("\n\n> IMPACTPATH not set therefore can't test CCS. \n WARNING: If you want CCS calculations you need to set IMPACTPATH")
return

print("\n> testing multimer CCS")

try:
A = bb.Multimer()
Expand Down

0 comments on commit e59556d

Please sign in to comment.