Skip to content

Commit

Permalink
Merge branch '3006.x' into full_3006_bld
Browse files Browse the repository at this point in the history
  • Loading branch information
dmurphy18 authored Jan 31, 2025
2 parents 5779349 + 29d83c1 commit 186c32a
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test-packages-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ jobs:
with:
name: nox-linux-${{ matrix.arch }}-${{ inputs.nox-session }}

- name: "Ensure docker is running"
run: |
sudo systemctl start containerd || exit 0
- name: "Pull container ${{ matrix.container }}"
run: |
docker pull ${{ matrix.container }}
Expand Down
1 change: 1 addition & 0 deletions changelog/67017.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update for deprecation of hex in pygit2 1.15.0 and above
1 change: 1 addition & 0 deletions changelog/67019.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed blob path for salt.ufw in the firewall tutorial documentation
32 changes: 28 additions & 4 deletions doc/topics/jinja/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,9 @@ This text will be wrapped in quotes.

.. versionadded:: 2017.7.0

Scan through string looking for a location where this regular expression
produces a match. Returns ``None`` in case there were no matches found
Looks for a match for the specified regex anywhere in the string. If the string
does not match the regex, this filter returns ``None``. If the string _does_
match the regex, then the `capture groups`_ for the regex will be returned.

Example:

Expand All @@ -420,6 +421,29 @@ Returns:
("defabcdef",)
If the regex you use does not contain a capture group then the number of
capture groups will be zero, and a matching regex will return an empty tuple.
This means that the following ``if`` statement would evaluate as ``False``:

.. code-block:: jinja
{%- if 'foobar' | regex_search('foo') %}
If you do not need a capture group and are just looking to test if a string
matches a regex, then you should check to see if the filter returns ``None``:

.. code-block:: jinja
{%- if (some_var | regex_search('foo')) is not none %}
.. note::

In a Jinja statement, a null value (i.e. a Python ``None``) should be
expressed as ``none`` (i.e. lowercase). More info on this can be found in
the **Note** section here in the `jinja docs`_.

.. _`capture groups`: https://docs.python.org/3/library/re.html#re.Match.groups
.. _`jinja docs`: https://jinja.palletsprojects.com/en/stable/templates/#literals

.. jinja_ref:: regex_match

Expand All @@ -428,8 +452,8 @@ Returns:

.. versionadded:: 2017.7.0

If zero or more characters at the beginning of string match this regular
expression, otherwise returns ``None``.
Works exactly like :jinja_ref:`regex_search`, but only checks for matches at
the _beginning_ of the string passed into this filter.

Example:

Expand Down
2 changes: 1 addition & 1 deletion doc/topics/tutorials/firewall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ to allow traffic on ``tcp/4505`` and ``tcp/4506``:
**Ubuntu**

Salt installs firewall rules in :blob:`/etc/ufw/applications.d/salt.ufw
<pkg/salt.ufw>`. Enable with:
<pkg/common/salt.ufw>`. Enable with:

.. code-block:: bash
Expand Down
15 changes: 9 additions & 6 deletions salt/utils/gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ def _val_cb(x, y):
if HAS_PSUTIL:
cur_pid = os.getpid()
process = psutil.Process(cur_pid)
dgm_process_dir = dir(process)
cache_dir = self.opts.get("cachedir", None)
gitfs_active = self.opts.get("gitfs_remotes", None)
if cache_dir and gitfs_active:
Expand Down Expand Up @@ -1780,7 +1779,7 @@ def checkout(self, fetch_on_fail=True):
return None

try:
head_sha = self.peel(local_head).hex
head_sha = str(self.peel(local_head).id)
except AttributeError:
# Shouldn't happen, but just in case a future pygit2 API change
# breaks things, avoid a traceback and log an error.
Expand Down Expand Up @@ -1839,7 +1838,10 @@ def _perform_checkout(checkout_ref, branch=True):
self.repo.create_reference(local_ref, pygit2_id)

try:
target_sha = self.peel(self.repo.lookup_reference(remote_ref)).hex
target_sha = str(
self.peel(self.repo.lookup_reference(remote_ref)).id
)

except KeyError:
log.error(
"pygit2 was unable to get SHA for %s in %s remote '%s'",
Expand Down Expand Up @@ -1920,10 +1922,11 @@ def _perform_checkout(checkout_ref, branch=True):
else:
try:
# If no AttributeError raised, this is an annotated tag
tag_sha = tag_obj.target.hex
tag_sha = str(tag_obj.target.id)

except AttributeError:
try:
tag_sha = tag_obj.hex
tag_sha = str(tag_obj.id)
except AttributeError:
# Shouldn't happen, but could if a future pygit2
# API change breaks things.
Expand Down Expand Up @@ -2277,7 +2280,7 @@ def find_file(self, path, tgt_env):
blob = None
break
if isinstance(blob, pygit2.Blob):
return blob, blob.hex, mode
return blob, str(blob.id), mode
return None, None, None

def get_tree_from_branch(self, ref):
Expand Down
19 changes: 16 additions & 3 deletions tests/pytests/unit/utils/test_gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
if HAS_PYGIT2:
import pygit2

try:
from pygit2.enums import ObjectType

HAS_PYGIT2_ENUMS = True

except ModuleNotFoundError:
HAS_PYGIT2_ENUMS = False


@pytest.fixture
def minion_opts(tmp_path):
Expand Down Expand Up @@ -147,9 +155,14 @@ def _prepare_remote_repository_pygit2(tmp_path):
tree,
[repository.head.target],
)
repository.create_tag(
"annotated_tag", commit, pygit2.GIT_OBJ_COMMIT, signature, "some message"
)
if HAS_PYGIT2_ENUMS:
repository.create_tag(
"annotated_tag", commit, ObjectType.COMMIT, signature, "some message"
)
else:
repository.create_tag(
"annotated_tag", commit, pygit2.GIT_OBJ_COMMIT, signature, "some message"
)
return remote


Expand Down

0 comments on commit 186c32a

Please sign in to comment.