diff --git a/cli.py b/cli.py index 6aeaeda..e5f0206 100755 --- a/cli.py +++ b/cli.py @@ -631,7 +631,7 @@ Examples: src_entry = os.path.join(src_dir, entry) dst_entry = os.path.join(temp_src, entry) if os.path.isdir(src_entry): - shutil.copytree(src_entry, dst_entry) + shutil.copytree(src_entry, dst_entry, ignore=shutil.ignore_patterns('__pycache__', '*.pyc', '*.pyo')) else: shutil.copy2(src_entry, dst_entry) print( diff --git a/device.py b/device.py index 80c8991..15c3f96 100644 --- a/device.py +++ b/device.py @@ -122,6 +122,13 @@ class DeviceConnection: if not os.path.isdir(local_dir): raise ValueError(f"{local_dir} is not a directory") + # Host bytecode must never reach the device: remove it before uploading. + import shutil + for root, dirs, _files in os.walk(local_dir): + for d in [d for d in dirs if d == "__pycache__"]: + shutil.rmtree(os.path.join(root, d), ignore_errors=True) + dirs.remove(d) + self.connect() try: # Determine remote directory name @@ -158,6 +165,8 @@ class DeviceConnection: # Copy files for file in files: + if file.endswith((".pyc", ".pyo")): + continue local_file = os.path.join(root, file) # Handle root directory case properly if remote_base == '/':