forked from sh-edraft.de/sh_discord_bot
Added requirements.txt generator #70-1
This commit is contained in:
parent
3b9ef0048e
commit
7d4f3e9541
@ -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)
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user