Compare commits

...

2 commits

4 changed files with 35 additions and 13 deletions

View file

@ -1,3 +1,9 @@
## 0.1.0a1 (2025-11-21)
### Fix
- ExtentionError => ExtensionError
## 0.1.0a0 (2025-11-06) ## 0.1.0a0 (2025-11-06)
### Feat ### Feat

View file

@ -4,7 +4,7 @@ requires = ["flit_core >=3.8.0,<4"]
[project] [project]
name = "rougail.user_data_questionary" name = "rougail.user_data_questionary"
version = "0.1.0a0" version = "0.1.0a1"
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}] authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
readme = "README.md" readme = "README.md"
description = "Rougail user_data questionary" description = "Rougail user_data questionary"

View file

@ -1 +1 @@
__version__ = "0.1.0a0" __version__ = "0.1.0a1"

View file

@ -18,12 +18,13 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import warnings
from questionary import text, select, confirm, password, Validator, ValidationError, print as qprint from questionary import text, select, confirm, password, Validator, ValidationError, print as qprint
from rougail.tiramisu import CONVERT_OPTION from rougail.tiramisu import CONVERT_OPTION
from rougail.config import RougailConfig from rougail.config import RougailConfig
from rougail.error import ExtentionError from rougail.error import ExtensionError
from tiramisu.error import ValueOptionError from tiramisu.error import ValueOptionError, ValueErrorWarning, ValueWarning
class RougailUserDataQuestionary: class RougailUserDataQuestionary:
@ -45,15 +46,22 @@ class RougailUserDataQuestionary:
rougailconfig['step.user_data'] = user_data rougailconfig['step.user_data'] = user_data
user_data = rougailconfig['step.user_data'] user_data = rougailconfig['step.user_data']
if 'questionary' not in user_data: if 'questionary' not in user_data:
raise ExtentionError('questionary is not set in step.user_data') raise ExtensionError('questionary is not set in step.user_data')
self.rougailconfig = rougailconfig self.rougailconfig = rougailconfig
self.errors = [] self.errors = []
self.warnings = [] self.warnings = []
warnings.simplefilter("always", ValueErrorWarning)
warnings.simplefilter("always", ValueWarning)
def run( def run(
self, self,
) -> None: ) -> None:
self.config.property.read_write() # self.config.property.read_write()
if 'demoting_error_warning' not in self.config.property.get():
add_demoting = True
self.config.property.add('demoting_error_warning')
else:
add_demoting = False
if self.rougailconfig['questionary.mandatory']: if self.rougailconfig['questionary.mandatory']:
current_titles = [] current_titles = []
while True: while True:
@ -75,16 +83,14 @@ class RougailUserDataQuestionary:
self.display_questionary(mandatory) self.display_questionary(mandatory)
else: else:
self.parse(self.config) self.parse(self.config)
self.config.property.read_only() if add_demoting:
return {'errors': [], self.config.property.remove('demoting_error_warning')
'warnings': [],
}
return [ return [
{ {
"source": 'Questionary', "source": 'Questionary',
"errors": self.errors, "errors": self.errors,
"warnings": self.warnings, "warnings": self.warnings,
"values": values, "values": [],
} }
] ]
@ -103,6 +109,8 @@ class RougailUserDataQuestionary:
kwargs = {} kwargs = {}
option_type = option.information.get('type') option_type = option.information.get('type')
isdefault = option.owner.isdefault() isdefault = option.owner.isdefault()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
default = option.value.get() default = option.value.get()
ismulti = option.ismulti() ismulti = option.ismulti()
type_obj = None type_obj = None
@ -159,7 +167,15 @@ class RougailValidator(Validator):
value.append(val) value.append(val)
if validate: if validate:
try: try:
with warnings.catch_warnings(record=True) as warns:
self.option.value.set(value) self.option.value.set(value)
for warn in warns:
if isinstance(warn.message, ValueErrorWarning):
warn.message.prefix = ''
raise ValidationError(
message=str(warn.message),
cursor_position=len(document),
)
except ValueOptionError as err: except ValueOptionError as err:
err.prefix = '' err.prefix = ''
raise ValidationError( raise ValidationError(