From e59556dd605b3e0671b65b86ba01666ed2fc9c75 Mon Sep 17 00:00:00 2001 From: SCM Date: Fri, 20 May 2022 16:27:05 +0100 Subject: [PATCH] Fixed setuptools so that cython works nicely in the modern era. python setup.py install actually installs now, while python setup.py build_ext --inplace builds the cython scripts --- README.md | 2 +- setup.py | 51 +++++++---------------- {src/biobox/test => test}/EMD-1080.mrc | Bin {src/biobox/test => test}/HSP.pdb | 0 {src/biobox/test => test}/test_biobox.py | 21 +++++++--- 5 files changed, 30 insertions(+), 44 deletions(-) rename {src/biobox/test => test}/EMD-1080.mrc (100%) rename {src/biobox/test => test}/HSP.pdb (100%) rename {src/biobox/test => test}/test_biobox.py (89%) diff --git a/README.md b/README.md index b4addee..0e8c6ae 100644 --- a/README.md +++ b/README.md @@ -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]( diff --git a/setup.py b/setup.py index 696e665..3c488fd 100644 --- a/setup.py +++ b/setup.py @@ -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") diff --git a/src/biobox/test/EMD-1080.mrc b/test/EMD-1080.mrc similarity index 100% rename from src/biobox/test/EMD-1080.mrc rename to test/EMD-1080.mrc diff --git a/src/biobox/test/HSP.pdb b/test/HSP.pdb similarity index 100% rename from src/biobox/test/HSP.pdb rename to test/HSP.pdb diff --git a/src/biobox/test/test_biobox.py b/test/test_biobox.py similarity index 89% rename from src/biobox/test/test_biobox.py rename to test/test_biobox.py index 0fac03f..7255756 100644 --- a/src/biobox/test/test_biobox.py +++ b/test/test_biobox.py @@ -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): @@ -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) @@ -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()