Skip to content

Commit

Permalink
Allow installation of pre-released collections (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jul 13, 2022
1 parent b619247 commit adbc34f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/ansible_compat/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import packaging
import subprocess_tee
from packaging.version import Version

from ansible_compat.config import (
AnsibleConfig,
Expand All @@ -36,6 +37,8 @@
CompletedProcess = subprocess.CompletedProcess

_logger = logging.getLogger(__name__)
# regex to extract the first version from a collection range specifier
version_re = re.compile(":[>=<]*([^,]*)")


class Runtime:
Expand Down Expand Up @@ -213,6 +216,13 @@ def install_collection(
if force or self.version_in_range(upper="2.11"):
cmd.append("--force")

# As ansible-galaxy install is not able to automatically determine
# if the range requires a pre-release, we need to manuall add the --pre
# flag when needed.
matches = version_re.search(collection)
if matches and Version(matches[1]).is_prerelease:
cmd.append("--pre")

if destination:
cmd.extend(["-p", str(destination)])
cmd.append(f"{collection}")
Expand Down Expand Up @@ -410,7 +420,7 @@ def require_collection( # noqa: C901
break
else:
if install:
self.install_collection(f"{name}:>={version}")
self.install_collection(f"{name}:>={version}" if version else name)
self.require_collection(name=name, version=version, install=False)
else:
msg = f"Collection '{name}' not found in '{paths}'"
Expand Down

0 comments on commit adbc34f

Please sign in to comment.