-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathutil.py
36 lines (24 loc) · 831 Bytes
/
util.py
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
# This source code is part of the Biotite package and is distributed
# under the 3-Clause BSD License. Please see 'LICENSE.rst' for further
# information.
import importlib
import shutil
import urllib.error
import urllib.request
from os.path import dirname, join, realpath
def data_dir(subdir):
return join(dirname(realpath(__file__)), subdir, "data")
### Functions for conditional test skips ###
tested_urls = {}
def cannot_connect_to(url):
if url not in tested_urls:
try:
urllib.request.urlopen(url)
tested_urls[url] = False
except urllib.error.URLError:
tested_urls[url] = True
return tested_urls[url]
def cannot_import(module):
return importlib.util.find_spec(module) is None
def is_not_installed(program):
return shutil.which(program) is None