| 1 |
|
| 2 |
""" |
| 3 |
Run 'python3 setup.py install' to install Porechop. |
| 4 |
""" |
| 5 |
|
| 6 |
|
| 7 |
import sys |
| 8 |
if sys.version_info.major != 3 or sys.version_info.minor < 4: |
| 9 |
print('Error: you must execute setup.py using Python 3.4 or later') |
| 10 |
sys.exit(1) |
| 11 |
|
| 12 |
import os |
| 13 |
import shutil |
| 14 |
from distutils.command.build import build |
| 15 |
from distutils.core import Command |
| 16 |
import subprocess |
| 17 |
import multiprocessing |
| 18 |
import fnmatch |
| 19 |
import importlib.util |
| 20 |
|
| 21 |
|
| 22 |
if not importlib.util.find_spec("setuptools"): |
| 23 |
import ez_setup |
| 24 |
ez_setup.use_setuptools() |
| 25 |
|
| 26 |
from setuptools import setup |
| 27 |
from setuptools.command.install import install |
| 28 |
|
| 29 |
|
| 30 |
exec(open('porechop/version.py').read()) |
| 31 |
|
| 32 |
with open('README.md', 'rb') as readme: |
| 33 |
LONG_DESCRIPTION = readme.read().decode() |
| 34 |
|
| 35 |
|
| 36 |
class PorechopBuild(build): |
| 37 |
""" |
| 38 |
The build process runs the Makefile to build the C++ functions into a shared library. |
| 39 |
""" |
| 40 |
|
| 41 |
def run(self): |
| 42 |
build.run(self) |
| 43 |
|
| 44 |
clean_cmd = ['make', 'clean'] |
| 45 |
try: |
| 46 |
make_cmd = ['make', '-j', str(min(8, multiprocessing.cpu_count()))] |
| 47 |
except NotImplementedError: |
| 48 |
make_cmd = ['make'] |
| 49 |
|
| 50 |
def clean_cpp(): |
| 51 |
subprocess.call(clean_cmd) |
| 52 |
|
| 53 |
def compile_cpp(): |
| 54 |
subprocess.call(make_cmd) |
| 55 |
|
| 56 |
self.execute(clean_cpp, [], 'Cleaning previous compilation: ' + ' '.join(clean_cmd)) |
| 57 |
self.execute(compile_cpp, [], 'Compiling Porechop: ' + ' '.join(make_cmd)) |
| 58 |
|
| 59 |
|
| 60 |
class PorechopInstall(install): |
| 61 |
""" |
| 62 |
The install process copies the C++ shared library to the install location. |
| 63 |
""" |
| 64 |
|
| 65 |
def run(self): |
| 66 |
install.run(self) |
| 67 |
shutil.copyfile(os.path.join('porechop', 'cpp_functions.so'), |
| 68 |
os.path.join(self.install_lib, 'porechop', 'cpp_functions.so')) |
| 69 |
|
| 70 |
|
| 71 |
class PorechopClean(Command): |
| 72 |
""" |
| 73 |
Custom clean command that really cleans up everything, except for: |
| 74 |
- the compiled *.so file needed when running the programs |
| 75 |
- setuptools-*.egg file needed when running this script |
| 76 |
""" |
| 77 |
user_options = [] |
| 78 |
|
| 79 |
def initialize_options(self): |
| 80 |
self.cwd = None |
| •81 |
self.all = None |
| 82 |
|
| 83 |
def finalize_options(self): |
| 84 |
self.cwd = os.getcwd() |
| 85 |
|
| 86 |
def run(self): |
| 87 |
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd |
| 88 |
|
| 89 |
delete_directories = [] |
| 90 |
for root, dir_names, filenames in os.walk(self.cwd): |
| 91 |
for dir_name in fnmatch.filter(dir_names, '*.egg-info'): |
| 92 |
delete_directories.append(os.path.join(root, dir_name)) |
| 93 |
for dir_name in fnmatch.filter(dir_names, 'build'): |
| 94 |
delete_directories.append(os.path.join(root, dir_name)) |
| 95 |
for dir_name in fnmatch.filter(dir_names, '__pycache__'): |
| 96 |
delete_directories.append(os.path.join(root, dir_name)) |
| 97 |
for delete_directory in delete_directories: |
| 98 |
print('Deleting directory:', delete_directory) |
| 99 |
shutil.rmtree(delete_directory) |
| 100 |
|
| 101 |
delete_files = [] |
| 102 |
for root, dir_names, filenames in os.walk(self.cwd): |
| 103 |
for filename in fnmatch.filter(filenames, 'setuptools*.zip'): |
| 104 |
delete_files.append(os.path.join(root, filename)) |
| 105 |
for filename in fnmatch.filter(filenames, '*.o'): |
| 106 |
delete_files.append(os.path.join(root, filename)) |
| 107 |
for filename in fnmatch.filter(filenames, '*.pyc'): |
| 108 |
delete_files.append(os.path.join(root, filename)) |
| 109 |
for delete_file in delete_files: |
| 110 |
print('Deleting file:', delete_file) |
| 111 |
os.remove(delete_file) |
| 112 |
|
| 113 |
|
| 114 |
setup(name='porechop', |
| 115 |
version=__version__, |
| 116 |
description='Porechop', |
| 117 |
long_description=LONG_DESCRIPTION, |
| 118 |
url='http://github.com/rrwick/porechop', |
| 119 |
author='Ryan Wick', |
| 120 |
author_email='[email protected]', |
| 121 |
license='GPL', |
| 122 |
packages=['porechop'], |
| 123 |
entry_points={"console_scripts": ['porechop = porechop.porechop:main']}, |
| 124 |
zip_safe=False, |
| 125 |
cmdclass={'build': PorechopBuild, |
| 126 |
'install': PorechopInstall, |
| 127 |
'clean': PorechopClean} |
| 128 |
) |