diff --git a/.gitignore b/.gitignore index 0c8881d..bd8cecf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ build logs results .pytest_cache +.coverage mkdocs.yml .generated-files.txt diff --git a/NOTICE-3RD-PARTY-CONTENT.md b/NOTICE-3RD-PARTY-CONTENT.md index 627f268..7e51d79 100644 --- a/NOTICE-3RD-PARTY-CONTENT.md +++ b/NOTICE-3RD-PARTY-CONTENT.md @@ -3,7 +3,7 @@ ## Python | Dependency | Version | License | |:-----------|:-------:|--------:| -|types-requests|2.32.0.20240521|Apache 2.0| +|types-requests|2.32.0.20240602|Apache 2.0| |urllib3|2.2.1|MIT| ## Workflows | Dependency | Version | License | diff --git a/docs/index.md b/docs/index.md index a974af2..b39ad0c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,10 +5,12 @@ ## Modules - [`velocitas_lib`](./velocitas_lib.md#module-velocitas_lib) +- [`velocitas_lib.conan_helper`](./velocitas_lib.conan_helper.md#module-velocitas_libconan_helper) - [`velocitas_lib.docker`](./velocitas_lib.docker.md#module-velocitas_libdocker) - [`velocitas_lib.functional_interface`](./velocitas_lib.functional_interface.md#module-velocitas_libfunctional_interface) - [`velocitas_lib.middleware`](./velocitas_lib.middleware.md#module-velocitas_libmiddleware) - [`velocitas_lib.services`](./velocitas_lib.services.md#module-velocitas_libservices) +- [`velocitas_lib.templates`](./velocitas_lib.templates.md#module-velocitas_libtemplates) - [`velocitas_lib.variables`](./velocitas_lib.variables.md#module-velocitas_libvariables) ## Classes @@ -16,11 +18,14 @@ - [`middleware.MiddlewareType`](./velocitas_lib.middleware.md#class-middlewaretype): Enumeration containing all possible middleware types. - [`services.Service`](./velocitas_lib.services.md#class-service): Service(id, config) - [`services.ServiceSpecConfig`](./velocitas_lib.services.md#class-servicespecconfig): ServiceSpecConfig(image, is_enabled, env_vars, args, ports, port_forwards, mounts, startup_log_patterns) +- [`templates.CopySpec`](./velocitas_lib.templates.md#class-copyspec): Copy specification of a single file or directory. - [`variables.ProjectVariables`](./velocitas_lib.variables.md#class-projectvariables) ## Functions +- [`velocitas_lib.capture_textfile_area`](./velocitas_lib.md#function-capture_textfile_area): Capture an area of a textfile between a matching start line (exclusive) and the first line matching end_line (exclusive). - [`velocitas_lib.create_log_file`](./velocitas_lib.md#function-create_log_file): Create a log file for the given service and runtime. +- [`velocitas_lib.create_truncated_string`](./velocitas_lib.md#function-create_truncated_string): Create a truncated version of input if it is longer than length. - [`velocitas_lib.download_file`](./velocitas_lib.md#function-download_file) - [`velocitas_lib.get_app_manifest`](./velocitas_lib.md#function-get_app_manifest) - [`velocitas_lib.get_cache_data`](./velocitas_lib.md#function-get_cache_data): Return the data of the cache as Python object. @@ -29,8 +34,15 @@ - [`velocitas_lib.get_programming_language`](./velocitas_lib.md#function-get_programming_language): Return the programming language of the project. - [`velocitas_lib.get_project_cache_dir`](./velocitas_lib.md#function-get_project_cache_dir): Return the project's cache directory. - [`velocitas_lib.get_script_path`](./velocitas_lib.md#function-get_script_path): Return the absolute path to the directory the invoked Python script +- [`velocitas_lib.get_valid_arch`](./velocitas_lib.md#function-get_valid_arch): Return a known architecture for the given `arch`. - [`velocitas_lib.get_workspace_dir`](./velocitas_lib.md#function-get_workspace_dir): Return the workspace directory. +- [`velocitas_lib.replace_in_file`](./velocitas_lib.md#function-replace_in_file): Replace all occurrences of text in a file with a replacement. - [`velocitas_lib.require_env`](./velocitas_lib.md#function-require_env): Require and return an environment variable. +- [`velocitas_lib.to_camel_case`](./velocitas_lib.md#function-to_camel_case): Return a camel case version of a snake case string. +- [`conan_helper.add_dependency_to_conanfile`](./velocitas_lib.conan_helper.md#function-add_dependency_to_conanfile): Add the dependency name to the project's list of dependencies. +- [`conan_helper.export_conan_project`](./velocitas_lib.conan_helper.md#function-export_conan_project): Export a conan project to the local conan cache. +- [`conan_helper.get_required_sdk_version`](./velocitas_lib.conan_helper.md#function-get_required_sdk_version): Return the required version of the core SDK. +- [`conan_helper.move_generated_sources`](./velocitas_lib.conan_helper.md#function-move_generated_sources): Move generated source code from the generation dir into - [`docker.build_vehicleapp_image`](./velocitas_lib.docker.md#function-build_vehicleapp_image): Build VehicleApp docker image and display the progress using a spinner. - [`docker.container_exists`](./velocitas_lib.docker.md#function-container_exists): Check if a container with a given name exists. - [`docker.is_docker_image_build_locally`](./velocitas_lib.docker.md#function-is_docker_image_build_locally): Check if vehicle app docker image is locally available @@ -42,6 +54,7 @@ - [`services.get_specific_service`](./velocitas_lib.services.md#function-get_specific_service): Return the specified service as Python object. - [`services.parse_service_config`](./velocitas_lib.services.md#function-parse_service_config): Parse service spec configuration and return it as an named tuple. - [`services.resolve_functions`](./velocitas_lib.services.md#function-resolve_functions) +- [`templates.copy_templates`](./velocitas_lib.templates.md#function-copy_templates): Copy templates from the template dir to the target dir. - [`variables.json_obj_to_flat_map`](./velocitas_lib.variables.md#function-json_obj_to_flat_map): Flatten a JSON Object into a one dimensional dict by joining the keys diff --git a/docs/velocitas_lib.conan_helper.md b/docs/velocitas_lib.conan_helper.md new file mode 100644 index 0000000..4bdc4d9 --- /dev/null +++ b/docs/velocitas_lib.conan_helper.md @@ -0,0 +1,109 @@ + + + + +# module `velocitas_lib.conan_helper` + + + + + +--- + + + +## function `get_required_sdk_version` + +```python +get_required_sdk_version() → Optional[str] +``` + +Return the required version of the core SDK. + + + +**Returns:** + + - `Optional[str]`: The required version or None in case SDK is not a dependency. + + +--- + + + +## function `move_generated_sources` + +```python +move_generated_sources( + generated_source_dir: str, + output_dir: str, + include_dir_rel: str, + src_dir_rel: str +) → Tuple[List[str], List[str]] +``` + +Move generated source code from the generation dir into headers: / sources: / + + + +**Args:** + + - `generated_source_dir` (str): The directory containing the generated sources. + - `output_dir` (str): The root directory to move the generated files to. + - `include_dir_rel` (str): Path relative to output_dir where to move the headers to. + - `src_dir_rel` (str): Path relative to the output_dir where to move the sources to. + + + +**Returns:** + + - `Tuple[List[str], List[str]]`: A tuple containing [0] = a list of the paths to all headers [1] = a list of the paths to all sources + + +--- + + + +## function `export_conan_project` + +```python +export_conan_project(conan_project_path: str) → None +``` + +Export a conan project to the local conan cache. + + + +**Args:** + + - `conan_project_path` (str): The path to directory containing the project. + + +--- + + + +## function `add_dependency_to_conanfile` + +```python +add_dependency_to_conanfile( + dependency_name: str, + dependency_version: str +) → None +``` + +Add the dependency name to the project's list of dependencies. + + + +**Args:** + + - `dependency_name` (str): The dependency to add e.g. grpc + - `dependency_version` (str): The version of the dependency to add e.g. 1.50.1 + + + + +--- + +_This file was automatically generated via [lazydocs](https://github.com/ml-tooling/lazydocs)._ diff --git a/docs/velocitas_lib.md b/docs/velocitas_lib.md index eb39150..1f3283f 100644 --- a/docs/velocitas_lib.md +++ b/docs/velocitas_lib.md @@ -12,6 +12,136 @@ +## function `to_camel_case` + +```python +to_camel_case(snake_str: str) → str +``` + +Return a camel case version of a snake case string. + + + +**Args:** + + - `snake_str` (str): A snake case string. + + + +**Returns:** + + - `str`: A camel case version of a snake case string. + + +--- + + + +## function `create_truncated_string` + +```python +create_truncated_string(input: str, length: int) → str +``` + +Create a truncated version of input if it is longer than length. Will keep the rightmost characters and cut of the front if it is longer than allowed. + + + +**Args:** + + - `input` (str): The input string. + - `length` (int): The allowed overall length. + + + +**Returns:** + + - `str`: A truncated string which has len() of length. + + +--- + + + +## function `replace_in_file` + +```python +replace_in_file(file_path: str, text: str, replacement: str) → None +``` + +Replace all occurrences of text in a file with a replacement. + + + +**Args:** + + - `file_path` (str): The path to the file. + - `text` (str): The text to find. + - `replacement` (str): The replacement for text. + + +--- + + + +## function `get_valid_arch` + +```python +get_valid_arch(arch: str) → str +``` + +Return a known architecture for the given `arch`. + + + +**Args:** + + - `arch` (str): The architecture of the profile. + + + +**Returns:** + + - `str`: valid architecture. + + +--- + + + +## function `capture_textfile_area` + +```python +capture_textfile_area( + file: TextIOWrapper, + start_line: str, + end_line: str, + map_fn: Optional[Callable[[str], str]] = None +) → List[str] +``` + +Capture an area of a textfile between a matching start line (exclusive) and the first line matching end_line (exclusive). + + + +**Args:** + + - `file` (TextIOWrapper): The text file to read from. + - `start_line` (str): The line which triggers the capture (will not be part of the output) + - `end_line` (str): The line which terminates the capture (will not be bart of the output) + - `map_fn` (Optional[Callable[[str], str]], optional): An optional mapping function to transform captured lines. Defaults to None. + + + +**Returns:** + + - `List[str]`: A list of captured lines. + + +--- + + + ## function `require_env` ```python @@ -41,7 +171,7 @@ Require and return an environment variable. --- - + ## function `get_workspace_dir` @@ -54,7 +184,7 @@ Return the workspace directory. --- - + ## function `get_app_manifest` @@ -69,7 +199,7 @@ get_app_manifest() → Dict[str, Any] --- - + ## function `get_script_path` @@ -82,7 +212,7 @@ Return the absolute path to the directory the invoked Python script is located i --- - + ## function `get_package_path` @@ -95,7 +225,7 @@ Return the absolute path to the package directory the invoked Python script belo --- - + ## function `get_project_cache_dir` @@ -114,7 +244,7 @@ Return the project's cache directory. --- - + ## function `get_cache_data` @@ -127,7 +257,7 @@ Return the data of the cache as Python object. --- - + ## function `get_log_file_name` @@ -153,7 +283,7 @@ Build the log file name for the given service and runtime. --- - + ## function `get_programming_language` @@ -166,7 +296,7 @@ Return the programming language of the project. --- - + ## function `create_log_file` @@ -192,7 +322,7 @@ Create a log file for the given service and runtime. --- - + ## function `download_file` diff --git a/docs/velocitas_lib.templates.md b/docs/velocitas_lib.templates.md new file mode 100644 index 0000000..3d2e4e6 --- /dev/null +++ b/docs/velocitas_lib.templates.md @@ -0,0 +1,83 @@ + + + + +# module `velocitas_lib.templates` + + + + + +--- + + + +## function `copy_templates` + +```python +copy_templates( + template_dir: str, + target_dir: str, + template_file_mapping: List[CopySpec], + variables: Dict[str, str] +) → None +``` + +Copy templates from the template dir to the target dir. + + + +**Args:** + + - `template_dir` (str): Path to the directory containing the template files. + - `target_dir` (str): Path to the target directory. + - `template_file_mapping` (Dict[str, str]): A mapping of source path to target path. + - `variables` (Dict[str, str]): Name to value mapping which will be replaced when parsing the template files. + + +--- + + + +## class `CopySpec` +Copy specification of a single file or directory. + + + +### method `__init__` + +```python +__init__(source_path: str, target_path: Optional[str] = None) +``` + + + + + + + + +--- + + + +### method `get_target` + +```python +get_target() → str +``` + +Get the target path of the copy spec. + + + +**Returns:** + + - `str`: If a target_path is given explicitly, it will be returned. Otherwise the source_path will be returned. + + + + +--- + +_This file was automatically generated via [lazydocs](https://github.com/ml-tooling/lazydocs)._ diff --git a/tests/test_conan_helper.py b/tests/test_conan_helper.py index 685a2dc..05ed1f3 100644 --- a/tests/test_conan_helper.py +++ b/tests/test_conan_helper.py @@ -20,7 +20,7 @@ from velocitas_lib import get_workspace_dir sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "src")) -from shared_utils.conan_helper import add_dependency_to_conanfile # noqa +from velocitas_lib.conan_helper import add_dependency_to_conanfile # noqa @pytest.fixture