-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ACEnglish/master
pyproject.toml fixes pip installation
- Loading branch information
Showing
6 changed files
with
152 additions
and
142 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import os | ||
import glob | ||
import shutil | ||
import sysconfig | ||
import setuptools | ||
from subprocess import run | ||
from distutils import ccompiler | ||
from setuptools import Extension | ||
from Cython.Build import cythonize | ||
from setuptools.command.build_py import build_py as _build_py | ||
|
||
########### | ||
# Helpers # | ||
########### | ||
debug = False | ||
|
||
cy_options = { | ||
'annotate': False, | ||
'compiler_directives': { | ||
'profile': debug, | ||
'linetrace': debug, | ||
'boundscheck': debug, | ||
'wraparound': debug, | ||
'nonecheck': debug, | ||
'initializedcheck': debug, | ||
'language_level': 3 | ||
} | ||
} | ||
|
||
cfg_vars = sysconfig.get_config_vars() | ||
for key, value in cfg_vars.items(): | ||
if type(value) == str: | ||
cfg_vars[key] = value.replace("-Wstrict-prototypes", "") | ||
|
||
def has_flag(compiler, flagname): | ||
"""Return a boolean indicating whether a flag name is supported on | ||
the specified compiler. | ||
""" | ||
import tempfile | ||
with tempfile.NamedTemporaryFile('w', suffix='.c') as f: | ||
f.write('int main (int argc, char **argv) { return 0; }') | ||
try: | ||
compiler.compile([f.name], extra_postargs=[flagname]) | ||
except setuptools.distutils.errors.CompileError: | ||
return False | ||
return True | ||
|
||
def get_extra_args(flags): | ||
compiler = ccompiler.new_compiler() | ||
extra_compile_args = [] | ||
for f in flags: | ||
if has_flag(compiler, f): | ||
extra_compile_args.append(f) | ||
return extra_compile_args | ||
|
||
################## | ||
# WFA2_lib build # | ||
################## | ||
extras = ["-Wno-unused-function", "-Wno-unused-result", '-Wno-ignored-qualifiers', "-Wno-deprecated-declarations"] | ||
extras_pywfa = get_extra_args(extras) | ||
|
||
root = os.path.abspath(os.path.dirname(__file__)) | ||
wfa = os.path.join(root, "pywfa/WFA2_lib") | ||
libraries = [f"{wfa}/lib"] | ||
library_dirs = [f"{wfa}/lib"] | ||
include_dirs = [".", root, wfa, f"{wfa}/lib", f"{wfa}/utils", f"{wfa}/wavefront", f"{wfa}/bindings/cpp", f"{wfa}/system", | ||
f"{wfa}/alignment", f"{root}/pywfa"] | ||
|
||
print("Libs", libraries) | ||
print("Library dirs", library_dirs) | ||
print("Include dirs", include_dirs) | ||
|
||
# Can't get openmp to behave. Whenever its on (1), the build fails. | ||
# this has happened on multiple OS with/without `libomp-dev` | ||
# compiler = ccompiler.new_compiler() | ||
omp = 0 #1 if has_flag(compiler, "-fopenmp") else 0 | ||
ret = run(f"cd pywfa/WFA2_lib; make clean all BUILD_WFA_PARALLEL={omp} BUILD_MINIMAL=1; cd ../../", shell=True) | ||
if ret.returncode != 0: | ||
print("Unable to build WFA2_lib") | ||
print(ret) | ||
exit(ret.returncode) | ||
|
||
################## | ||
# bindings build # | ||
################## | ||
m_ext_module = cythonize(Extension("pywfa.align", | ||
["pywfa/align.pyx"], | ||
libraries=libraries, | ||
library_dirs=library_dirs, | ||
include_dirs=include_dirs, | ||
extra_compile_args=extras_pywfa, | ||
language="c", | ||
extra_objects=[f"{wfa}/lib/libwfa.a"] | ||
), | ||
**cy_options) | ||
|
||
shared = glob.glob(f"{root}/build/lib*/pywfa/*.so") + glob.glob(f"{root}/build/lib*/pywfa/*.dll") | ||
[shutil.copy(i, f"{root}/pywfa") for i in shared] | ||
|
||
################### | ||
# Basic build_ext # | ||
################### | ||
# Thanks to https://stackoverflow.com/questions/73800736/pyproject-toml-and-cython-extension-module | ||
class build_py(_build_py): | ||
def run(self): | ||
self.run_command("build_ext") | ||
return super().run() | ||
|
||
def initialize_options(self): | ||
super().initialize_options() | ||
if self.distribution.ext_modules == None: | ||
self.distribution.ext_modules = [] | ||
|
||
self.distribution.ext_modules.extend( | ||
m_ext_module | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[build-system] | ||
requires = ["setuptools>=61.0", "cython"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name="pywfa" | ||
version='0.4.1' | ||
description="Align sequences using WFA2-lib" | ||
requires-python='>=3.7' | ||
readme = "README.rst" | ||
authors = [ | ||
{ name = "Kez Cleal", email = "clealk@cardiff.ac.uk" } | ||
] | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
] | ||
|
||
[tool.setuptools] | ||
py-modules = ["_custom_build"] | ||
packages=["pywfa", "pywfa.tests", "pywfa.WFA2_lib"] | ||
|
||
[tool.setuptools.cmdclass] | ||
build_py = "_custom_build.build_py" | ||
|
||
[project.urls] | ||
Repository="https://github.com/kcleal/pywfa" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from __future__ import absolute_import | ||
from .align import WavefrontAligner, clip_cigartuples, cigartuples_to_str, elide_mismatches_from_cigar | ||
|
||
from pywfa.align import ( | ||
WavefrontAligner, | ||
clip_cigartuples, | ||
cigartuples_to_str, | ||
elide_mismatches_from_cigar, | ||
) |