|
1 | 1 | # ruff: noqa: F403 F405 (Ignore Pyreason import * for public api) |
2 | 2 | # Set numba environment variable |
3 | 3 | import os |
| 4 | +import sys |
4 | 5 | package_path = os.path.abspath(os.path.dirname(__file__)) |
5 | 6 | cache_path = os.path.join(package_path, 'cache') |
6 | 7 | cache_status_path = os.path.join(package_path, '.cache_status.yaml') |
|
9 | 10 |
|
10 | 11 | from pyreason.pyreason import * |
11 | 12 | import yaml |
12 | | -from importlib.metadata import version |
13 | | -from pkg_resources import get_distribution, DistributionNotFound |
| 13 | +from importlib.metadata import PackageNotFoundError, version |
14 | 14 |
|
15 | 15 | try: |
16 | | - __version__ = get_distribution(__name__).version |
17 | | -except DistributionNotFound: |
| 16 | + __version__ = version(__name__) |
| 17 | +except PackageNotFoundError: |
18 | 18 | # package is not installed |
19 | 19 | pass |
20 | 20 |
|
21 | 21 |
|
22 | 22 | with open(cache_status_path) as file: |
23 | 23 | cache_status = yaml.safe_load(file) |
24 | 24 |
|
25 | | -if not cache_status['initialized']: |
| 25 | +running_tests = 'pytest' in sys.modules or 'unittest' in sys.modules |
| 26 | + |
| 27 | +if not cache_status['initialized'] and not running_tests: |
26 | 28 | print('Imported PyReason for the first time. Initializing caches for faster runtimes ... this will take a minute') |
27 | 29 | graph_path = os.path.join(package_path, 'examples', 'hello-world', 'friends_graph.graphml') |
28 | 30 |
|
|
37 | 39 | print('PyReason initialized!') |
38 | 40 | print() |
39 | 41 |
|
40 | | - # Update cache status (skip under test runners to keep repo file clean) |
41 | | - import sys |
42 | | - if 'pytest' not in sys.modules and 'unittest' not in sys.modules: |
43 | | - cache_status['initialized'] = True |
44 | | - with open(cache_status_path, 'w') as file: |
45 | | - yaml.dump(cache_status, file) |
| 42 | + cache_status['initialized'] = True |
| 43 | + with open(cache_status_path, 'w') as file: |
| 44 | + yaml.dump(cache_status, file) |
0 commit comments