From: Gbkng Date: Wed, 14 Feb 2024 08:44:02 +0000 (+0100) Subject: git: ignore VSCode cache files, sat cache file and add a pre-commit config X-Git-Tag: V9_13_0~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=076787ab22f087dc3a9a0212e0b09227b250bf32;p=tools%2Fsat.git git: ignore VSCode cache files, sat cache file and add a pre-commit config --- diff --git a/.gitignore b/.gitignore index 856c9cd..5d2f227 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,9 @@ doc/src/commands/apidoc* # Byte-compiled / optimized / DLL files __pycache__/ + +# IDE/editors/tools cache files +.vscode/ + +# cache file, generated by sat, to store configuration +data/local.pyconf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..05a38b4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,81 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 # Use the ref you want to point at + hooks: + - id: trailing-whitespace + exclude: | + (?x)^( + .*\.py + )$ + - id: check-added-large-files + - id: debug-statements + - id: detect-private-key + - id: end-of-file-fixer + - id: mixed-line-ending + exclude: | + (?x)^( + .*\.py + )$ + - id: check-case-conflict + exclude: | + (?x)^( + .*\.py + )$ + - id: check-json + - id: pretty-format-json + - id: check-merge-conflict + - id: check-toml + - id: check-xml + - id: requirements-txt-fixer + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.1.9 + hooks: + # Run the linter. + - id: ruff + types_or: [python, pyi, jupyter] + args: [--fix] + exclude: | + (?x)^( + .*[Tt]est.*| + __init__.py + )$ + # Run the formatter. + - id: ruff-format + types_or: [python, pyi, jupyter] + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.8.0 + hooks: + - id: mypy + exclude: | + (?x)^( + .*[Tt]est.* + )$ + args: [--ignore-missing-imports, --explicit-package-bases] + - repo: https://github.com/scop/pre-commit-shfmt + rev: v3.7.0-4 + hooks: + # Choose one of: + - id: shfmt # prebuilt upstream executable + args: [--indent=4, -w, -s] + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.9.0.6 + hooks: + - id: shellcheck + args: [--severity=warning] + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.21.0 # or higher tag + hooks: + - id: yamllint + args: [--strict, '--config-data={extends: relaxed, rules: {line-length: {max: 120}}}'] + - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt + rev: 0.2.1 # or other specific tag + hooks: + - id: yamlfmt + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 # Use the ref you want to point at + hooks: + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal diff --git a/commands/config.py b/commands/config.py index a5997bb..6bb522c 100644 --- a/commands/config.py +++ b/commands/config.py @@ -22,6 +22,7 @@ import platform import datetime import shutil import gettext +from pathlib import Path import pprint as PP import src @@ -286,9 +287,15 @@ class ConfigManager: # Load LOCAL config file # search only in the data directory src.pyconf.streamOpener = ConfigOpener([cfg.VARS.datadir]) + + # if `local.pyconf` file is missing, create it from + # `local_original.pyconf` template file + localconf_path = osJoin(cfg.VARS.datadir, 'local.pyconf') + if not Path(localconf_path).is_file(): + shutil.copyfile(osJoin(cfg.VARS.datadir, 'local_original.pyconf'), localconf_path) + try: - local_cfg = src.pyconf.Config(open( osJoin(cfg.VARS.datadir, - 'local.pyconf')), + local_cfg = src.pyconf.Config(open(localconf_path), PWD = ('LOCAL', cfg.VARS.datadir) ) except src.pyconf.ConfigError as e: raise src.SatException(_("Error in configuration file: " diff --git a/data/local.pyconf b/data/local.pyconf deleted file mode 100644 index 24ee9eb..0000000 --- a/data/local.pyconf +++ /dev/null @@ -1,16 +0,0 @@ - - LOCAL : - { - base : 'default' - workdir : 'default' - log_dir : 'default' - archive_dir : 'default' - VCS : 'unknown' - tag : 'unknown' - } - PROJECTS : - { - project_file_paths : - [ - ] - }