LiveSync 0.3.1__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LiveSync
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Repeatedly synchronize local workspace with a (slow) remote machine
5
5
  Home-page: https://github.com/zauberzeug/livesync
6
6
  Author: Zauberzeug GmbH
@@ -26,8 +26,9 @@ It is available as [PyPI package](https://pypi.org/project/livesync/) and hosted
26
26
 
27
27
  [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview) and similar tools are great as long as your remote machine is powerful enough.
28
28
  But if your target is a Raspberry Pi, Jetson Nano/Xavier/Orin, Beagle Board or similar, it feels like coding in jelly.
29
- Especially if you run powerful extensions like Pylance.
29
+ Especially if you run powerful extensions like Pylance, GitHub Copilot or Duet AI.
30
30
  LiveSync solves this by watching your code for changes and just copying the modifications to the slow remote machine.
31
+ So you can develop on your own machine (and run tests there in the background) while all your changes appear also on the remote.
31
32
  It works best if you have some kind of reload mechanism in place on the target ([NiceGUI](https://nicegui.io), [FastAPI](https://fastapi.tiangolo.com/) or [Flask](https://flask.palletsprojects.com/) for example).
32
33
 
33
34
  ## Usage
@@ -59,10 +60,12 @@ Options:
59
60
  command to be executed on remote host after any file change (default: None)
60
61
  - `--mutex-interval MUTEX_INTERVAL`
61
62
  interval in which mutex is updated (default: 10 seconds)
63
+ - `--ignore-mutex`
64
+ ignore mutex (use with caution) (default: False)
62
65
 
63
66
  ### Python
64
67
 
65
- Simple example:
68
+ Simple example (where `robot` is the ssh hostname of the target system):
66
69
 
67
70
  ```py
68
71
  from livesync import Folder, sync
@@ -73,14 +76,25 @@ sync(
73
76
  )
74
77
  ```
75
78
 
79
+ The `sync` call will block until the script is aborted.
80
+ The `Folder` class allows to set the `port` and an `on_change` bash command which is executed after a sync has been performed.
81
+ Via the `rsync_args` build method you can pass additional options to configure rsync.
82
+
76
83
  Advanced example:
77
84
 
78
85
  ```py
86
+ import argparse
79
87
  from livesync import Folder, sync
80
88
 
89
+ parser = argparse.ArgumentParser(description='Sync local code with robot.')
90
+ parser.add_argument('robot', help='Robot hostname')
91
+
92
+ args = parser.parse_args()
93
+
94
+ touch = 'touch ~/robot/main.py'
81
95
  sync(
82
- Folder('.', 'robot:~/navigation', on_change='touch ~/navigation/main.py'),
83
- Folder('../rosys', 'robot:~/rosys', ssh_port=2222).rsync_args(add='-L', remove='--checksum'),
96
+ Folder('.', f'{args.robot}:~/navigation', on_change='touch ~/navigation/main.py'),
97
+ Folder('../rosys', f'{args.robot}:~/rosys').rsync_args(add='-L', remove='--checksum'),
84
98
  mutex_interval=30,
85
99
  )
86
100
  ```
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LiveSync
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Repeatedly synchronize local workspace with a (slow) remote machine
5
5
  Home-page: https://github.com/zauberzeug/livesync
6
6
  Author: Zauberzeug GmbH
@@ -26,8 +26,9 @@ It is available as [PyPI package](https://pypi.org/project/livesync/) and hosted
26
26
 
27
27
  [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview) and similar tools are great as long as your remote machine is powerful enough.
28
28
  But if your target is a Raspberry Pi, Jetson Nano/Xavier/Orin, Beagle Board or similar, it feels like coding in jelly.
29
- Especially if you run powerful extensions like Pylance.
29
+ Especially if you run powerful extensions like Pylance, GitHub Copilot or Duet AI.
30
30
  LiveSync solves this by watching your code for changes and just copying the modifications to the slow remote machine.
31
+ So you can develop on your own machine (and run tests there in the background) while all your changes appear also on the remote.
31
32
  It works best if you have some kind of reload mechanism in place on the target ([NiceGUI](https://nicegui.io), [FastAPI](https://fastapi.tiangolo.com/) or [Flask](https://flask.palletsprojects.com/) for example).
32
33
 
33
34
  ## Usage
@@ -59,10 +60,12 @@ Options:
59
60
  command to be executed on remote host after any file change (default: None)
60
61
  - `--mutex-interval MUTEX_INTERVAL`
61
62
  interval in which mutex is updated (default: 10 seconds)
63
+ - `--ignore-mutex`
64
+ ignore mutex (use with caution) (default: False)
62
65
 
63
66
  ### Python
64
67
 
65
- Simple example:
68
+ Simple example (where `robot` is the ssh hostname of the target system):
66
69
 
67
70
  ```py
68
71
  from livesync import Folder, sync
@@ -73,14 +76,25 @@ sync(
73
76
  )
74
77
  ```
75
78
 
79
+ The `sync` call will block until the script is aborted.
80
+ The `Folder` class allows to set the `port` and an `on_change` bash command which is executed after a sync has been performed.
81
+ Via the `rsync_args` build method you can pass additional options to configure rsync.
82
+
76
83
  Advanced example:
77
84
 
78
85
  ```py
86
+ import argparse
79
87
  from livesync import Folder, sync
80
88
 
89
+ parser = argparse.ArgumentParser(description='Sync local code with robot.')
90
+ parser.add_argument('robot', help='Robot hostname')
91
+
92
+ args = parser.parse_args()
93
+
94
+ touch = 'touch ~/robot/main.py'
81
95
  sync(
82
- Folder('.', 'robot:~/navigation', on_change='touch ~/navigation/main.py'),
83
- Folder('../rosys', 'robot:~/rosys', ssh_port=2222).rsync_args(add='-L', remove='--checksum'),
96
+ Folder('.', f'{args.robot}:~/navigation', on_change='touch ~/navigation/main.py'),
97
+ Folder('../rosys', f'{args.robot}:~/rosys').rsync_args(add='-L', remove='--checksum'),
84
98
  mutex_interval=30,
85
99
  )
86
100
  ```
@@ -13,8 +13,9 @@ It is available as [PyPI package](https://pypi.org/project/livesync/) and hosted
13
13
 
14
14
  [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview) and similar tools are great as long as your remote machine is powerful enough.
15
15
  But if your target is a Raspberry Pi, Jetson Nano/Xavier/Orin, Beagle Board or similar, it feels like coding in jelly.
16
- Especially if you run powerful extensions like Pylance.
16
+ Especially if you run powerful extensions like Pylance, GitHub Copilot or Duet AI.
17
17
  LiveSync solves this by watching your code for changes and just copying the modifications to the slow remote machine.
18
+ So you can develop on your own machine (and run tests there in the background) while all your changes appear also on the remote.
18
19
  It works best if you have some kind of reload mechanism in place on the target ([NiceGUI](https://nicegui.io), [FastAPI](https://fastapi.tiangolo.com/) or [Flask](https://flask.palletsprojects.com/) for example).
19
20
 
20
21
  ## Usage
@@ -46,10 +47,12 @@ Options:
46
47
  command to be executed on remote host after any file change (default: None)
47
48
  - `--mutex-interval MUTEX_INTERVAL`
48
49
  interval in which mutex is updated (default: 10 seconds)
50
+ - `--ignore-mutex`
51
+ ignore mutex (use with caution) (default: False)
49
52
 
50
53
  ### Python
51
54
 
52
- Simple example:
55
+ Simple example (where `robot` is the ssh hostname of the target system):
53
56
 
54
57
  ```py
55
58
  from livesync import Folder, sync
@@ -60,14 +63,25 @@ sync(
60
63
  )
61
64
  ```
62
65
 
66
+ The `sync` call will block until the script is aborted.
67
+ The `Folder` class allows to set the `port` and an `on_change` bash command which is executed after a sync has been performed.
68
+ Via the `rsync_args` build method you can pass additional options to configure rsync.
69
+
63
70
  Advanced example:
64
71
 
65
72
  ```py
73
+ import argparse
66
74
  from livesync import Folder, sync
67
75
 
76
+ parser = argparse.ArgumentParser(description='Sync local code with robot.')
77
+ parser.add_argument('robot', help='Robot hostname')
78
+
79
+ args = parser.parse_args()
80
+
81
+ touch = 'touch ~/robot/main.py'
68
82
  sync(
69
- Folder('.', 'robot:~/navigation', on_change='touch ~/navigation/main.py'),
70
- Folder('../rosys', 'robot:~/rosys', ssh_port=2222).rsync_args(add='-L', remove='--checksum'),
83
+ Folder('.', f'{args.robot}:~/navigation', on_change='touch ~/navigation/main.py'),
84
+ Folder('../rosys', f'{args.robot}:~/rosys').rsync_args(add='-L', remove='--checksum'),
71
85
  mutex_interval=30,
72
86
  )
73
87
  ```
@@ -59,15 +59,13 @@ class Folder:
59
59
 
60
60
  def get_summary(self) -> str:
61
61
  summary = f'{self.source_path} --> {self.target}\n'
62
- if not (self.source_path / '.git').exists():
63
- return summary
64
62
  try:
65
63
  cmd = ['git', 'log', '--pretty=format:[%h]\n', '-n', '1']
66
64
  summary += subprocess.check_output(cmd, cwd=self.source_path).decode()
67
65
  cmd = ['git', 'status', '--short', '--branch']
68
66
  summary += subprocess.check_output(cmd, cwd=self.source_path).decode().strip() + '\n'
69
67
  except Exception:
70
- pass # maybe git is not installed
68
+ pass # not a git repo, git is not installed, or something else
71
69
  return summary
72
70
 
73
71
  async def watch(self) -> None:
@@ -86,7 +84,7 @@ class Folder:
86
84
  args += ''.join(f' --exclude="{e}"' for e in self._get_ignores())
87
85
  args += f' -e "ssh -p {self.ssh_port}"' # NOTE: use SSH with custom port
88
86
  args += f' --rsync-path="mkdir -p {self.target_path} && rsync"' # NOTE: create target folder if not exists
89
- run_subprocess(f'rsync {args} {self.source_path}/ {self.target}/', quiet=True)
87
+ run_subprocess(f'rsync {args} "{self.source_path}/" "{self.target}/"', quiet=True)
90
88
  if isinstance(self.on_change, str):
91
89
  run_subprocess(f'ssh {self.host} -p {self.ssh_port} "cd {self.target_path}; {self.on_change}"')
92
90
  if callable(self.on_change):
@@ -13,12 +13,13 @@ def main():
13
13
  parser.add_argument('--ssh-port', type=int, default=22, help='SSH port on target')
14
14
  parser.add_argument('--on-change', type=str, help='command to be executed on remote host after any file change')
15
15
  parser.add_argument('--mutex-interval', type=int, default=10, help='interval in which mutex is updated')
16
+ parser.add_argument('--ignore-mutex', action='store_true', help='ignore mutex (use with caution)')
16
17
  parser.add_argument('rsync_args', nargs=argparse.REMAINDER, help='arbitrary rsync parameters after "--"')
17
18
  args = parser.parse_args()
18
19
 
19
20
  folder = Folder(args.source, args.target, ssh_port=args.ssh_port, on_change=args.on_change)
20
21
  folder.rsync_args(' '.join(args.rsync_args))
21
- sync(folder, mutex_interval=args.mutex_interval)
22
+ sync(folder, mutex_interval=args.mutex_interval, ignore_mutex=args.ignore_mutex)
22
23
 
23
24
 
24
25
  if __name__ == '__main__':
@@ -10,15 +10,16 @@ def get_summary(folders: Iterable[Folder]) -> str:
10
10
  return '\n'.join(folder.get_summary() for folder in folders).replace('"', '\'')
11
11
 
12
12
 
13
- async def run_folder_tasks(folders: Iterable[Folder], mutex_interval: float) -> None:
13
+ async def run_folder_tasks(folders: Iterable[Folder], mutex_interval: float, ignore_mutex: bool = False) -> None:
14
14
  try:
15
- summary = get_summary(folders)
16
- mutexes = {folder.host: Mutex(folder.host, folder.ssh_port) for folder in folders}
17
- for mutex in mutexes.values():
18
- print(f'Checking mutex on {mutex.host}', flush=True)
19
- if not mutex.set(summary):
20
- print(f'Target is in use by {mutex.occupant}')
21
- sys.exit(1)
15
+ if not ignore_mutex:
16
+ summary = get_summary(folders)
17
+ mutexes = {folder.host: Mutex(folder.host, folder.ssh_port) for folder in folders}
18
+ for mutex in mutexes.values():
19
+ print(f'Checking mutex on {mutex.host}', flush=True)
20
+ if not mutex.set(summary):
21
+ print(f'Target is in use by {mutex.occupant}')
22
+ sys.exit(1)
22
23
 
23
24
  for folder in folders:
24
25
  print(f' {folder.source_path} --> {folder.target}', flush=True)
@@ -29,17 +30,18 @@ async def run_folder_tasks(folders: Iterable[Folder], mutex_interval: float) ->
29
30
  asyncio.create_task(folder.watch())
30
31
 
31
32
  while True:
32
- summary = get_summary(folders)
33
- for mutex in mutexes.values():
34
- if not mutex.set(summary):
35
- break
33
+ if not ignore_mutex:
34
+ summary = get_summary(folders)
35
+ for mutex in mutexes.values():
36
+ if not mutex.set(summary):
37
+ break
36
38
  await asyncio.sleep(mutex_interval)
37
39
  except Exception as e:
38
40
  print(e)
39
41
 
40
42
 
41
- def sync(*folders: Folder, mutex_interval: float = 10) -> None:
43
+ def sync(*folders: Folder, mutex_interval: float = 10, ignore_mutex: bool = False) -> None:
42
44
  try:
43
- asyncio.run(run_folder_tasks(folders, mutex_interval))
45
+ asyncio.run(run_folder_tasks(folders, mutex_interval, ignore_mutex=ignore_mutex))
44
46
  except KeyboardInterrupt:
45
47
  print('Bye!')
File without changes
File without changes
File without changes
File without changes
File without changes