cengal.modules_management.module_rel_path.versions.v_0.module_rel_path
1#!/usr/bin/env python 2# coding=utf-8 3 4# Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space> 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17 18 19__all__ = ['module_dir', 'module_rel_path', 'module_import_str', 'current_module_dir', 'current_module_rel_path', 'current_module_import_str'] 20 21 22""" 23Module Docstring 24Docstrings: http://www.python.org/dev/peps/pep-0257/ 25""" 26 27__author__ = "ButenkoMS <gtalk@butenkoms.space>" 28__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>" 29__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ] 30__license__ = "Apache License, Version 2.0" 31__version__ = "4.4.1" 32__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>" 33__email__ = "gtalk@butenkoms.space" 34# __status__ = "Prototype" 35__status__ = "Development" 36# __status__ = "Production" 37 38 39from cengal.introspection.inspect import entity_owning_module_info_and_owning_path, get_module_importable_str_and_path, frame 40from cengal.introspection.inspect import entity_name 41from cengal.file_system.path_manager import get_relative_path_part 42from cengal.text_processing.text_processing import removesuffix 43import os 44from typing import Optional 45 46 47def module_dir(library_module) -> str: 48 module_file_full_path = get_module_importable_str_and_path(library_module)[1] 49 return os.path.dirname(module_file_full_path) 50 51 52def module_rel_path(library_top_module, library_module) -> str: 53 module_file_full_path = get_module_importable_str_and_path(library_module)[1] 54 top_init_file_full_path: str = get_module_importable_str_and_path(library_top_module)[1] 55 library_dir_full_path: str = os.path.dirname(top_init_file_full_path) 56 return get_relative_path_part(module_file_full_path, library_dir_full_path) 57 58 59def module_import_str(library_top_module, library_module) -> str: 60 result: str = f'{entity_name(library_top_module)}/{module_rel_path(library_top_module, library_module)}' 61 result = result.replace('\\', '/') 62 result = result.replace('//', '/') 63 result = result.strip('/') 64 result = removesuffix(result, '.py') 65 result = result.strip('/') 66 result = result.replace('/', '.') 67 return result 68 69 70def current_module_dir(depth: Optional[int] = 1) -> str: 71 _, _, module_file_full_path, _ = entity_owning_module_info_and_owning_path(frame(depth + 1)) 72 return os.path.dirname(module_file_full_path) 73 74 75def current_module_rel_path(library_top_module, depth: Optional[int] = 1) -> str: 76 _, _, module_file_full_path, _ = entity_owning_module_info_and_owning_path(frame(depth + 1)) 77 top_init_file_full_path: str = get_module_importable_str_and_path(library_top_module)[1] 78 library_dir_full_path: str = os.path.dirname(top_init_file_full_path) 79 return get_relative_path_part(module_file_full_path, library_dir_full_path) 80 81 82def current_module_import_str(library_top_module, depth: Optional[int] = 1) -> str: 83 result: str = f'{entity_name(library_top_module)}/{current_module_rel_path(library_top_module, depth + 1)}' 84 result = result.replace('\\', '/') 85 result = result.replace('//', '/') 86 result = result.strip('/') 87 result = removesuffix(result, '.py') 88 result = result.strip('/') 89 result = result.replace('/', '.') 90 return result
def
module_dir(library_module) -> str:
def
module_rel_path(library_top_module, library_module) -> str:
53def module_rel_path(library_top_module, library_module) -> str: 54 module_file_full_path = get_module_importable_str_and_path(library_module)[1] 55 top_init_file_full_path: str = get_module_importable_str_and_path(library_top_module)[1] 56 library_dir_full_path: str = os.path.dirname(top_init_file_full_path) 57 return get_relative_path_part(module_file_full_path, library_dir_full_path)
def
module_import_str(library_top_module, library_module) -> str:
60def module_import_str(library_top_module, library_module) -> str: 61 result: str = f'{entity_name(library_top_module)}/{module_rel_path(library_top_module, library_module)}' 62 result = result.replace('\\', '/') 63 result = result.replace('//', '/') 64 result = result.strip('/') 65 result = removesuffix(result, '.py') 66 result = result.strip('/') 67 result = result.replace('/', '.') 68 return result
def
current_module_dir(depth: Union[int, NoneType] = 1) -> str:
def
current_module_rel_path(library_top_module, depth: Union[int, NoneType] = 1) -> str:
76def current_module_rel_path(library_top_module, depth: Optional[int] = 1) -> str: 77 _, _, module_file_full_path, _ = entity_owning_module_info_and_owning_path(frame(depth + 1)) 78 top_init_file_full_path: str = get_module_importable_str_and_path(library_top_module)[1] 79 library_dir_full_path: str = os.path.dirname(top_init_file_full_path) 80 return get_relative_path_part(module_file_full_path, library_dir_full_path)
def
current_module_import_str(library_top_module, depth: Union[int, NoneType] = 1) -> str:
83def current_module_import_str(library_top_module, depth: Optional[int] = 1) -> str: 84 result: str = f'{entity_name(library_top_module)}/{current_module_rel_path(library_top_module, depth + 1)}' 85 result = result.replace('\\', '/') 86 result = result.replace('//', '/') 87 result = result.strip('/') 88 result = removesuffix(result, '.py') 89 result = result.strip('/') 90 result = result.replace('/', '.') 91 return result