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