From 22720233d033feec2a3525121ead52f33cf5becc Mon Sep 17 00:00:00 2001 From: Ivan Blagoev Topolsky Date: Mon, 27 Jul 2020 16:39:27 +0200 Subject: [PATCH] setuptools dependency on Mac OS X --- src/shorah/amplicon.py | 13 +++++++++---- src/shorah/cli.py | 3 +++ src/shorah/shorah_snv.py | 11 +++++++---- src/shorah/shotgun.py | 13 +++++++++---- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/shorah/amplicon.py b/src/shorah/amplicon.py index bae5054..e142bbf 100644 --- a/src/shorah/amplicon.py +++ b/src/shorah/amplicon.py @@ -38,7 +38,6 @@ import logging import logging.handlers -from pkg_resources import resource_filename from Bio import SeqIO @@ -53,10 +52,16 @@ from . import shorah_snv # Try fetching diri and b2w exe with pkg resources -diri_exe = resource_filename(__name__, 'bin/diri_sampler') -b2w_exe = resource_filename(__name__, 'bin/b2w') +try: + from pkg_resources import resource_filename +except ModuleNotFoundError: + diri_exe = None + b2w_exe = None +else: + diri_exe = resource_filename(__name__, 'bin/diri_sampler') + b2w_exe = resource_filename(__name__, 'bin/b2w') # Try fetching diri and b2w exe with bash 'which' -if not (os.path.exists(diri_exe) and os.path.exists(b2w_exe)): +if not (diri_exe and b2w_exe) or not (os.path.exists(diri_exe) and os.path.exists(b2w_exe)): diri_exe = shutil.which('diri_sampler') b2w_exe = shutil.which('b2w') if not (diri_exe and b2w_exe): diff --git a/src/shorah/cli.py b/src/shorah/cli.py index 63a2ffe..2a95eaa 100644 --- a/src/shorah/cli.py +++ b/src/shorah/cli.py @@ -42,6 +42,7 @@ import sys +use_pkg_resources = False; all_dirs = os.path.abspath(__file__).split(os.sep) base_dir = os.sep.join(all_dirs[:-all_dirs[::-1].index('shorah')]) version_fname = os.path.join(base_dir, '.version') @@ -57,6 +58,8 @@ except DistributionNotFound: __version__ = 'unknown' print("cannot find version", file=sys.stderr) + else: + use_pkg_resources = True; # manipulate path to import functions parent_dir = os.path.join(base_dir, 'src') diff --git a/src/shorah/shorah_snv.py b/src/shorah/shorah_snv.py index 434deb2..028eb39 100644 --- a/src/shorah/shorah_snv.py +++ b/src/shorah/shorah_snv.py @@ -44,12 +44,15 @@ import logging -from pkg_resources import resource_filename - # Try fetching fil exe with pkg resources -fil_exe = resource_filename(__name__, 'bin/fil') +try: + from pkg_resources import resource_filename +except ModuleNotFoundError: + fil_exe = None +else: + fil_exe = resource_filename(__name__, 'bin/fil') # Try fetching fil exe with bash 'which' -if not os.path.exists(fil_exe): +if not fil_exe or not os.path.exists(fil_exe): fil_exe = shutil.which('fil') if not fil_exe: # Try fetching fil exe based on directory structure diff --git a/src/shorah/shotgun.py b/src/shorah/shotgun.py index 684b80a..ecaebcd 100644 --- a/src/shorah/shotgun.py +++ b/src/shorah/shotgun.py @@ -35,7 +35,6 @@ import sys import shlex import logging -from pkg_resources import resource_filename import re import shutil @@ -52,10 +51,16 @@ from . import shorah_snv # Try fetching diri and b2w exe with pkg resources -diri_exe = resource_filename(__name__, 'bin/diri_sampler') -b2w_exe = resource_filename(__name__, 'bin/b2w') +try: + from pkg_resources import resource_filename +except ModuleNotFoundError: + diri_exe = None + b2w_exe = None +else: + diri_exe = resource_filename(__name__, 'bin/diri_sampler') + b2w_exe = resource_filename(__name__, 'bin/b2w') # Try fetching diri and b2w exe with bash 'which' -if not (os.path.exists(diri_exe) and os.path.exists(b2w_exe)): +if not (diri_exe and b2w_exe) or not (os.path.exists(diri_exe) and os.path.exists(b2w_exe)): diri_exe = shutil.which('diri_sampler') b2w_exe = shutil.which('b2w') if not (diri_exe and b2w_exe):