Debian Codegraph @

setup.py

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/env python3
2 """
3 Run 'python3 setup.py install' to install Porechop.
4 """
5
6 # Make sure this is being run with Python 3.4 or later.
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 # Install setuptools if not already present.
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 # Get the program version from another file.
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) # Run original build code
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) # Run original install code
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
82 def finalize_options(self):
83 self.cwd = os.getcwd()
84
85 def run(self):
86 assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd
87
88 delete_directories = []
89 for root, dir_names, filenames in os.walk(self.cwd):
90 for dir_name in fnmatch.filter(dir_names, '*.egg-info'):
91 delete_directories.append(os.path.join(root, dir_name))
92 for dir_name in fnmatch.filter(dir_names, 'build'):
93 delete_directories.append(os.path.join(root, dir_name))
94 for dir_name in fnmatch.filter(dir_names, '__pycache__'):
95 delete_directories.append(os.path.join(root, dir_name))
96 for delete_directory in delete_directories:
97 print('Deleting directory:', delete_directory)
98 shutil.rmtree(delete_directory)
99
100 delete_files = []
101 for root, dir_names, filenames in os.walk(self.cwd):
102 for filename in fnmatch.filter(filenames, 'setuptools*.zip'):
103 delete_files.append(os.path.join(root, filename))
104 for filename in fnmatch.filter(filenames, '*.o'):
105 delete_files.append(os.path.join(root, filename))
106 for filename in fnmatch.filter(filenames, '*.pyc'):
107 delete_files.append(os.path.join(root, filename))
108 for delete_file in delete_files:
109 print('Deleting file:', delete_file)
110 os.remove(delete_file)
111
112
113 setup(name='porechop',
114 version=__version__,
115 description='Porechop',
116 long_description=LONG_DESCRIPTION,
117 url='http://github.com/rrwick/porechop',
118 author='Ryan Wick',
119 author_email='[email protected]',
120 license='GPL',
121 packages=['porechop'],
122 entry_points={"console_scripts": ['porechop = porechop.porechop:main']},
123 zip_safe=False,
124 cmdclass={'build': PorechopBuild,
125 'install': PorechopInstall,
126 'clean': PorechopClean}
127 )