|
4 | 4 |
|
5 | 5 | from .activator import Activator |
6 | 6 |
|
7 | | -if sys.version_info >= (3, 7): |
8 | | - from importlib.resources import read_binary |
| 7 | +if sys.version_info >= (3, 10) or sys.version_info <= (3, 7): |
| 8 | + if sys.version_info >= (3, 10): |
| 9 | + from importlib.resources import files |
| 10 | + else: |
| 11 | + from importlib_resources import files |
| 12 | + |
| 13 | + def read_binary(module_name: str, filename: str) -> bytes: |
| 14 | + return (files(module_name) / filename).read_bytes() |
| 15 | + |
9 | 16 | else: |
10 | | - from importlib_resources import read_binary |
| 17 | + from importlib.resources import read_binary |
11 | 18 |
|
12 | 19 |
|
13 | 20 | class ViaTemplateActivator(Activator, metaclass=ABCMeta): |
@@ -43,11 +50,11 @@ def _generate(self, replacements, templates, to_folder, creator): |
43 | 50 | return generated |
44 | 51 |
|
45 | 52 | def as_name(self, template): |
46 | | - return template.name |
| 53 | + return template |
47 | 54 |
|
48 | 55 | def instantiate_template(self, replacements, template, creator): |
49 | 56 | # read content as binary to avoid platform specific line normalization (\n -> \r\n) |
50 | | - binary = read_binary(self.__module__, str(template)) |
| 57 | + binary = read_binary(self.__module__, template) |
51 | 58 | text = binary.decode("utf-8", errors="strict") |
52 | 59 | for key, value in replacements.items(): |
53 | 60 | value = self._repr_unicode(creator, value) |
|
0 commit comments