Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add esp-idf component manifests generation #555

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions devtools/devtool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python3

import argparse

import yaml

import devtool
import pathlib as p
import typing as t
Expand Down Expand Up @@ -29,6 +32,7 @@ class Devtool:
'target': 'Find components by target',
'depends': 'Show components that depend (directly or indirectly) on a specified component',
'ci': 'Show list of ci jobs to be done',
'manifest': 'Generate manifest for component'
}
README = 'README.md'

Expand Down Expand Up @@ -150,6 +154,53 @@ def cmd_depends(self):

print('\n'.join(self._find_dependants(args.dependency, {c.name: c for c in self.iter_components()}).keys()))

@staticmethod
def _get_maintainer(person: devtool.Person) -> str:
res = [person.full_name]
if person.email:
res.append(person.email)
elif person.url:
res.append(person.url)
elif person.gh_id:
res.append('https://github.com/%s' % person.gh_id)
if len(res) > 1:
res[1] = '<%s>' % res[1]
return ' '.join(res)

def cmd_manifest(self):
parser = argparse.ArgumentParser(
prog=self.PROGRAM,
description=self.COMMANDS['manifest'],
usage='devtool.py manifest [-h] [--namespace=<namespace>]'
)
parser.add_argument('--namespace', help='Component namespace', default='eil')
args = parser.parse_args(sys.argv[2:])

components = {c.name: c for c in self.iter_components()}
for name, c in components.items():
if name == 'example':
continue
path: p.Path = self.meta.repo_path / self.meta.COMPONENTS_DIR / name
manifest = {
'description': c.description,
'version': c.version,
'targets': [t for t in c.targets if t != 'esp8266'],
'license': c.license.value,
'maintainers': [self._get_maintainer(person) for person in c.code_owners],
'url': 'https://github.com/UncleRus/esp-idf-lib',
'repository': 'https://github.com/UncleRus/esp-idf-lib',
'issues': 'https://github.com/UncleRus/esp-idf-lib/issues',
'documentation': 'https://esp-idf-lib.readthedocs.io/en/latest/groups/%s.html' % name,
'examples': '../../examples/%s' % name,
'dependencies': {
'esp-idf': '>=4.3',
}
}
for d in c.depends:
if d in components:
manifest['dependencies']['eil/%s' % d] = '>=%s' % components[d].version
yaml.safe_dump(manifest, (path / 'idf_component.yml').open('w', encoding='utf-8'), sort_keys=False)

def cmd_ci(self):
diff = subprocess.run(
args=('git', 'diff', '--name-only', 'origin/master..HEAD'),
Expand Down
4 changes: 2 additions & 2 deletions devtools/devtool/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Licenses(str, Enum):

@staticmethod
def from_value(raw: str) -> Licenses:
if raw == 'BSD-3':
if raw.upper() == 'BSD-3':
return Licenses.BSD3
return Licenses(raw)

Expand Down Expand Up @@ -114,7 +114,7 @@ def load(m: Metadata, dirname: os.PathLike) -> Component:

lc = str(raw['license'])
try:
lc = Licenses.from_value(lc.upper())
lc = Licenses.from_value(lc)
except:
raise InvalidLicenseError(ctx, lc)

Expand Down