diff --git a/kdb-bot/tools/post_build/application.py b/kdb-bot/tools/post_build/application.py index 39c68b63..29f67e58 100644 --- a/kdb-bot/tools/post_build/application.py +++ b/kdb-bot/tools/post_build/application.py @@ -21,6 +21,6 @@ class Application(ApplicationABC): def main(self): Console.write_line('KDB Post-Build:') Console.spinner(f'Removing unnecessary configs', self._remove_config.remove) - # Console.spinner(f'Creating requirements file for pip', self._deps.create) + Console.spinner(f'Creating requirements file for pip', self._deps.create) diff --git a/kdb-bot/tools/post_build/service/dependencies.py b/kdb-bot/tools/post_build/service/dependencies.py index aa10e0ba..1359b738 100644 --- a/kdb-bot/tools/post_build/service/dependencies.py +++ b/kdb-bot/tools/post_build/service/dependencies.py @@ -1,7 +1,64 @@ +import os + +from cpl_cli.configuration import WorkspaceSettings, ProjectSettings, BuildSettings +from cpl_core.configuration import ConfigurationABC +from cpl_core.console import Console +from cpl_core.environment import ApplicationEnvironmentABC + +from post_build.post_build_settings import PostBuildSettings + + class Dependencies: - def __init__(self): - pass + def __init__( + self, + config: ConfigurationABC, + env: ApplicationEnvironmentABC, + ws: WorkspaceSettings, + project: ProjectSettings, + build: BuildSettings, + post_build: PostBuildSettings + ): + self._config = config + self._env = env + self._workspace = ws + self._project = project + self._build = build + self._post_build = post_build + + self._dependencies = {} + + def _add_dependencies(self, deps: list[str]): + for d in deps: + d_name = d + if '>=' in d: + d_name = d.split('>=')[0] + if '<=' in d: + d_name = d.split('<=')[0] + if '==' in d: + d_name = d.split('==')[0] + + if d_name in self._dependencies: + continue + + self._dependencies[d_name] = d def create(self): - pass + dist_path = os.path.abspath(os.path.join( + self._env.working_directory, + os.path.dirname(self._workspace.projects[self._project.name]), + self._build.output_path, + self._project.name, + 'build' + )) + + for project in self._workspace.projects: + project_file = os.path.join(self._env.working_directory, self._workspace.projects[project]) + self._config.add_json_file(project_file, output=False, optional=False) + project: ProjectSettings = self._config.get_configuration(ProjectSettings) + self._add_dependencies(project.dependencies) + + with open(f'{dist_path}/requirements.txt', 'w+', encoding='utf-8') as f: + for dependency in self._dependencies: + f.write(f'{self._dependencies[dependency]}\n') + f.close() diff --git a/kdb-bot/tools/post_build/service/remove_config.py b/kdb-bot/tools/post_build/service/remove_config.py index 07774e10..99210a30 100644 --- a/kdb-bot/tools/post_build/service/remove_config.py +++ b/kdb-bot/tools/post_build/service/remove_config.py @@ -9,7 +9,7 @@ from post_build.post_build_settings import PostBuildSettings class RemoveConfig: - def __init__(self, env: ApplicationEnvironmentABC, ws: WorkspaceSettings, project: ProjectSettings, build: BuildSettings, post_build: PostBuildSettings,): + def __init__(self, env: ApplicationEnvironmentABC, ws: WorkspaceSettings, project: ProjectSettings, build: BuildSettings, post_build: PostBuildSettings): self._env = env self._workspace = ws