Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…0.4.5 (#6)

Co-authored-by: salt-extensions-renovatebot[bot] <182623858+salt-extensions-renovatebot[bot]@users.noreply.github.com>
  • Loading branch information
salt-extensions-renovatebot[bot] authored Sep 28, 2024
1 parent 08de77a commit 90fb319
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Autogenerated. Do not edit this by hand, use `copier update`.
---
_commit: 0.4.4
_commit: 0.4.5
_src_path: https://github.com/lkubb/salt-extension-copier
author: EITR Technologies, LLC
author_email: [email protected]
Expand All @@ -13,7 +13,7 @@ license: apache
loaders:
- module
- state
max_salt_version: 3007
max_salt_version: '3007'
no_saltext_namespace: false
package_name: kubernetes
project_name: kubernetes
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repos:
language: python
pass_filenames: false

- repo: https://github.com/s0undt3ch/salt-rewrite
- repo: https://github.com/saltstack/salt-rewrite
# Automatically rewrite code with known rules
rev: 2.5.2
hooks:
Expand All @@ -45,7 +45,7 @@ repos:
files: ^src/saltext/kubernetes/.*\.py$
args: [--silent]

- repo: https://github.com/s0undt3ch/salt-rewrite
- repo: https://github.com/saltstack/salt-rewrite
# Automatically rewrite code with known rules
rev: 2.5.2
hooks:
Expand Down
50 changes: 48 additions & 2 deletions tools/helpers/copier.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
from functools import wraps
from pathlib import Path
Expand All @@ -13,7 +14,33 @@
yaml = None


COPIER_ANSWERS = Path(".copier-answers.yml").resolve()
if os.environ.get("STAGE"):
# If we're running inside a Copier task/migration, cwd is the target dir.
# We cannot use __file__ because this file is imported from the template clone.
COPIER_ANSWERS = Path(".copier-answers.yml").resolve()
else:
COPIER_ANSWERS = (Path(__file__).parent.parent.parent / ".copier-answers.yml").resolve()


if yaml is not None:

def represent_str(dumper, data):
"""
Represent multiline strings using "|"
"""
if len(data.splitlines()) > 1:
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
return dumper.represent_scalar("tag:yaml.org,2002:str", data)

class OpinionatedYamlDumper(yaml.SafeDumper):
"""
Indent lists by two spaces
"""

def increase_indent(self, flow=False, indentless=False):
return super().increase_indent(flow=flow, indentless=False)

OpinionatedYamlDumper.add_representer(str, represent_str)


def _needs_answers(func):
Expand All @@ -33,10 +60,29 @@ def load_answers():
"""
if not yaml:
raise RuntimeError("Missing pyyaml in environment")
with open(COPIER_ANSWERS) as f:
with open(COPIER_ANSWERS, encoding="utf-8") as f:
return yaml.safe_load(f)


@_needs_answers
def dump_answers(answers):
"""
Write the complete answers file. Depends on PyYAML.
Intended for answers migrations.
"""
if not yaml:
raise RuntimeError("Missing pyyaml in environment")
with open(COPIER_ANSWERS, "w", encoding="utf-8") as f:
yaml.dump(
answers,
f,
Dumper=OpinionatedYamlDumper,
indent=0,
default_flow_style=False,
canonical=False,
)


@_needs_answers
def discover_project_name():
"""
Expand Down
12 changes: 10 additions & 2 deletions tools/helpers/pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ def _run_pre_commit_loop(retries_left):
for i, failing_hook in enumerate(failing):
prompt.warn(f"✗ Failing hook ({i + 1}): {failing_hook}", failing[failing_hook])
finally:
# Undo git add --intent-to-add to allow RenovateBot to detect new files correctly
git("restore", "--staged", *new_files)
if new_files:
try:
# Check if there is at least one commit in the repo,
# otherwise git restore --staged fails.
git("rev-parse", "HEAD")
except ProcessExecutionError:
pass
else:
# Undo git add --intent-to-add to allow RenovateBot to detect new files correctly
git("restore", "--staged", *new_files)
return False

0 comments on commit 90fb319

Please sign in to comment.