Compare commits

..

20 commits

Author SHA1 Message Date
3f2920f37c bump: version 0.2.0a7 → 0.2.0a8 2025-02-17 11:17:43 +01:00
0010c9cf07 fix: add config.py file 2025-02-17 11:17:23 +01:00
fb7c3c3346 bump: version 0.2.0a6 → 0.2.0a7 2025-02-17 10:01:27 +01:00
e6582d6d9d fix: better error support 2025-02-17 10:01:23 +01:00
5cfa351e67 bump: version 0.2.0a5 → 0.2.0a6 2025-02-10 10:00:37 +01:00
e9b1ab5f85 feat: return 1 if output has problems 2025-02-10 10:00:09 +01:00
95da29454a bump: version 0.2.0a4 → 0.2.0a5 2025-02-05 11:58:25 +01:00
a530ff33d6 feat: user_data can be loaded after other plugins 2025-02-05 11:57:06 +01:00
dcbe1a99d6 bump: version 0.2.0a3 → 0.2.0a4 2025-01-04 12:33:31 +01:00
c0d103f2e8 fix: add and remove not_for_commandline property 2025-01-04 12:33:26 +01:00
e87bcbd4c8 bump: version 0.2.0a2 → 0.2.0a3 2025-01-04 12:00:02 +01:00
703b1ce70e fix: remove upgrade feature (now in formatter project) + better support of not_for_commandline feature 2025-01-04 11:59:43 +01:00
60ee2a6feb bump: version 0.2.0a1 → 0.2.0a2 2024-12-11 22:19:57 +01:00
6feebea664 fix: user_data and output are not plugins 2024-12-11 22:19:44 +01:00
b5c845f90c bump: version 0.2.0a0 → 0.2.0a1 2024-11-28 21:47:36 +01:00
c79975c5df fix: separation between run and print function 2024-11-28 21:47:22 +01:00
52cbfc1f15 bump: version 0.1.2a0 → 0.2.0a0 2024-11-27 10:24:53 +01:00
e62797c79f feat: load config from environment if rougail-user-data-environment is installed 2024-11-27 09:20:30 +01:00
8073ef9bc1 bump: version 0.1.1 → 0.1.2a0 2024-11-25 09:20:44 +01:00
ea0076279c fix: translation is not mandatory 2024-11-25 09:18:59 +01:00
6 changed files with 153 additions and 18 deletions

View file

@ -1,3 +1,63 @@
## 0.2.0a8 (2025-02-17)
### Fix
- add config.py file
## 0.2.0a7 (2025-02-17)
### Fix
- better error support
## 0.2.0a6 (2025-02-10)
### Feat
- return 1 if output has problems
## 0.2.0a5 (2025-02-05)
### Feat
- user_data can be loaded after other plugins
## 0.2.0a4 (2025-01-04)
### Fix
- add and remove not_for_commandline property
## 0.2.0a3 (2025-01-04)
### Fix
- remove upgrade feature (now in formatter project) + better support of not_for_commandline feature
## 0.2.0a2 (2024-12-11)
### Fix
- user_data and output are not plugins
## 0.2.0a1 (2024-11-28)
### Fix
- separation between run and print function
## 0.2.0a0 (2024-11-27)
### Feat
- load config from environment if rougail-user-data-environment is installed
### Fix
- translation is not mandatory
## 0.1.1 (2024-11-06)
## 0.1.1rc0 (2024-11-06)
### Fix

View file

@ -4,7 +4,7 @@ requires = ["flit_core >=3.8.0,<4"]
[project]
name = "rougail.cli"
version = "0.1.1"
version = "0.2.0a8"
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
readme = "README.md"
description = "CLI for Rougail"
@ -40,5 +40,5 @@ name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "pep440"
version_provider = "pep621"
#update_changelog_on_bump = true
update_changelog_on_bump = true
changelog_merge_prerelease = true

View file

@ -1,6 +1,6 @@
"""
Silique (https://www.silique.fr)
Copyright (C) 2024
Copyright (C) 2024-2025
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View file

@ -1,6 +1,6 @@
"""
Silique (https://www.silique.fr)
Copyright (C) 2024
Copyright (C) 2024-2025
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -17,13 +17,18 @@ along with Mtools. If not, see <http://www.gnu.org/licenses/>.
"""
from tiramisu_cmdline_parser import TiramisuCmdlineParser
from tiramisu.error import PropertiesOptionError
from tiramisu import Config
from pathlib import Path
from rougail import Rougail, PropertiesOptionError
from rougail import Rougail
from rougail.config import get_rougail_config
from rougail.update import RougailUpgrade
from rougail.utils import load_modules
try:
from rougail.user_data_environment import RougailUserDataEnvironment
from rougail.user_datas import UserDatas
except ImportError:
RougailUserDataEnvironment = None
from .i18n import _
@ -32,20 +37,31 @@ def _main():
rougailconfig = get_rougail_config(
backward_compatibility=False, add_extra_options=False
)
rougailconfig.generate_config()
cmd_config = rougailconfig.config
origin_prop = cmd_config.property.default('read_write', 'append')
cmd_config.property.setdefault(frozenset(origin_prop | {"not_for_commandline"}), 'read_write', 'append')
cmd_config.property.read_write()
cmd_config.property.add("not_for_commandline")
if RougailUserDataEnvironment:
fake_rougail_config = {'step.user_data': 'environment',
'environment.default_environment_name': 'ROUGAILCLI',
}
user_data = UserDatas(cmd_config).user_datas(RougailUserDataEnvironment(cmd_config, rougailconfig=fake_rougail_config).run())
if user_data["errors"]:
raise Exception(user_data["errors"][0])
if user_data["warnings"]:
raise Exception(user_data["warnings"][0])
parser = TiramisuCmdlineParser(
cmd_config,
add_extra_options=False,
short_name_max_len=2,
)
parser.parse_args()
global print_traceback
print_traceback = rougailconfig["cli.debug"]
cmd_config.property.setdefault(origin_prop, 'read_write', 'append')
cmd_config.property.remove("not_for_commandline")
cmd_config.property.read_only()
if rougailconfig["upgrade"]:
RougailUpgrade(rougailconfig=rougailconfig).run()
return
try:
user_data_names = rougailconfig["step.user_data"]
except PropertiesOptionError:
@ -53,10 +69,7 @@ def _main():
output_name = rougailconfig["step.output"]
# structural
rougail = Rougail(rougailconfig)
for user_data_name in user_data_names:
rougail.converted.plugins.append("user_data_" + user_data_name)
rougail.converted.plugins.append("output_" + output_name)
config = rougail.get_config()
config = rougail.run()
# data user
if not user_data_names:
user_datas = None
@ -74,6 +87,8 @@ def _main():
_('cannot find "user_data" module "{0}"').format(user_data_name)
)
module = load_modules("rougail.user_data_" + user_data_name, str(path))
if hasattr(module.RougailUserData, 'force_apply_user_data') and module.RougailUserData.force_apply_user_data is True:
continue
user_datas.extend(
module.RougailUserData(
config,
@ -84,6 +99,23 @@ def _main():
err_warn = rougail.user_datas(user_datas)
else:
err_warn = {"errors": [], "warnings": []}
if user_data_names:
config.property.read_write()
user_datas = []
for user_data_name in user_data_names:
path = (
Path(__file__).parent.parent
/ ("user_data_" + user_data_name)
/ "__init__.py"
)
module = load_modules("rougail.user_data_" + user_data_name, str(path))
if hasattr(module.RougailUserData, 'force_apply_user_data') and module.RougailUserData.force_apply_user_data is True:
ret = module.RougailUserData(
config,
rougailconfig=rougailconfig,
).run()
err_warn["errors"].extend(ret["errors"])
err_warn["warnings"].extend(ret["warnings"])
# output
config.property.read_only()
path = Path(__file__).parent.parent / ("output_" + output_name) / "__init__.py"
@ -92,17 +124,24 @@ def _main():
_('cannot find cli file for "output_name" module "{0}"').format(output_name)
)
module = load_modules("rougail.output_" + output_name, str(path))
module.RougailOutput(
ret = module.RougailOutput(
config=config,
rougailconfig=rougailconfig,
user_data_errors=err_warn["errors"],
user_data_warnings=err_warn["warnings"],
).run()
).print()
if ret is False:
exit(1)
def main():
global print_traceback
print_traceback = False
try:
_main()
except Exception as err:
if print_traceback:
import traceback
traceback.print_exc()
print(_("ERROR: {0}").format(err))
exit(1)

36
src/rougail/cli/config.py Normal file
View file

@ -0,0 +1,36 @@
"""
Silique (https://www.silique.fr)
Copyright (C) 2025
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from .i18n import _
def get_rougail_config(
*,
backward_compatibility: bool = True, # pylint: disable=unused-argument
) -> dict:
options = f"""
cli:
debug:
description: {_('display debug informations')}
negative_description: {_('do not display debut informations')}
default: false
"""
return {
"options": options,
"process": None,
}

View file

@ -1,6 +1,6 @@
"""Internationalisation utilities
Silique (https://www.silique.fr)
Copyright (C) 2024
Copyright (C) 2024-2025
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -19,6 +19,6 @@ along with Mtools. If not, see <http://www.gnu.org/licenses/>.
from gettext import translation
from pathlib import Path
t = translation("rougail_cli", str(Path(__file__).parent / "locale"))
t = translation("rougail_cli", str(Path(__file__).parent / "locale"), fallback=True)
_ = t.gettext