Skip to content

Commit

Permalink
Merge pull request #6 from cidrblock/fix_venv_warning
Browse files Browse the repository at this point in the history
Copy the collection before building
  • Loading branch information
cidrblock authored Aug 22, 2023
2 parents 83fd2db + f135635 commit 5fc77ba
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/pip4a/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,28 @@ def _install_core(self: Installer) -> None:
logger.critical(err)

def _install_collection(self: Installer) -> None:
"""Install the collection from the current working directory."""
"""Install the collection from the build directory."""
self._init_build_dir()

command = f"cp -r --parents $(git ls-files 2> /dev/null || ls) {C.COLLECTION_BUILD_DIR}"
msg = "Copying collection to build directory using git ls-files."
logger.info(msg)
msg = f"Running command: {command}"
logger.debug(msg)
try:
subprocess.run(
command,
check=True,
capture_output=not self.app.args.verbose,
shell=True, # noqa: S602
)
except subprocess.CalledProcessError as exc:
err = f"Failed to copy collection to build directory: {exc}"
logger.critical(err)

command = (
f"{self.bindir / 'ansible-galaxy'} collection build"
f"cd {C.COLLECTION_BUILD_DIR} &&"
f" {self.bindir / 'ansible-galaxy'} collection build"
f" --output-path {C.COLLECTION_BUILD_DIR}"
)

Expand All @@ -101,18 +118,22 @@ def _install_collection(self: Installer) -> None:
err = f"Failed to build collection: {exc} {exc.stderr}"
logger.critical(err)

built = [f for f in Path(C.COLLECTION_BUILD_DIR).iterdir() if f.is_file()]
built = [
f
for f in Path(C.COLLECTION_BUILD_DIR).iterdir()
if f.is_file() and f.name.endswith(".tar.gz")
]
if len(built) != 1:
err = (
"Expected to find one collection tarball in"
f"{C.COLLECTION_BUILD_DIR}, found {len(built)}"
)
raise RuntimeError(err)
built[0]
tarball = built[0]

command = (
f"{self.bindir / 'ansible-galaxy'} collection"
" install {tarball} -p {self.site_pkg_path}"
f" install {tarball} -p {self.site_pkg_path}"
)
env = os.environ
if not self.app.args.verbose:
Expand Down

0 comments on commit 5fc77ba

Please sign in to comment.