| 1 |
#!/usr/bin/env python3 |
| 2 |
""" |
| 3 |
Run 'pip install .' to install Readucks. |
| 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('readucks/version.py').read()) |
| 31 |
|
| 32 |
with open('README.md', 'rb') as readme: |
| 33 |
LONG_DESCRIPTION = readme.read().decode() |
| 34 |
|
| 35 |
|
| 36 |
class Build(build): |
| 37 |
""" |
| 38 |
The build process. |
| 39 |
""" |
| 40 |
|
| 41 |
def run(self): |
| 42 |
build.run(self) # Run original build code |
| 43 |
|
| 44 |
|
| 45 |
class Install(install): |
| 46 |
""" |
| 47 |
The install process. |
| 48 |
""" |
| 49 |
|
| 50 |
def run(self): |
| 51 |
install.run(self) # Run original install code |
| 52 |
|
| 53 |
|
| 54 |
class Clean(Command): |
| 55 |
""" |
| 56 |
Custom clean command that really cleans up everything, except for: |
| 57 |
- the compiled *.so file needed when running the programs |
| 58 |
- setuptools-*.egg file needed when running this script |
| 59 |
""" |
| 60 |
user_options = [] |
| 61 |
|
| 62 |
def initialize_options(self): |
| 63 |
self.cwd = None |
| 64 |
|
| 65 |
def finalize_options(self): |
| 66 |
self.cwd = os.getcwd() |
| 67 |
|
| 68 |
def run(self): |
| 69 |
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd |
| 70 |
|
| 71 |
delete_directories = [] |
| 72 |
for root, dir_names, filenames in os.walk(self.cwd): |
| 73 |
for dir_name in fnmatch.filter(dir_names, '*.egg-info'): |
| 74 |
delete_directories.append(os.path.join(root, dir_name)) |
| 75 |
for dir_name in fnmatch.filter(dir_names, 'build'): |
| 76 |
delete_directories.append(os.path.join(root, dir_name)) |
| 77 |
for dir_name in fnmatch.filter(dir_names, '__pycache__'): |
| 78 |
delete_directories.append(os.path.join(root, dir_name)) |
| 79 |
for delete_directory in delete_directories: |
| 80 |
print('Deleting directory:', delete_directory) |
| 81 |
shutil.rmtree(delete_directory) |
| 82 |
|
| 83 |
delete_files = [] |
| 84 |
for root, dir_names, filenames in os.walk(self.cwd): |
| 85 |
for filename in fnmatch.filter(filenames, 'setuptools*.zip'): |
| 86 |
delete_files.append(os.path.join(root, filename)) |
| 87 |
for filename in fnmatch.filter(filenames, '*.o'): |
| 88 |
delete_files.append(os.path.join(root, filename)) |
| 89 |
for filename in fnmatch.filter(filenames, '*.pyc'): |
| 90 |
delete_files.append(os.path.join(root, filename)) |
| 91 |
for delete_file in delete_files: |
| 92 |
print('Deleting file:', delete_file) |
| 93 |
os.remove(delete_file) |
| 94 |
|
| 95 |
|
| 96 |
setup(name='readucks', |
| 97 |
version=__version__, |
| 98 |
description='Readucks: a simple demultiplexer for nanopore reads', |
| 99 |
long_description=LONG_DESCRIPTION, |
| 100 |
long_description_content_type="text/markdown", |
| 101 |
url='http://github.com/rambaut/readucks', |
| 102 |
author='Andrew Rambaut', |
| 103 |
author_email='[email protected]', |
| 104 |
license='GPL', |
| 105 |
packages=['readucks'], |
| 106 |
entry_points={"console_scripts": ['readucks = readucks.readucks:main']}, |
| 107 |
zip_safe=False, |
| 108 |
cmdclass={'build': Build, |
| 109 |
'install': Install, |
| 110 |
'clean': Clean} |
| 111 |
) |