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:
parent
996661ed46
commit
4d511d15ce
@ -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:
|
def transform_rel_path_into_abs_path(abs_path: str, rel_path: str) -> str:
|
||||||
"""It transforms the rel_path into an absolute path"""
|
"""It transforms the rel_path into an absolute path"""
|
||||||
|
if rel_path[0] == '/':
|
||||||
|
return rel_path
|
||||||
if rel_path[:2] == './':
|
if rel_path[:2] == './':
|
||||||
rel_path = rel_path.replace('./', 'app-gen-tool/')
|
rel_path = rel_path.replace('./', 'app-gen-tool/')
|
||||||
longest_common_path = ""
|
longest_common_path = ""
|
||||||
|
@ -7,6 +7,7 @@ import yaml
|
|||||||
from app_gen_tool.application import Application
|
from app_gen_tool.application import Application
|
||||||
from app_gen_tool.common import uppercase_name
|
from app_gen_tool.common import uppercase_name
|
||||||
from app_gen_tool import constants
|
from app_gen_tool import constants
|
||||||
|
from pbr.version import VersionInfo
|
||||||
|
|
||||||
|
|
||||||
class FluxCD(Application):
|
class FluxCD(Application):
|
||||||
@ -178,6 +179,54 @@ class FluxCD(Application):
|
|||||||
if not os.path.exists(self._app['outputLifecycleDir']):
|
if not os.path.exists(self._app['outputLifecycleDir']):
|
||||||
os.makedirs(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
|
# Sub-process of app generation
|
||||||
# generate application plugin files
|
# generate application plugin files
|
||||||
def _gen_plugins(self):
|
def _gen_plugins(self):
|
||||||
@ -303,7 +352,7 @@ class FluxCD(Application):
|
|||||||
setup_py_file = os.path.join(plugin_dir, 'setup.py')
|
setup_py_file = os.path.join(plugin_dir, 'setup.py')
|
||||||
file_content = (
|
file_content = (
|
||||||
'import setuptools\n\nsetuptools.setup(\n '
|
'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:
|
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)
|
directory = os.path.join(plugin_dir, appname)
|
||||||
self.create_init_file(directory)
|
self.create_init_file(directory)
|
||||||
|
|
||||||
|
# Generate METADATA file
|
||||||
|
self._write_metadata_file()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Sub-process of app generation
|
# Sub-process of app generation
|
||||||
@ -335,17 +387,8 @@ class FluxCD(Application):
|
|||||||
os.makedirs(dirplugins, exist_ok=True)
|
os.makedirs(dirplugins, exist_ok=True)
|
||||||
os.chdir(dirplugins)
|
os.chdir(dirplugins)
|
||||||
|
|
||||||
command = [
|
|
||||||
'python3',
|
|
||||||
'setup.py',
|
|
||||||
'bdist_wheel',
|
|
||||||
'--universal',
|
|
||||||
'-d',
|
|
||||||
'.',
|
|
||||||
]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.call(command, stderr=subprocess.STDOUT)
|
subprocess.run(["python3 -m build"], shell=True)
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
pyyaml==6.0.1
|
pyyaml==6.0.1
|
||||||
wheel==0.41.2
|
wheel==0.41.2
|
||||||
|
build==1.2.1
|
@ -36,7 +36,7 @@ setup(
|
|||||||
f'{PACKAGE_NAME} = {PACKAGE_DIRECTORY}.cmd.generator:main',
|
f'{PACKAGE_NAME} = {PACKAGE_DIRECTORY}.cmd.generator:main',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
setup_requires=['pbr>=0.5'],
|
setup_requires=['pbr>=5.0.0'],
|
||||||
pbr=True,
|
pbr=True,
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import git
|
import git
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import glob
|
import fnmatch
|
||||||
|
|
||||||
|
|
||||||
from app_gen_tool.common import get_chart_from_git
|
from app_gen_tool.common import get_chart_from_git
|
||||||
@ -178,7 +178,11 @@ class TestFluxCDAppGen:
|
|||||||
|
|
||||||
FluxCD._gen_plugin_wheels(app)
|
FluxCD._gen_plugin_wheels(app)
|
||||||
|
|
||||||
output_file = os.path.join(self.OUTPUT_FOLDER, "plugins", "*.whl")
|
output_dir = os.path.join(self.OUTPUT_FOLDER, "plugins")
|
||||||
file_exists = glob.glob(output_file, recursive = True)
|
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
|
assert file_exists
|
@ -1,5 +1,6 @@
|
|||||||
hacking>=1.1.0,<=2.0.0 # Apache-2.0
|
hacking>=1.1.0,<=2.0.0 # Apache-2.0
|
||||||
bashate>=0.2
|
bashate>=0.2
|
||||||
|
build==1.2.1
|
||||||
PyYAML>=3.1.0
|
PyYAML>=3.1.0
|
||||||
shellcheck-py;python_version>="3.0" # MIT
|
shellcheck-py;python_version>="3.0" # MIT
|
||||||
yamllint<1.26.1;python_version>="3.0" # GPLv2
|
yamllint<1.26.1;python_version>="3.0" # GPLv2
|
||||||
|
Loading…
Reference in New Issue
Block a user