Add METADATA file to generated app

This update adds a METADATA file inside the plugins directory.
The app-gen-tool embedded with the stx-9 ISO was failing due
to pbr issues with the package version. Adding this METADATA
resolves the problem. Also updated the build method from
easy_install to build and corrected an error from the
"transform_rel_path_into_abs_path" function..

Test Plan:
PASS: app-gen-tool embbed with stx-9 now runs with
the --package-only flag without errors.

PASS: poc-starlingx-app application apply works
fine after the METADATA file being added.

Task: 50289
Story: 2010937
Change-Id: Iecdc5cc4770609a5f6be991568eec426ba59d0ac
Signed-off-by: Tomás N. P. Barros <tomas.barros@encora.com>
This commit is contained in:
Tomás N. P. Barros 2024-06-06 16:28:53 -03:00
parent 996661ed46
commit 4d511d15ce
6 changed files with 69 additions and 18 deletions

View File

@ -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 = ""

View File

@ -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

View File

@ -1,2 +1,3 @@
pyyaml==6.0.1
wheel==0.41.2
build==1.2.1

View File

@ -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,

View File

@ -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

View File

@ -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