diff --git a/stx-app-generator/stx-app-generator/app_gen_tool/common.py b/stx-app-generator/stx-app-generator/app_gen_tool/common.py index a749268..d2d386c 100644 --- a/stx-app-generator/stx-app-generator/app_gen_tool/common.py +++ b/stx-app-generator/stx-app-generator/app_gen_tool/common.py @@ -96,6 +96,8 @@ def get_chart_from_git(new_path: str, temp_dir: str, git_url: str, git_name: str def transform_rel_path_into_abs_path(abs_path: str, rel_path: str) -> str: """It transforms the rel_path into an absolute path""" + if rel_path[0] == '/': + return rel_path if rel_path[:2] == './': rel_path = rel_path.replace('./', 'app-gen-tool/') longest_common_path = "" diff --git a/stx-app-generator/stx-app-generator/app_gen_tool/fluxcd.py b/stx-app-generator/stx-app-generator/app_gen_tool/fluxcd.py index 6b67955..e40f4e8 100644 --- a/stx-app-generator/stx-app-generator/app_gen_tool/fluxcd.py +++ b/stx-app-generator/stx-app-generator/app_gen_tool/fluxcd.py @@ -7,6 +7,7 @@ import yaml from app_gen_tool.application import Application from app_gen_tool.common import uppercase_name from app_gen_tool import constants +from pbr.version import VersionInfo class FluxCD(Application): @@ -178,6 +179,54 @@ class FluxCD(Application): if not os.path.exists(self._app['outputLifecycleDir']): os.makedirs(self._app['outputLifecycleDir']) + def _write_metadata_file(self): + """writes the METADATA file for the package""" + def split_and_format_value(value) -> str: + if isinstance(value, str): + return ''.join([f'\t{lin}\n' for lin in value.split('\n')]) + else: + return ''.join([f'\t{lin}\n' for lin in value]) + + def expected_order(tup: tuple) -> int: + if tup[0] == 'name': + return 0 + elif tup[0] == 'version': + return 1 + elif tup[0] == 'summary': + return 2 + else: + return 3 + + yml_data = self.plugin_setup + yml_data['metadata']['name'] = f'{self.APP_NAME}' + yml_data['metadata']['version'] = f'{VersionInfo(self.APP_NAME)}' + yml_data['metadata'][ + 'summary' + ] = f'StarlingX sysinv extensions for {self.APP_NAME}' + yml_data['metadata'] = dict( + sorted(yml_data['metadata'].items(), key=expected_order) + ) + + out = '' + for label in yml_data: + out += f'[{label}]\n' + for key, val in yml_data[label].items(): + if label == 'metadata' and val is None: + raise ValueError(f'You should\'ve written a value for: {key}') + elif not isinstance(val, list): + out += f'{str(key).title()}: {val}\n' + else: + out += f'{str(key).title()}:\n' + out += split_and_format_value(val) + out += '\n' + + out = out.replace('[metadata]\n', '') + + with open( + f'{self._app["outputPluginDir"]}/METADATA', 'w', encoding='utf-8' + ) as f: + f.write(out) + # Sub-process of app generation # generate application plugin files def _gen_plugins(self): @@ -303,7 +352,7 @@ class FluxCD(Application): setup_py_file = os.path.join(plugin_dir, 'setup.py') file_content = ( 'import setuptools\n\nsetuptools.setup(\n ' - 'setup_requires=["pbr>=2.0.0"],\n pbr=True)' + 'setup_requires=["pbr>=5.0.0"],\n pbr=True)' ) with open(setup_py_file, 'w', encoding='utf-8') as f: @@ -318,6 +367,9 @@ class FluxCD(Application): directory = os.path.join(plugin_dir, appname) self.create_init_file(directory) + # Generate METADATA file + self._write_metadata_file() + return True # Sub-process of app generation @@ -335,17 +387,8 @@ class FluxCD(Application): os.makedirs(dirplugins, exist_ok=True) os.chdir(dirplugins) - command = [ - 'python3', - 'setup.py', - 'bdist_wheel', - '--universal', - '-d', - '.', - ] - try: - subprocess.call(command, stderr=subprocess.STDOUT) + subprocess.run(["python3 -m build"], shell=True) except Exception: return False diff --git a/stx-app-generator/stx-app-generator/requirements.txt b/stx-app-generator/stx-app-generator/requirements.txt index 033661d..f31d210 100644 --- a/stx-app-generator/stx-app-generator/requirements.txt +++ b/stx-app-generator/stx-app-generator/requirements.txt @@ -1,2 +1,3 @@ pyyaml==6.0.1 -wheel==0.41.2 \ No newline at end of file +wheel==0.41.2 +build==1.2.1 \ No newline at end of file diff --git a/stx-app-generator/stx-app-generator/setup.py b/stx-app-generator/stx-app-generator/setup.py index 9254cc9..86f75fc 100644 --- a/stx-app-generator/stx-app-generator/setup.py +++ b/stx-app-generator/stx-app-generator/setup.py @@ -36,7 +36,7 @@ setup( f'{PACKAGE_NAME} = {PACKAGE_DIRECTORY}.cmd.generator:main', ], }, - setup_requires=['pbr>=0.5'], + setup_requires=['pbr>=5.0.0'], pbr=True, packages=find_packages(), include_package_data=True, diff --git a/stx-app-generator/stx-app-generator/tests/unit/test_application_class.py b/stx-app-generator/stx-app-generator/tests/unit/test_application_class.py index 7657dfe..b3ee7ac 100644 --- a/stx-app-generator/stx-app-generator/tests/unit/test_application_class.py +++ b/stx-app-generator/stx-app-generator/tests/unit/test_application_class.py @@ -2,7 +2,7 @@ import git import os import shutil -import glob +import fnmatch from app_gen_tool.common import get_chart_from_git @@ -178,7 +178,11 @@ class TestFluxCDAppGen: FluxCD._gen_plugin_wheels(app) - output_file = os.path.join(self.OUTPUT_FOLDER, "plugins", "*.whl") - file_exists = glob.glob(output_file, recursive = True) + output_dir = os.path.join(self.OUTPUT_FOLDER, "plugins") + file_exists = False + for root, dirs, files in os.walk(output_dir): + for file in files: + if fnmatch.fnmatch(file, '*.whl'): + return True assert file_exists \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt index e6c83de..e474e7f 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,6 +1,7 @@ hacking>=1.1.0,<=2.0.0 # Apache-2.0 -bashate >= 0.2 -PyYAML >= 3.1.0 +bashate>=0.2 +build==1.2.1 +PyYAML>=3.1.0 shellcheck-py;python_version>="3.0" # MIT yamllint<1.26.1;python_version>="3.0" # GPLv2 pylint