Skip to content

Commit

Permalink
Fix copy file error on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianonicolai committed Nov 27, 2023
1 parent 7eeb2ec commit 7960a1d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
1 change: 1 addition & 0 deletions .config/requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ansible-builder
pyyaml
subprocess-tee
gitpython
1 change: 1 addition & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
default_python: "3.11" # used by jobs in other_names
other_names: |
lint
platforms: linux,macos

tox:
name: ${{ matrix.name }} / python ${{ matrix.python_version }}
Expand Down
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ repos:
- "--config=pyproject.toml"

- repo: https://github.com/pycqa/pylint.git
rev: v3.0.1
rev: v3.0.2
hooks:
- id: pylint
args:
Expand All @@ -81,9 +81,10 @@ repos:
- subprocess_tee
- setuptools
- tox
- gitpython

- repo: https://github.com/pre-commit/mirrors-mypy.git
rev: v1.6.1
rev: v1.7.0
hooks:
- id: mypy
additional_dependencies:
Expand All @@ -92,6 +93,7 @@ repos:
- tox
- types-PyYAML
- types-setuptools
- gitpython
args:
- src
- tests
Expand Down
55 changes: 38 additions & 17 deletions src/ansible_development_environment/subcommands/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pathlib import Path
from typing import TYPE_CHECKING

from git import Repo

from ansible_development_environment.collection import (
Collection,
parse_collection_request,
Expand Down Expand Up @@ -204,7 +206,39 @@ def _install_galaxy_requirements(self: Installer) -> None:
msg = f"Installed collections include: {oxford_join(installed)}"
self._output.note(msg)

def _install_local_collection( # noqa: PLR0915, PLR0912
def _copy_git_repo_files(
self: Installer,
local_repo_path: Path | None,
destination_path: Path,
) -> None:
if local_repo_path is None:
msg = "Invalid repo path, no files to copy from Git"
self._output.info(msg)
return

repo = Repo(local_repo_path)

# Get the list of tracked files in the repository
tracked_files = repo.git.ls_files().split("\n")

# Create the destination folder if it doesn't exist
Path(destination_path).mkdir(parents=True, exist_ok=True)

for file in tracked_files:
src_file_path = Path(local_repo_path) / file
dest_file_path = Path(destination_path) / file

# Ensure the destination directory for the file exists
dest_file_path.parent.mkdir(parents=True, exist_ok=True)

try:
# Copy the file
shutil.copy2(src_file_path, dest_file_path)
except shutil.Error as exc:
err = f"Failed to copy collection to build directory: {exc}"
self._output.critical(err)

def _install_local_collection(
self: Installer,
collection: Collection,
) -> None:
Expand All @@ -220,23 +254,10 @@ def _install_local_collection( # noqa: PLR0915, PLR0912
msg = f"Installing local collection from: {collection.build_dir}"
self._output.info(msg)

command = (
"cp -r --parents $(git ls-files 2> /dev/null || ls)"
f" {collection.build_dir}"
self._copy_git_repo_files(
local_repo_path=collection.path,
destination_path=collection.build_dir,
)
msg = "Copying collection to build directory using git ls-files."
self._output.debug(msg)
try:
subprocess_run(
command=command,
cwd=collection.path,
verbose=self._config.args.verbose,
msg=msg,
output=self._output,
)
except subprocess.CalledProcessError as exc:
err = f"Failed to copy collection to build directory: {exc} {exc.stderr}"
self._output.critical(err)

command = (
f"cd {collection.build_dir} &&"
Expand Down

0 comments on commit 7960a1d

Please sign in to comment.