Compare commits
No commits in common. "fe960191730064c1a7b03db4fe8f8a7b42b7974d" and "b7dbaaa95da057e97d0edc2a27cfb4cd6dc2e441" have entirely different histories.
fe96019173
...
b7dbaaa95d
17 changed files with 30 additions and 147 deletions
|
|
@ -1,10 +1,3 @@
|
|||
## 0.2.0a27 (2025-10-31)
|
||||
|
||||
### Fix
|
||||
|
||||
- remove all warnings!
|
||||
- update tests with new output_doc module
|
||||
|
||||
## 0.2.0a26 (2025-10-29)
|
||||
|
||||
### Fix
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ requires = ["flit_core >=3.8.0,<4"]
|
|||
|
||||
[project]
|
||||
name = "rougail.cli"
|
||||
version = "0.2.0a27"
|
||||
version = "0.2.0a26"
|
||||
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
|
||||
readme = "README.md"
|
||||
description = "CLI for Rougail"
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import os
|
|||
from warnings import filterwarnings
|
||||
from pathlib import Path
|
||||
from sys import exit
|
||||
from warnings import warn
|
||||
|
||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
|
@ -60,14 +59,15 @@ def _main(arguments, do_not_print):
|
|||
return list(versions)
|
||||
for version in versions:
|
||||
print(version)
|
||||
exit()
|
||||
config, err_warn = load_user_datas(rougailconfig)
|
||||
output = get_output(rougailconfig, config, err_warn)
|
||||
if do_not_print:
|
||||
return output.run()
|
||||
ret = output.print()
|
||||
if ret is False:
|
||||
exit(1)
|
||||
else:
|
||||
manage_warnings(rougailconfig["cli.warnings"])
|
||||
config, err_warn = load_user_datas(rougailconfig)
|
||||
output = get_output(rougailconfig, config, err_warn)
|
||||
if do_not_print:
|
||||
return output.run()
|
||||
ret = output.print()
|
||||
if ret is False:
|
||||
exit(1)
|
||||
|
||||
|
||||
def load_cmd_user_datas(rougailconfig, arguments):
|
||||
|
|
@ -89,27 +89,20 @@ def load_cmd_user_datas(rougailconfig, arguments):
|
|||
env_prefix = ENV_PREFIX
|
||||
else:
|
||||
env_prefix = None
|
||||
user_data = rougailconfig_load(rougailconfig, config_file, env_prefix, True, _arguments=arguments, _generate=False)
|
||||
display_warnings = rougailconfig["cli.warnings"]
|
||||
manage_warnings(display_warnings)
|
||||
user_data = rougailconfig_load(rougailconfig, config_file, env_prefix, True, display_warnings=cmd_config.option("cli.warnings").value.get(), raise_on_error=False, _arguments=arguments, _generate=False)
|
||||
# replays to display errors if needed
|
||||
if not cmd_config.option("cli.versions").value.get():
|
||||
if display_warnings and user_data["warnings"]:
|
||||
for warning in user_data["warnings"]:
|
||||
warn(warning)
|
||||
if manage_warnings:
|
||||
# replays to display errors if needed
|
||||
parser = TiramisuCmdlineParser(
|
||||
cmd_config,
|
||||
short_name_max_len=2,
|
||||
)
|
||||
parser.parse_args(arguments)
|
||||
parser = TiramisuCmdlineParser(
|
||||
cmd_config,
|
||||
short_name_max_len=2,
|
||||
)
|
||||
parser.parse_args(arguments)
|
||||
if user_data["errors"]:
|
||||
raise Exception(user_data["errors"][0])
|
||||
|
||||
cmd_config.property.setdefault(origin_prop, "read_write", "append")
|
||||
cmd_config.property.read_only()
|
||||
cmd_config.property.remove("not_for_commandline")
|
||||
|
||||
cmd_config.property.read_only()
|
||||
return cmd_config
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
__version__ = "0.2.0a27"
|
||||
__version__ = "0.2.0a26"
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ GNU General Public License for more details.
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with Mtools. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from warnings import warn
|
||||
from rougail.user_datas import UserDatas
|
||||
|
||||
|
||||
|
|
@ -22,6 +23,8 @@ def load(rougailconfig: "RougailConfig",
|
|||
yaml_file: str=None,
|
||||
env_prefix: str=None,
|
||||
commandline: bool=False,
|
||||
display_warnings: bool=True,
|
||||
raise_on_error: bool=True,
|
||||
_arguments=None,
|
||||
_generate=True
|
||||
):
|
||||
|
|
@ -38,6 +41,11 @@ def load(rougailconfig: "RougailConfig",
|
|||
if commandline:
|
||||
user_datas.extend(from_cmdline(cmd_config, _arguments))
|
||||
user_data = UserDatas(cmd_config).user_datas(user_datas)
|
||||
if display_warnings and user_data["warnings"]:
|
||||
for warning in user_data["warnings"]:
|
||||
warn(warning)
|
||||
if raise_on_error and user_data["errors"]:
|
||||
raise Exception(user_data["errors"][0])
|
||||
cmd_config.property.importation(origin_prop)
|
||||
return user_data
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
my_variable:
|
||||
redefine: true
|
||||
validators: # validators in jinja without description makes warnings
|
||||
- jinja: |-
|
||||
{{ _.my_variable != "my_value" }}
|
||||
|
|
@ -1 +0,0 @@
|
|||
["family \"configuration rougail-json\" is disabled, \"test mandatories variables before display in json\" will be ignored when loading from the YAML file \"warnings.yml\""]
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
---
|
||||
main_structural_directories:
|
||||
- structures
|
||||
doc:
|
||||
output_format: console
|
||||
json:
|
||||
mandatory: true
|
||||
|
|
@ -1 +0,0 @@
|
|||
[]
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
---
|
||||
main_structural_directories:
|
||||
- structures
|
||||
doc:
|
||||
output_format: console
|
||||
json:
|
||||
mandatory: true
|
||||
cli:
|
||||
warnings: false
|
||||
|
|
@ -1 +0,0 @@
|
|||
["family \"configuration rougail-json\" is disabled, \"test mandatories variables before display in json\" will be ignored when loading from the YAML file \"warnings3.yml\"", "\"validators\" is a calculation for my_variable but has no description in \"structures/file.yml\" and \"structures_warnings/file.yml\""]
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
---
|
||||
main_structural_directories:
|
||||
- structures
|
||||
- structures_warnings
|
||||
doc:
|
||||
output_format: console
|
||||
json:
|
||||
mandatory: true
|
||||
|
|
@ -1 +0,0 @@
|
|||
[]
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
---
|
||||
main_structural_directories:
|
||||
- structures
|
||||
- structures_warnings
|
||||
doc:
|
||||
output_format: console
|
||||
json:
|
||||
mandatory: true
|
||||
cli:
|
||||
warnings: false
|
||||
|
|
@ -1 +1 @@
|
|||
"{\n \"my_variable\": {\n \"type\": \"variable\",\n \"default\": {\n \"name\": \"Default\",\n \"values\": \"my_value\"\n },\n \"properties\": [\n {\n \"type\": \"type\",\n \"name\": \"string\"\n },\n {\n \"type\": \"property\",\n \"name\": \"mandatory\"\n }\n ],\n \"path\": \"my_variable\",\n \"names\": [\n \"my_variable\"\n ],\n \"description\": \"A description.\",\n \"gen_examples\": [\n \"my_value\"\n ],\n \"mandatory_without_value\": false\n }\n}"
|
||||
"{\n \"my_variable\": {\n \"type\": \"variable\",\n \"default\": {\n \"name\": \"Default\",\n \"values\": \"my_value\"\n },\n \"properties\": [\n {\n \"type\": \"type\",\n \"name\": \"string\"\n },\n {\n \"type\": \"property\",\n \"name\": \"mandatory\"\n }\n ],\n \"path\": \"my_variable\",\n \"names\": [\n \"my_variable\"\n ],\n \"description\": \"A description.\"\n }\n}"
|
||||
|
|
@ -1 +1 @@
|
|||
"{\n \"my_variable\": {\n \"type\": \"variable\",\n \"default\": {\n \"name\": \"Default\",\n \"values\": \"my_value\"\n },\n \"properties\": [\n {\n \"type\": \"type\",\n \"name\": \"string\"\n },\n {\n \"type\": \"property\",\n \"name\": \"mandatory\"\n }\n ],\n \"path\": \"my_variable\",\n \"names\": [\n \"my_variable\"\n ],\n \"description\": \"A description.\",\n \"gen_examples\": [\n \"my_value\"\n ],\n \"mandatory_without_value\": false\n }\n}"
|
||||
"{\n \"my_variable\": {\n \"type\": \"variable\",\n \"default\": {\n \"name\": \"Default\",\n \"values\": \"my_value\"\n },\n \"properties\": [\n {\n \"type\": \"type\",\n \"name\": \"string\"\n },\n {\n \"type\": \"property\",\n \"name\": \"mandatory\"\n }\n ],\n \"path\": \"my_variable\",\n \"names\": [\n \"my_variable\"\n ],\n \"description\": \"A description.\"\n }\n}"
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
import os
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
from contextlib import chdir
|
||||
from json import dumps, loads
|
||||
|
|
@ -81,7 +80,7 @@ def test_cli_version_user_data_disabled_2():
|
|||
fh.write(dumps(ret[1]))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == (True, data), filename
|
||||
assert ret == (True, data)
|
||||
|
||||
|
||||
def test_cli_rougailcli():
|
||||
|
|
@ -120,67 +119,3 @@ def test_cli_rougailcli_mix():
|
|||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == (True, data)
|
||||
|
||||
|
||||
def test_cli_rougailcli_warning():
|
||||
with chdir(test_dir / 'rougailcli_file'):
|
||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings.yml'
|
||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||
warnings.simplefilter("always", UserWarning)
|
||||
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
||||
ret = [str(w.message) for w in rougail_wn]
|
||||
filename = Path('warnings.txt')
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(dumps([str(w.message) for w in rougail_wn]))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == data, str(filename.absolute())
|
||||
|
||||
|
||||
def test_cli_rougailcli_not_warning():
|
||||
with chdir(test_dir / 'rougailcli_file'):
|
||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings2.yml'
|
||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||
warnings.simplefilter("always", UserWarning)
|
||||
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
||||
filename = Path('warnings2.txt')
|
||||
ret = [str(w.message) for w in rougail_wn]
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(dumps(ret))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == data, str(filename.absolute())
|
||||
|
||||
|
||||
def test_cli_rougailcli_warning2():
|
||||
with chdir(test_dir / 'rougailcli_file'):
|
||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings3.yml'
|
||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||
warnings.simplefilter("always", UserWarning)
|
||||
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
||||
ret = [str(w.message) for w in rougail_wn]
|
||||
filename = Path('warnings3.txt')
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(dumps([str(w.message) for w in rougail_wn]))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == data, str(filename.absolute())
|
||||
|
||||
|
||||
def test_cli_rougailcli_not_warning2():
|
||||
with chdir(test_dir / 'rougailcli_file'):
|
||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings4.yml'
|
||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||
warnings.simplefilter("always", UserWarning)
|
||||
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
||||
filename = Path('warnings4.txt')
|
||||
ret = [str(w.message) for w in rougail_wn]
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(dumps(ret))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == data, str(filename.absolute())
|
||||
|
|
|
|||
Loading…
Reference in a new issue