|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import os |
| 4 | +import sys |
4 | 5 |
|
5 | 6 | import click |
6 | 7 | from tutor import fmt, hooks, config as tutor_config |
7 | 8 |
|
8 | 9 | from .__about__ import __version__ |
9 | 10 |
|
10 | | -try: |
11 | | - import importlib.resources as importlib_resources |
12 | | -except ImportError: |
13 | | - import importlib_resources |
| 11 | +if sys.version_info >= (3, 9): |
| 12 | + from importlib.resources import files as importlib_resources_files |
| 13 | +else: |
| 14 | + import pkg_resources |
14 | 15 |
|
15 | 16 | ############### |
16 | 17 | # CONFIGURATION |
|
45 | 46 | ("lms", ("wordpress", "tasks", "lms", "init.sh")), |
46 | 47 | ] |
47 | 48 |
|
| 49 | + |
| 50 | +def get_template_full_path(package_name: str, *template_path: str) -> str: |
| 51 | + if sys.version_info >= (3, 9): |
| 52 | + return str( |
| 53 | + importlib_resources_files(package_name) |
| 54 | + / os.path.join("templates", *template_path) |
| 55 | + ) |
| 56 | + else: |
| 57 | + resource_path = pkg_resources.resource_filename(package_name, "") |
| 58 | + return os.path.join(resource_path, "templates", *template_path) |
| 59 | + |
| 60 | + |
48 | 61 | for service, template_path in MY_INIT_TASKS: |
49 | | - full_path: str = str( |
50 | | - importlib_resources.files("tutorwordpress") |
51 | | - / os.path.join("templates", *template_path) |
52 | | - ) |
| 62 | + full_path: str = get_template_full_path("tutorwordpress", *template_path) |
53 | 63 | with open(full_path, encoding="utf-8") as init_task_file: |
54 | 64 | init_task: str = init_task_file.read() |
55 | 65 | hooks.Filters.CLI_DO_INIT_TASKS.add_item((service, init_task)) |
|
0 commit comments