-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathbuild_strategy.py
638 lines (545 loc) · 27.4 KB
/
build_strategy.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
"""
Keeps implementation of different build strategies
"""
import hashlib
import logging
import os.path
import pathlib
import shutil
from abc import abstractmethod, ABC
from copy import deepcopy
from typing import Callable, Dict, List, Any, Optional, cast, Set, Tuple, TypeVar
from samcli.commands._utils.experimental import is_experimental_enabled, ExperimentalFlag
from samcli.lib.utils import osutils
from samcli.lib.utils.async_utils import AsyncContext
from samcli.lib.utils.hash import dir_checksum
from samcli.lib.utils.packagetype import ZIP, IMAGE
from samcli.lib.build.dependency_hash_generator import DependencyHashGenerator
from samcli.lib.build.build_graph import (
BuildGraph,
FunctionBuildDefinition,
LayerBuildDefinition,
AbstractBuildDefinition,
DEFAULT_DEPENDENCIES_DIR,
)
from samcli.lib.build.exceptions import MissingBuildMethodException
from samcli.lib.build.utils import warn_on_invalid_architecture
from samcli.lib.utils.architecture import X86_64, ARM64
LOG = logging.getLogger(__name__)
# type definition which can be used in generic types for both FunctionBuildDefinition & LayerBuildDefinition
FunctionOrLayerBuildDefinition = TypeVar(
"FunctionOrLayerBuildDefinition", FunctionBuildDefinition, LayerBuildDefinition
)
def clean_redundant_folders(base_dir: str, uuids: Set[str]) -> None:
"""
Compares existing folders inside base_dir and removes the ones which is not in the uuids set.
Parameters
----------
base_dir : str
Base directory that it will be operating
uuids : Set[str]
Expected folder names. If any folder name in the base_dir is not present in this Set, it will be deleted.
"""
base_dir_path = pathlib.Path(base_dir)
if not base_dir_path.exists():
return
for full_dir_path in base_dir_path.iterdir():
if full_dir_path.name not in uuids and full_dir_path.is_dir():
LOG.debug("Cleaning up redundant folder %s, which is not related to any function or layer", full_dir_path)
shutil.rmtree(pathlib.Path(base_dir, full_dir_path.name))
class BuildStrategy(ABC):
"""
Base class for BuildStrategy
Keeps basic implementation of build, build_functions and build_layers
"""
def __init__(self, build_graph: BuildGraph) -> None:
self._build_graph = build_graph
def __enter__(self) -> None:
pass
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
pass
def build(self) -> Dict[str, str]:
"""
Builds all functions and layers in the given build graph
"""
result = {}
with self:
result.update(self._build_layers(self._build_graph))
result.update(self._build_functions(self._build_graph))
return result
def _build_functions(self, build_graph: BuildGraph) -> Dict[str, str]:
"""
Iterates through build graph and runs each unique build and copies outcome to the corresponding function folder
"""
function_build_results = {}
for build_definition in build_graph.get_function_build_definitions():
function_build_results.update(self.build_single_function_definition(build_definition))
return function_build_results
@abstractmethod
def build_single_function_definition(self, build_definition: FunctionBuildDefinition) -> Dict[str, str]:
"""
Builds single function definition and returns dictionary which contains function name as key,
build location as value
"""
def _build_layers(self, build_graph: BuildGraph) -> Dict[str, str]:
"""
Iterates through build graph and runs each unique build and copies outcome to the corresponding layer folder
"""
layer_build_results = {}
for layer_definition in build_graph.get_layer_build_definitions():
layer_build_results.update(self.build_single_layer_definition(layer_definition))
return layer_build_results
@abstractmethod
def build_single_layer_definition(self, layer_definition: LayerBuildDefinition) -> Dict[str, str]:
"""
Builds single layer definition and returns dictionary which contains layer name as key,
build location as value
"""
class DefaultBuildStrategy(BuildStrategy):
"""
Default build strategy, loops over given build graph for each function and layer, and builds each of them one by one
"""
def __init__(
self,
build_graph: BuildGraph,
build_dir: str,
build_function: Callable[[str, str, str, str, str, Optional[str], str, dict, dict, Optional[str], bool], str],
build_layer: Callable[[str, str, str, List[str], str, str, dict, Optional[str], bool, Optional[Dict]], str],
cached: bool = False,
) -> None:
super().__init__(build_graph)
self._build_dir = build_dir
self._build_function = build_function
self._build_layer = build_layer
self._cached = cached
def build_single_function_definition(self, build_definition: FunctionBuildDefinition) -> Dict[str, str]:
"""
Build the unique definition and then copy the artifact to the corresponding function folder
"""
function_build_results = {}
LOG.info(
"Building codeuri: %s runtime: %s metadata: %s architecture: %s functions: %s",
build_definition.codeuri,
build_definition.runtime,
build_definition.metadata,
build_definition.architecture,
build_definition.get_resource_full_paths(),
)
# build into one of the functions from this build definition
single_full_path = build_definition.get_full_path()
single_build_dir = build_definition.get_build_dir(self._build_dir)
LOG.debug("Building to following folder %s", single_build_dir)
# we should create a copy and pass it down, otherwise additional env vars like LAMBDA_BUILDERS_LOG_LEVEL
# will make cache invalid all the time
container_env_vars = deepcopy(build_definition.env_vars)
# when a function is passed here, it is ZIP function, codeuri and runtime are not None
result = self._build_function(
build_definition.get_function_name(),
build_definition.codeuri, # type: ignore
build_definition.packagetype,
build_definition.runtime, # type: ignore
build_definition.architecture,
build_definition.get_handler_name(),
single_build_dir,
build_definition.metadata,
container_env_vars,
build_definition.dependencies_dir if self._cached else None,
build_definition.download_dependencies,
)
function_build_results[single_full_path] = result
# copy results to other functions
if build_definition.packagetype == ZIP:
for function in build_definition.functions:
if function.full_path != single_full_path:
# for zip function we need to refer over the result
# artifacts directory which have built as the action above
if is_experimental_enabled(ExperimentalFlag.BuildPerformance):
LOG.debug(
"Using previously build shared location %s for function %s", result, function.full_path
)
function_build_results[function.full_path] = result
else:
# for zip function we need to copy over the artifacts
# artifacts directory will be created by the builder
artifacts_dir = function.get_build_dir(self._build_dir)
LOG.debug("Copying artifacts from %s to %s", single_build_dir, artifacts_dir)
osutils.copytree(single_build_dir, artifacts_dir)
function_build_results[function.full_path] = artifacts_dir
elif build_definition.packagetype == IMAGE:
for function in build_definition.functions:
if function.full_path != single_full_path:
# for image function, we just need to copy the image tag
function_build_results[function.full_path] = result
return function_build_results
def build_single_layer_definition(self, layer_definition: LayerBuildDefinition) -> Dict[str, str]:
"""
Build the unique definition and then copy the artifact to the corresponding layer folder
"""
layer = layer_definition.layer
LOG.info("Building layer '%s'", layer.full_path)
if layer.build_method is None:
raise MissingBuildMethodException(
f"Layer {layer.full_path} cannot be build without BuildMethod. "
f"Please provide BuildMethod in Metadata."
)
if layer.build_method == "makefile":
warn_on_invalid_architecture(layer_definition)
# There are two cases where we'd like to warn the customer
# 1. Compatible Architectures is only x86 (or not present) but Build Architecture is arm64
# 2. Build Architecture is x86 (or not present) but Compatible Architectures is only arm64
build_architecture = layer.build_architecture or X86_64
compatible_architectures = layer.compatible_architectures or [X86_64]
if build_architecture not in compatible_architectures:
LOG.warning(
"WARNING: Layer '%s' has BuildArchitecture %s, which is not listed in CompatibleArchitectures",
layer.layer_id,
build_architecture,
)
single_build_dir = layer.get_build_dir(self._build_dir)
# when a layer is passed here, it is ZIP function, codeuri and runtime are not None
# codeuri and compatible_runtimes are not None
return {
layer.full_path: self._build_layer(
layer.name,
layer.codeuri, # type: ignore
layer.build_method,
layer.compatible_runtimes, # type: ignore
layer.build_architecture,
single_build_dir,
layer_definition.env_vars,
layer_definition.dependencies_dir if self._cached else None,
layer_definition.download_dependencies,
layer.metadata,
)
}
class CachedBuildStrategy(BuildStrategy):
"""
Cached implementation of Build Strategy
For each function and layer, it first checks if there is a valid cache, and if there is, it copies from previous
build. If caching is invalid, it builds function or layer from scratch and updates cache folder and hash of the
function or layer.
For actual building, it uses delegate implementation
"""
def __init__(
self,
build_graph: BuildGraph,
delegate_build_strategy: BuildStrategy,
base_dir: str,
build_dir: str,
cache_dir: str,
) -> None:
super().__init__(build_graph)
self._delegate_build_strategy = delegate_build_strategy
self._base_dir = base_dir
self._build_dir = build_dir
self._cache_dir = cache_dir
def build(self) -> Dict[str, str]:
result = {}
with self._delegate_build_strategy:
result.update(super().build())
return result
def build_single_function_definition(self, build_definition: FunctionBuildDefinition) -> Dict[str, str]:
"""
Builds single function definition with caching
"""
if build_definition.packagetype == IMAGE:
return self._delegate_build_strategy.build_single_function_definition(build_definition)
code_dir = str(pathlib.Path(self._base_dir, cast(str, build_definition.codeuri)).resolve())
source_hash = dir_checksum(code_dir, ignore_list=[".aws-sam"], hash_generator=hashlib.sha256())
cache_function_dir = pathlib.Path(self._cache_dir, build_definition.uuid)
function_build_results = {}
if not cache_function_dir.exists() or build_definition.source_hash != source_hash:
LOG.info(
"Cache is invalid, running build and copying resources for following functions (%s)",
build_definition.get_resource_full_paths(),
)
build_result = self._delegate_build_strategy.build_single_function_definition(build_definition)
function_build_results.update(build_result)
if cache_function_dir.exists():
shutil.rmtree(str(cache_function_dir))
build_definition.source_hash = source_hash
# Since all the build contents are same for a build definition, just copy any one of them into the cache
for _, value in build_result.items():
osutils.copytree(value, str(cache_function_dir))
break
else:
LOG.info(
"Valid cache found, copying previously built resources for following functions (%s)",
build_definition.get_resource_full_paths(),
)
if is_experimental_enabled(ExperimentalFlag.BuildPerformance):
first_function_artifacts_dir: Optional[str] = None
for function in build_definition.functions:
if not first_function_artifacts_dir:
# artifacts directory will be created by the builder
artifacts_dir = build_definition.get_build_dir(self._build_dir)
LOG.debug("Linking artifacts from %s to %s", cache_function_dir, artifacts_dir)
osutils.create_symlink_or_copy(str(cache_function_dir), artifacts_dir)
function_build_results[function.full_path] = artifacts_dir
first_function_artifacts_dir = artifacts_dir
else:
LOG.debug(
"Function (%s) build folder is updated to %s",
function.full_path,
first_function_artifacts_dir,
)
function_build_results[function.full_path] = first_function_artifacts_dir
else:
for function in build_definition.functions:
# artifacts directory will be created by the builder
artifacts_dir = function.get_build_dir(self._build_dir)
LOG.debug("Copying artifacts from %s to %s", cache_function_dir, artifacts_dir)
osutils.copytree(str(cache_function_dir), artifacts_dir)
function_build_results[function.full_path] = artifacts_dir
return function_build_results
def build_single_layer_definition(self, layer_definition: LayerBuildDefinition) -> Dict[str, str]:
"""
Builds single layer definition with caching
"""
code_dir = str(pathlib.Path(self._base_dir, cast(str, layer_definition.codeuri)).resolve())
source_hash = dir_checksum(code_dir, ignore_list=[".aws-sam"], hash_generator=hashlib.sha256())
cache_function_dir = pathlib.Path(self._cache_dir, layer_definition.uuid)
layer_build_result = {}
if not cache_function_dir.exists() or layer_definition.source_hash != source_hash:
LOG.info(
"Cache is invalid, running build and copying resources for following layers (%s)",
layer_definition.get_resource_full_paths(),
)
build_result = self._delegate_build_strategy.build_single_layer_definition(layer_definition)
layer_build_result.update(build_result)
if cache_function_dir.exists():
shutil.rmtree(str(cache_function_dir))
layer_definition.source_hash = source_hash
# Since all the build contents are same for a build definition, just copy any one of them into the cache
for _, value in build_result.items():
osutils.copytree(value, str(cache_function_dir))
break
else:
LOG.info(
"Valid cache found, copying previously built resources for following layers (%s)",
layer_definition.get_resource_full_paths(),
)
# artifacts directory will be created by the builder
artifacts_dir = layer_definition.layer.get_build_dir(self._build_dir)
if is_experimental_enabled(ExperimentalFlag.BuildPerformance):
LOG.debug("Linking artifacts folder from %s to %s", cache_function_dir, artifacts_dir)
osutils.create_symlink_or_copy(str(cache_function_dir), artifacts_dir)
else:
LOG.debug("Copying artifacts from %s to %s", cache_function_dir, artifacts_dir)
osutils.copytree(str(cache_function_dir), artifacts_dir)
layer_build_result[layer_definition.layer.full_path] = artifacts_dir
return layer_build_result
def _clean_redundant_cached(self) -> None:
"""
clean the redundant cached folder
"""
uuids = {bd.uuid for bd in self._build_graph.get_function_build_definitions()}
uuids.update({ld.uuid for ld in self._build_graph.get_layer_build_definitions()})
clean_redundant_folders(self._cache_dir, uuids)
class ParallelBuildStrategy(BuildStrategy):
"""
Parallel implementation of Build Strategy
This strategy runs each build in parallel.
For actual build implementation it calls delegate implementation (could be one of the other Build Strategy)
"""
def __init__(
self,
build_graph: BuildGraph,
delegate_build_strategy: BuildStrategy,
) -> None:
super().__init__(build_graph)
self._delegate_build_strategy = delegate_build_strategy
def build(self) -> Dict[str, str]:
with self._delegate_build_strategy:
return super().build()
def _build_layers(self, build_graph: BuildGraph) -> Dict[str, str]:
return self._run_builds_async(self.build_single_layer_definition, build_graph.get_layer_build_definitions())
def _build_functions(self, build_graph: BuildGraph) -> Dict[str, str]:
return self._run_builds_async(
self.build_single_function_definition, build_graph.get_function_build_definitions()
)
@staticmethod
def _run_builds_async(
build_method: Callable[[FunctionOrLayerBuildDefinition], Dict[str, str]],
build_definitions: Tuple[FunctionOrLayerBuildDefinition, ...],
) -> Dict[str, str]:
"""Builds given list of build definitions in async and return the result"""
if not build_definitions:
return dict()
async_context = AsyncContext()
for build_definition in build_definitions:
async_context.add_async_task(build_method, build_definition)
async_results = async_context.run_async()
build_result: Dict[str, str] = dict()
for async_result in async_results:
build_result.update(async_result)
return build_result
def build_single_layer_definition(self, layer_definition: LayerBuildDefinition) -> Dict[str, str]:
return self._delegate_build_strategy.build_single_layer_definition(layer_definition)
def build_single_function_definition(self, build_definition: FunctionBuildDefinition) -> Dict[str, str]:
return self._delegate_build_strategy.build_single_function_definition(build_definition)
class IncrementalBuildStrategy(BuildStrategy):
"""
Incremental build is supported for certain runtimes in aws-lambda-builders, with dependencies_dir (str)
and download_dependencies (bool) options.
This build strategy sets whether we need to download dependencies again (download_dependencies option) by comparing
the hash of the manifest file of the given runtime as well as the dependencies directory location
(dependencies_dir option).
"""
def __init__(
self,
build_graph: BuildGraph,
delegate_build_strategy: BuildStrategy,
base_dir: str,
manifest_path_override: Optional[str],
):
super().__init__(build_graph)
self._delegate_build_strategy = delegate_build_strategy
self._base_dir = base_dir
self._manifest_path_override = manifest_path_override
def build(self) -> Dict[str, str]:
result = {}
with self, self._delegate_build_strategy:
result.update(super().build())
return result
def build_single_function_definition(self, build_definition: FunctionBuildDefinition) -> Dict[str, str]:
self._check_whether_manifest_is_changed(build_definition, build_definition.codeuri, build_definition.runtime)
return self._delegate_build_strategy.build_single_function_definition(build_definition)
def build_single_layer_definition(self, layer_definition: LayerBuildDefinition) -> Dict[str, str]:
self._check_whether_manifest_is_changed(
layer_definition, layer_definition.codeuri, layer_definition.build_method
)
return self._delegate_build_strategy.build_single_layer_definition(layer_definition)
def _check_whether_manifest_is_changed(
self,
build_definition: AbstractBuildDefinition,
codeuri: Optional[str],
runtime: Optional[str],
) -> None:
"""
Checks whether the manifest file have been changed by comparing its hash with previously stored one and updates
download_dependencies property of build definition to True, if it is changed
"""
manifest_hash = DependencyHashGenerator(
cast(str, codeuri), self._base_dir, cast(str, runtime), self._manifest_path_override
).hash
is_manifest_changed = True
is_dependencies_dir_missing = True
if manifest_hash:
is_manifest_changed = manifest_hash != build_definition.manifest_hash
is_dependencies_dir_missing = not os.path.exists(build_definition.dependencies_dir)
if is_manifest_changed or is_dependencies_dir_missing:
build_definition.manifest_hash = manifest_hash
LOG.info(
"Manifest file is changed (new hash: %s) or dependency folder (%s) is missing for (%s), "
"downloading dependencies and copying/building source",
manifest_hash,
build_definition.dependencies_dir,
build_definition.get_resource_full_paths(),
)
else:
LOG.info(
"Manifest is not changed for (%s), running incremental build",
build_definition.get_resource_full_paths(),
)
build_definition.download_dependencies = is_manifest_changed or is_dependencies_dir_missing
def _clean_redundant_dependencies(self) -> None:
"""
Update build definitions with possible new manifest hash information and clean the redundant dependencies folder
"""
uuids = {bd.uuid for bd in self._build_graph.get_function_build_definitions()}
uuids.update({ld.uuid for ld in self._build_graph.get_layer_build_definitions()})
clean_redundant_folders(DEFAULT_DEPENDENCIES_DIR, uuids)
class CachedOrIncrementalBuildStrategyWrapper(BuildStrategy):
"""
A wrapper class which holds instance of CachedBuildStrategy and IncrementalBuildStrategy
to select one of them during function or layer build, depending on the runtime that they are using
"""
SUPPORTED_RUNTIME_PREFIXES: Set[str] = {
"python",
"ruby",
"nodejs",
}
def __init__(
self,
build_graph: BuildGraph,
delegate_build_strategy: BuildStrategy,
base_dir: str,
build_dir: str,
cache_dir: str,
manifest_path_override: Optional[str],
is_building_specific_resource: bool,
use_container: bool,
):
super().__init__(build_graph)
self._incremental_build_strategy = IncrementalBuildStrategy(
build_graph,
delegate_build_strategy,
base_dir,
manifest_path_override,
)
self._cached_build_strategy = CachedBuildStrategy(
build_graph,
delegate_build_strategy,
base_dir,
build_dir,
cache_dir,
)
self._is_building_specific_resource = is_building_specific_resource
self._use_container = use_container
def build(self) -> Dict[str, str]:
result = {}
with self._cached_build_strategy, self._incremental_build_strategy:
result.update(super().build())
return result
def build_single_function_definition(self, build_definition: FunctionBuildDefinition) -> Dict[str, str]:
if self._is_incremental_build_supported(build_definition.runtime):
LOG.debug(
"Running incremental build for runtime %s for following resources (%s)",
build_definition.runtime,
build_definition.get_resource_full_paths(),
)
return self._incremental_build_strategy.build_single_function_definition(build_definition)
LOG.debug(
"Running incremental build for runtime %s for following resources (%s)",
build_definition.runtime,
build_definition.get_resource_full_paths(),
)
return self._cached_build_strategy.build_single_function_definition(build_definition)
def build_single_layer_definition(self, layer_definition: LayerBuildDefinition) -> Dict[str, str]:
if self._is_incremental_build_supported(layer_definition.build_method):
LOG.debug(
"Running incremental build for runtime %s for following resources (%s)",
layer_definition.build_method,
layer_definition.get_resource_full_paths(),
)
return self._incremental_build_strategy.build_single_layer_definition(layer_definition)
LOG.debug(
"Running cached build for runtime %s for following resources (%s)",
layer_definition.build_method,
layer_definition.get_resource_full_paths,
)
return self._cached_build_strategy.build_single_layer_definition(layer_definition)
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
"""
After build is complete, this method cleans up redundant folders in cached directory as well as in dependencies
directory. This also updates hashes of the functions and layers, if only single function or layer is been built.
If SAM CLI switched to use only IncrementalBuildStrategy, contents of this method should be moved inside
IncrementalBuildStrategy so that it will still continue to clean-up redundant folders.
"""
if self._is_building_specific_resource:
self._build_graph.update_definition_hash()
else:
self._build_graph.clean_redundant_definitions_and_update(not self._is_building_specific_resource)
self._cached_build_strategy._clean_redundant_cached()
self._incremental_build_strategy._clean_redundant_dependencies()
def _is_incremental_build_supported(self, runtime: Optional[str]) -> bool:
# incremental build doesn't support in container build
if self._use_container:
return False
if not runtime:
return False
for supported_runtime_prefix in CachedOrIncrementalBuildStrategyWrapper.SUPPORTED_RUNTIME_PREFIXES:
if runtime.startswith(supported_runtime_prefix):
return True
return False