Skip to content

Commit

Permalink
Add project tool.belay.ignore functionality. Fix sync ignores for dir…
Browse files Browse the repository at this point in the history
…ectoreis
  • Loading branch information
BrianPugh committed May 30, 2023
1 parent 0f4fa99 commit 239bbf1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions belay/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def progress_update(description=None, **kwargs):
folder=project_folder / project_package,
dst=f"/{project_package}",
progress_update=tasks["project_package"],
ignore=config.ignore,
)

if main:
Expand Down
3 changes: 2 additions & 1 deletion belay/device_sync_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Optional, Union

from pathspec import PathSpec
from pathspec.util import append_dir_sep

from ._minify import minify as minify_code
from .hash import fnv1a
Expand All @@ -20,7 +21,7 @@ def discover_files_dirs(
ignore = []
ignore_spec = PathSpec.from_lines("gitwildmatch", ignore)
for src_object in local_file_or_folder.rglob("*"):
if ignore_spec.match_file(str(src_object)):
if ignore_spec.match_file(append_dir_sep(src_object)):
continue
src_objects.append(src_object)
# Sort so that folder creation comes before file sending.
Expand Down
3 changes: 3 additions & 0 deletions belay/packagemanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class BelayConfig(BaseModel):
# Name/Folder of project's primary micropython code.
name: Optional[str] = None

# Items in project directory to ignore.
ignore: Optional[list] = []

# "main" dependencies
dependencies: Dict[str, DependencyList] = {}

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ belay = "belay.cli.main:run_app"
python = "^3.8" # TODO: unrestrict upper bound once Questionary loosens
pyserial = ">=3.1"
typer = {extras = ["all"], version = ">=0.6.0"}
pathspec = "*"
pathspec = ">=0.10.3"
tomli = ">=2.0.1"
autoregistry = ">=0.10.1"
fsspec = {version = ">=2022.11.0", extras = ["http"]}
Expand Down
1 change: 1 addition & 0 deletions tests/cli/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_install_basic(tmp_path, mocker, mock_device):
progress_update=mocker.ANY,
mpy_cross_binary=None,
dst="/my_pkg_name",
ignore=[],
),
]
)
41 changes: 41 additions & 0 deletions tests/test_device_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,47 @@ def test_discover_files_dirs_dir_ignore(tmp_path):
]


def test_discover_files_dirs_dir_ignore_folder(tmp_path):
(tmp_path / "file1.ext").touch()
(tmp_path / "file2.pyc").touch()
(tmp_path / "folder1").mkdir()
(tmp_path / "folder1" / "file3.ext").touch()

remote_dir = "/foo/bar"

src_files, src_dirs, dst_files = belay.device.discover_files_dirs(
remote_dir=remote_dir,
local_file_or_folder=tmp_path,
ignore=["*.pyc", "folder1"],
)

src_files = [x.relative_to(tmp_path) for x in src_files]
src_dirs = [x.relative_to(tmp_path) for x in src_dirs]
assert src_files == [
Path("file1.ext"),
]
assert src_dirs == []
assert dst_files == [
Path("/foo/bar/file1.ext"),
]

src_files, src_dirs, dst_files = belay.device.discover_files_dirs(
remote_dir=remote_dir,
local_file_or_folder=tmp_path,
ignore=["*.pyc", "folder1/"], # Testing trailing slash
)

src_files = [x.relative_to(tmp_path) for x in src_files]
src_dirs = [x.relative_to(tmp_path) for x in src_dirs]
assert src_files == [
Path("file1.ext"),
]
assert src_dirs == []
assert dst_files == [
Path("/foo/bar/file1.ext"),
]


def test_discover_files_dirs_empty(tmp_path):
remote_dir = "/foo/bar"
src_files, src_dirs, dst_files = belay.device.discover_files_dirs(
Expand Down

0 comments on commit 239bbf1

Please sign in to comment.