Skip to content

Commit

Permalink
🐛(ozi-new interactive): fix arg passing to ozi-new project
Browse files Browse the repository at this point in the history
Signed-off-by: rjdbcm <[email protected]>
  • Loading branch information
rjdbcm committed Jun 30, 2024
1 parent daac072 commit 561d068
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
9 changes: 9 additions & 0 deletions ozi/new/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from ozi.new.interactive import interactive_prompt
from ozi.new.parser import parser
from ozi.new.validate import valid_classifier
from ozi.new.validate import valid_contact_info
from ozi.new.validate import valid_copyright_head
from ozi.new.validate import valid_emails
Expand Down Expand Up @@ -79,6 +80,14 @@ def _valid_project(project: Namespace) -> Namespace:
author_email=project.author_email,
maintainer_email=project.maintainer_email,
)
for i in [
project.audience,
project.environment,
project.framework,
project.topic,
]:
for classifier in i:
valid_classifier(classifier)
return project


Expand Down
13 changes: 7 additions & 6 deletions ozi/new/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import re
import sys
from functools import lru_cache
from itertools import chain
from typing import TYPE_CHECKING
from typing import Any
from typing import Sequence
Expand Down Expand Up @@ -798,7 +797,7 @@ def validate_message(


def classifier_checkboxlist(key: str) -> list[str] | None: # pragma: no cover
return checkboxlist_dialog(
result = checkboxlist_dialog(
values=sorted(
(
zip(
Expand All @@ -813,6 +812,7 @@ def classifier_checkboxlist(key: str) -> list[str] | None: # pragma: no cover
ok_text='✔ Ok',
cancel_text='← Back',
).run()
return result


def header_input( # noqa: C901
Expand Down Expand Up @@ -988,8 +988,9 @@ def menu_loop(
):
output.setdefault(f'--{x}', [])
classifier = classifier_checkboxlist(x)
if classifier:
output[f'--{x}'] += classifier
if classifier is not None:
for i in classifier:
output[f'--{x}'].append(i)
prefix.update(
(
{
Expand Down Expand Up @@ -1235,5 +1236,5 @@ def interactive_prompt(project: Namespace) -> list[str]: # noqa: C901 # pragma
for i in v:
if len(i) > 0:
ret_args += [k, i]

return list(chain.from_iterable(ret_args))
print(ret_args)
return ret_args
10 changes: 5 additions & 5 deletions ozi/new/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
help='Classifier: Intended Audience (Multiple Use), default: ["Other Audience"]',
default=METADATA.spec.python.pkg.info.classifiers.intended_audience,
nargs='?',
action=CloseMatch,
action='append',
)
defaults.add_argument(
'--typing',
Expand All @@ -172,7 +172,7 @@
metavar='ENVIRONMENT_NAMES',
default=METADATA.spec.python.pkg.info.classifiers.environment,
help='Classifier: Environment (Multiple Use), default: ["Other Environment"]',
action=CloseMatch,
action='append',
nargs='?',
type=str,
)
Expand Down Expand Up @@ -210,7 +210,7 @@
'--framework',
help='Classifier: Framework (Multiple Use)',
metavar='FRAMEWORK_NAMES',
action=CloseMatch,
action='append',
type=str,
nargs='?',
default=[],
Expand All @@ -229,7 +229,7 @@
metavar='LANGUAGE_NAMES',
default=['English'],
help='Classifier: Natural Language (Multiple Use), default: ["English"]',
action=CloseMatch,
action='append',
type=str,
nargs='?',
)
Expand All @@ -238,7 +238,7 @@
help='Classifier: Topic (Multiple Use)',
nargs='?',
metavar='TOPIC_NAMES',
action=CloseMatch,
action='append',
type=str,
default=[],
)
Expand Down
11 changes: 11 additions & 0 deletions ozi/new/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pyparsing import ParseException
from pyparsing import ParseResults
from pyparsing import Regex
from trove_classifiers import classifiers

from ozi.spdx import spdx_license_expression
from ozi.spec import METADATA
Expand All @@ -23,6 +24,16 @@
from ozi.vendor.email_validator import ValidatedEmail
from ozi.vendor.email_validator import validate_email

_CLASSIFIERS = {i.partition(' :: ')[2].strip() for i in classifiers}


def valid_classifier(classifier: str) -> None:
"""Validate a classifier string"""
if classifier in _CLASSIFIERS or classifier in classifiers:
TAP.ok('Classifier', classifier)
else: # pragma: no cover
TAP.not_ok('Classifier', 'invalid', classifier)


def valid_project_url(project_url: Sequence[str]) -> None:
"""Validate a list of project urls strings of the format ``name,url``."""
Expand Down
10 changes: 5 additions & 5 deletions tests/test_ozi_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@
'license_exception_id': st.one_of(
list(map(st.just, ozi.actions.ExactMatch().license_exception_id)), # type: ignore
),
'topic': st.lists(st.sampled_from(list(map(st.just, ozi.actions.ExactMatch().topic)))), # type: ignore
'topic': st.lists(st.sampled_from(ozi.actions.ExactMatch().topic)), # type: ignore
'audience': st.lists(
st.sampled_from(list(map(st.just, ozi.actions.ExactMatch().audience))), # type: ignore
st.sampled_from(ozi.actions.ExactMatch().audience), # type: ignore
),
'framework': st.lists(
st.sampled_from(list(map(st.just, ozi.actions.ExactMatch().framework))), # type: ignore
st.sampled_from(ozi.actions.ExactMatch().framework), # type: ignore
),
'environment': st.lists(
st.sampled_from(list(map(st.just, ozi.actions.ExactMatch().environment))), # type: ignore
st.sampled_from(ozi.actions.ExactMatch().environment), # type: ignore
),
'status': st.lists(
st.sampled_from(list(map(st.just, ozi.actions.ExactMatch().status))), # type: ignore
st.sampled_from(ozi.actions.ExactMatch().status), # type: ignore
),
'dist_requires': st.lists(
st.from_regex(
Expand Down

0 comments on commit 561d068

Please sign in to comment.