cengal.build_tools.build_extensions.versions.v_0.build_extensions

  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__ = [
 20    'CengalBuildExtension',
 21    'CengalSetuptoolsBuildExtension',
 22    'CengalCythonBuildExtension',
 23    'CengalGeneratorBuildExtension',
 24]
 25
 26
 27"""
 28Module Docstring
 29Docstrings: http://www.python.org/dev/peps/pep-0257/
 30"""
 31
 32__author__ = "ButenkoMS <gtalk@butenkoms.space>"
 33__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>"
 34__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ]
 35__license__ = "Apache License, Version 2.0"
 36__version__ = "4.4.1"
 37__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>"
 38__email__ = "gtalk@butenkoms.space"
 39# __status__ = "Prototype"
 40__status__ = "Development"
 41# __status__ = "Production"
 42
 43
 44# from distutils.dist import Distribution
 45from os import environ
 46
 47from setuptools._distutils.dist import Distribution
 48
 49from cengal.file_system.path_manager import path_relative_to_src, RelativePath, get_relative_path_part, sep
 50from cengal.file_system.directory_manager import current_src_dir, change_current_dir
 51from cengal.file_system.directory_manager import filtered_file_list, FilteringType, filtered_file_list_traversal, file_list_traversal, FilteringEntity
 52from cengal.file_system.file_manager import current_src_file_dir, file_exists
 53from cengal.build_tools.prepare_cflags import prepare_cflags, concat_cflags, prepare_compile_time_env, adjust_definition_names, \
 54    dict_of_tuples_to_dict, list_to_dict
 55from cengal.introspection.inspect import get_exception, entity_repr_limited_try_qualname, pifrl, pdi
 56from cengal.text_processing.text_processing import find_text
 57from cengal.system import OS_TYPE, TEMPLATE_MODULE_NAME
 58from shutil import rmtree
 59from os import remove
 60from os.path import splitext, normpath, join as path_join, basename, split
 61from setuptools import Extension as SetuptoolsExtension
 62from Cython.Distutils import Extension as CythonExtension
 63from distutils.command.build import build as build_orig
 64from distutils.command.build_ext import build_ext as build_ext_orig
 65from setuptools.command.sdist import sdist as sdist_orig
 66import json
 67import importlib
 68
 69from os.path import isdir, exists, isfile, dirname
 70
 71import setuptools
 72import platform
 73
 74from cengal.file_system.path_manager import RelativePath, get_relative_path_part
 75from cengal.file_system.directory_manager import current_src_dir
 76from cengal.file_system.directory_manager import file_list_traversal, FilteringEntity
 77from cengal.build_tools.prepare_cflags import prepare_compile_time_flags, prepare_compile_time_env
 78from cengal.os.execute import prepare_params, escape_text, escape_param, prepare_command
 79from setuptools.discovery import find_package_path
 80import subprocess
 81from pprint import pprint
 82from typing import List, Dict, Optional, Iterable, Callable, Sequence, Tuple, Union, Type, Any
 83
 84
 85class CengalBuildExtension:
 86    base_class: Optional[Type] = None
 87    store_as_data: bool = False
 88
 89    def __init__(self, kwargs) -> None:
 90        self.kwargs = kwargs
 91        self._path = None
 92        self._module_import_str = None
 93        self._files = list()
 94
 95    def __call__(self) -> Optional[List[str]]:
 96        return self.base_class(**self.kwargs) if self.base_class is not None else None
 97    
 98    def sdist() -> Optional[List[str]]:
 99        raise NotImplementedError
100    
101    @property
102    def path(self) -> str:
103        return self._path
104
105    @path.setter
106    def path(self, value: str):
107        self._path = value
108    
109    @property
110    def dir_path(self) -> str:
111        return None if self._path is None else dirname(self._path)
112    
113    @property
114    def dir_path_rel(self) -> RelativePath:
115        return None if self._path is None else RelativePath(dirname(self._path))
116
117    @property
118    def module_import_str(self) -> str:
119        return self._module_import_str
120    
121    @module_import_str.setter
122    def module_import_str(self, value: str):
123        self._module_import_str = value
124
125    @property
126    def name(self) -> str:
127        return self._module_import_str
128
129    @property
130    def package(self) -> str:
131        return '.'.join(self._module_import_str.split('.')[:-1])
132    
133    @property
134    def files(self) -> str:
135        return self._files
136    
137    @files.setter
138    def files(self, value: str):
139        self._files = value
140
141
142class CengalSetuptoolsBuildExtension(CengalBuildExtension):
143    base_class: Optional[Type] = SetuptoolsExtension
144
145    def __init__(self, **kwargs) -> None:
146        super().__init__(kwargs)
147
148
149class CengalCythonBuildExtension(CengalBuildExtension):
150    base_class: Optional[Type] = CythonExtension
151
152    def __init__(self, **kwargs) -> None:
153        super().__init__(kwargs)
154
155
156class CengalGeneratorBuildExtension(CengalBuildExtension):
157    base_class: Optional[Type] = None
158    store_as_data: bool = True
159
160    def __init__(self, **kwargs) -> None:
161        super().__init__(kwargs)
162    
163    def __call__(self):
164        raise NotImplementedError
class CengalBuildExtension:
 86class CengalBuildExtension:
 87    base_class: Optional[Type] = None
 88    store_as_data: bool = False
 89
 90    def __init__(self, kwargs) -> None:
 91        self.kwargs = kwargs
 92        self._path = None
 93        self._module_import_str = None
 94        self._files = list()
 95
 96    def __call__(self) -> Optional[List[str]]:
 97        return self.base_class(**self.kwargs) if self.base_class is not None else None
 98    
 99    def sdist() -> Optional[List[str]]:
100        raise NotImplementedError
101    
102    @property
103    def path(self) -> str:
104        return self._path
105
106    @path.setter
107    def path(self, value: str):
108        self._path = value
109    
110    @property
111    def dir_path(self) -> str:
112        return None if self._path is None else dirname(self._path)
113    
114    @property
115    def dir_path_rel(self) -> RelativePath:
116        return None if self._path is None else RelativePath(dirname(self._path))
117
118    @property
119    def module_import_str(self) -> str:
120        return self._module_import_str
121    
122    @module_import_str.setter
123    def module_import_str(self, value: str):
124        self._module_import_str = value
125
126    @property
127    def name(self) -> str:
128        return self._module_import_str
129
130    @property
131    def package(self) -> str:
132        return '.'.join(self._module_import_str.split('.')[:-1])
133    
134    @property
135    def files(self) -> str:
136        return self._files
137    
138    @files.setter
139    def files(self, value: str):
140        self._files = value
CengalBuildExtension(kwargs)
90    def __init__(self, kwargs) -> None:
91        self.kwargs = kwargs
92        self._path = None
93        self._module_import_str = None
94        self._files = list()
base_class: Union[Type, NoneType] = None
store_as_data: bool = False
kwargs
def sdist() -> Union[List[str], NoneType]:
 99    def sdist() -> Optional[List[str]]:
100        raise NotImplementedError
path: str
102    @property
103    def path(self) -> str:
104        return self._path
dir_path: str
110    @property
111    def dir_path(self) -> str:
112        return None if self._path is None else dirname(self._path)
dir_path_rel: cengal.file_system.path_manager.versions.v_0.path_manager.RelativePath
114    @property
115    def dir_path_rel(self) -> RelativePath:
116        return None if self._path is None else RelativePath(dirname(self._path))
module_import_str: str
118    @property
119    def module_import_str(self) -> str:
120        return self._module_import_str
name: str
126    @property
127    def name(self) -> str:
128        return self._module_import_str
package: str
130    @property
131    def package(self) -> str:
132        return '.'.join(self._module_import_str.split('.')[:-1])
files: str
134    @property
135    def files(self) -> str:
136        return self._files
class CengalSetuptoolsBuildExtension(CengalBuildExtension):
143class CengalSetuptoolsBuildExtension(CengalBuildExtension):
144    base_class: Optional[Type] = SetuptoolsExtension
145
146    def __init__(self, **kwargs) -> None:
147        super().__init__(kwargs)
CengalSetuptoolsBuildExtension(**kwargs)
146    def __init__(self, **kwargs) -> None:
147        super().__init__(kwargs)
base_class: Union[Type, NoneType] = <class 'setuptools.extension.Extension'>
class CengalCythonBuildExtension(CengalBuildExtension):
150class CengalCythonBuildExtension(CengalBuildExtension):
151    base_class: Optional[Type] = CythonExtension
152
153    def __init__(self, **kwargs) -> None:
154        super().__init__(kwargs)
CengalCythonBuildExtension(**kwargs)
153    def __init__(self, **kwargs) -> None:
154        super().__init__(kwargs)
base_class: Union[Type, NoneType] = <class 'Cython.Distutils.extension.Extension'>
class CengalGeneratorBuildExtension(CengalBuildExtension):
157class CengalGeneratorBuildExtension(CengalBuildExtension):
158    base_class: Optional[Type] = None
159    store_as_data: bool = True
160
161    def __init__(self, **kwargs) -> None:
162        super().__init__(kwargs)
163    
164    def __call__(self):
165        raise NotImplementedError
CengalGeneratorBuildExtension(**kwargs)
161    def __init__(self, **kwargs) -> None:
162        super().__init__(kwargs)
base_class: Union[Type, NoneType] = None
store_as_data: bool = True