1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
import os
import sys
import glob
import tarfile
import zipfile
import urllib.request
from setuptools import setup, Extension
from setuptools.command import build_ext
root_dir = os.path.dirname(os.path.abspath(__file__))
sources = glob.glob(os.path.join(root_dir, 'src', '*.c'))
link_args = ['-lsqlite3']
link_args.extend(os.environ['LDFLAGS'].split(' '))
comp_args = []
comp_args.extend(os.environ['CPPFLAGS'].split(' '))
comp_args.extend(os.environ['CFLAGS'].split(' '))
include_dirs = []
def prepare_zlib():
global include_dirs
global sources
zlib_dir = os.path.join(root_dir, "zlib-1.3.1")
zlib_file = os.path.join(root_dir, "zlib-1.3.1.zip")
url = "https://github.com/madler/zlib/releases/download/v1.3.1/zlib131.zip"
if not os.path.exists(zlib_dir):
if not os.path.isfile(zlib_file):
urllib.request.urlretrieve(url, zlib_file)
with zipfile.ZipFile(zlib_file) as _zip:
_zip.extractall()
include_dirs.append(zlib_dir)
sources.extend(glob.glob(os.path.join(zlib_dir, '*.c')))
def prepare_sqlite3():
global include_dirs
global sources
sqlite_dir = os.path.join(root_dir, "sqlite-amalgamation-3470200")
sqlite_file = os.path.join(root_dir, "sqlite-amalgamation-3470200.zip")
url = "https://www.sqlite.org/2024/sqlite-amalgamation-3470200.zip"
if not os.path.exists(sqlite_dir):
if not os.path.isfile(sqlite_file):
urllib.request.urlretrieve(url, sqlite_file)
with zipfile.ZipFile(sqlite_file) as _zip:
_zip.extractall()
include_dirs.append(sqlite_dir)
sources.append(os.path.join(sqlite_dir, 'sqlite3.c'))
def prepare_indexed_gzip():
global include_dirs
global sources
igzip_dir = os.path.join(root_dir, "indexed_gzip-1.9.4", "indexed_gzip")
igzip_file = os.path.join(root_dir, "indexed_gzip-1.9.4.zip")
url = "https://github.com/pauldmccarthy/indexed_gzip/archive/refs/tags/v1.9.4.zip"
if not os.path.exists(igzip_dir):
if not os.path.isfile(igzip_file):
urllib.request.urlretrieve(url, igzip_file)
with zipfile.ZipFile(igzip_file) as _zip:
_zip.extractall()
include_dirs.append(igzip_dir)
sources.extend(glob.glob(os.path.join(igzip_dir, 'zran*.c')))
if sys.platform.startswith('win'):
comp_args.extend([
'/D_LFS64_LARGEFILE',
'/D_LARGEFILE64_SOURCE',
'/D_FILE_OFFSET_BITS=64'
])
else:
comp_args.extend([
'-Wno-unused-result',
'-D_FILE_OFFSET_BITS=64'
])
if sys.platform.startswith('darwin'):
comp_args.append('-DHAVE_UNISTD_H')
else:
comp_args.extend([
'-D_LFS64_LARGEFILE',
'-D_LARGEFILE64_SOURCE'
])
class CustomBuildExt(build_ext.build_ext):
def build_extensions(self):
if not sys.platform.startswith(('win', 'darwin')):
if '--debug' in sys.argv:
self.compiler.compiler_so = [
opt
for opt in self.compiler.compiler_so
if opt != '-O2'
]
self.compiler.compiler_so.append('-O0')
self.compiler.compiler_so.append('--coverage')
self.compiler.linker_so = [
opt
for opt in self.compiler.linker_so
if opt != '-O2'
]
self.compiler.linker_so.append('-O0')
self.compiler.linker_so.append('--coverage')
else:
self.compiler.compiler_so = [
opt
for opt in self.compiler.compiler_so
if opt != '-g'
]
self.compiler.linker_so = [
opt
for opt in self.compiler.linker_so
if opt != '-g'
]
super().build_extensions()
#if not sys.platform.startswith('linux'):
#prepare_sqlite3()
#prepare_zlib()
#prepare_indexed_gzip()
extension = Extension('pyfastx',
sources = sources,
include_dirs = include_dirs,
extra_compile_args = comp_args,
extra_link_args = link_args
)
description = (
"pyfastx is a python module for fast random "
"access to sequences from plain and gzipped "
"FASTA/Q file"
)
with open(os.path.join(root_dir, 'README.rst')) as fh:
long_description = fh.read()
with open(os.path.join(root_dir, 'src', 'version.h')) as fh:
version = fh.read().split()[2].strip('"')
setup(
name = 'pyfastx',
version = version,
ext_modules = [extension],
description = description,
long_description = long_description,
#long_description_content_type = 'text/x-rst',
author = 'Lianming Du',
author_email = 'adullb@qq.com',
url = 'https://github.com/lmdu/pyfastx',
license = 'MIT',
keywords = 'fasta fastq sequence bioinformatics',
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"Natural Language :: English",
"License :: OSI Approved :: MIT License",
"Programming Language :: C",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Operating System :: Unix",
"Topic :: Scientific/Engineering :: Bio-Informatics"
],
entry_points = {
'console_scripts': ['pyfastx = pyfastxcli:main']
},
py_modules = ["pyfastxcli"],
test_suite = "tests",
cmdclass = {
'build_ext': CustomBuildExt
}
)
|