itcpr 2.0.6__tar.gz → 2.0.7__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.4
2
2
  Name: itcpr
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: CLI tool for syncing GitHub repositories from ITCPR Cloud
5
5
  Home-page: https://itcpr.org
6
6
  Author: ITCPR
@@ -25,6 +25,8 @@ Provides-Extra: dev
25
25
  Requires-Dist: pytest; extra == "dev"
26
26
  Requires-Dist: black; extra == "dev"
27
27
  Requires-Dist: flake8; extra == "dev"
28
+ Provides-Extra: yaml
29
+ Requires-Dist: PyYAML>=6.0; extra == "yaml"
28
30
  Dynamic: author
29
31
  Dynamic: home-page
30
32
  Dynamic: license-file
@@ -218,6 +220,23 @@ Options:
218
220
  - `--watch, -w`: Run continuous sync loop
219
221
  - `--interval, -i`: Sync interval in seconds (watch mode only, default: 60)
220
222
 
223
+ **Sync Rules (itcpr.yml):**
224
+
225
+ You can configure per-repository sync behavior by creating an `itcpr.yml` file in the repository root:
226
+
227
+ ```yaml
228
+ sync:
229
+ enabled: true # Enable/disable sync for this repo (default: true)
230
+ auto_commit: true # Auto-commit local changes (default: true)
231
+ auto_push: true # Auto-push local commits (default: true)
232
+ branch: main # Optional: specific branch to sync
233
+ ignore: # Optional: patterns to ignore
234
+ - "*.log"
235
+ - "temp/"
236
+ ```
237
+
238
+ **Note:** To use `itcpr.yml`, install PyYAML: `pip install itcpr[yaml]` or `pip install PyYAML`
239
+
221
240
  ## How It Works
222
241
 
223
242
  ### Authentication
@@ -245,10 +264,46 @@ Options:
245
264
 
246
265
  ## Configuration
247
266
 
267
+ ### Global Configuration
268
+
248
269
  Configuration is stored in `~/.itcpr/config.toml`.
249
270
 
250
271
  Repository metadata is stored in `~/.itcpr/repos.db` (SQLite).
251
272
 
273
+ ### Per-Repository Configuration (itcpr.yml)
274
+
275
+ Each repository can have its own `itcpr.yml` file in the repository root to control sync behavior:
276
+
277
+ ```yaml
278
+ sync:
279
+ enabled: true # Enable/disable sync for this repo
280
+ auto_commit: true # Automatically commit local changes
281
+ auto_push: true # Automatically push local commits
282
+ branch: main # Optional: sync specific branch
283
+ ignore: [] # Optional: file patterns to ignore
284
+ ```
285
+
286
+ **Example: Disable auto-push for a repository**
287
+
288
+ ```yaml
289
+ sync:
290
+ auto_push: false
291
+ ```
292
+
293
+ **Example: Disable sync entirely for a repository**
294
+
295
+ ```yaml
296
+ sync:
297
+ enabled: false
298
+ ```
299
+
300
+ **Installation:** To use `itcpr.yml` files, install the optional YAML dependency:
301
+ ```bash
302
+ pip install itcpr[yaml]
303
+ # OR
304
+ pip install PyYAML
305
+ ```
306
+
252
307
  ## Troubleshooting
253
308
 
254
309
  ### "Not logged in" error
@@ -186,6 +186,23 @@ Options:
186
186
  - `--watch, -w`: Run continuous sync loop
187
187
  - `--interval, -i`: Sync interval in seconds (watch mode only, default: 60)
188
188
 
189
+ **Sync Rules (itcpr.yml):**
190
+
191
+ You can configure per-repository sync behavior by creating an `itcpr.yml` file in the repository root:
192
+
193
+ ```yaml
194
+ sync:
195
+ enabled: true # Enable/disable sync for this repo (default: true)
196
+ auto_commit: true # Auto-commit local changes (default: true)
197
+ auto_push: true # Auto-push local commits (default: true)
198
+ branch: main # Optional: specific branch to sync
199
+ ignore: # Optional: patterns to ignore
200
+ - "*.log"
201
+ - "temp/"
202
+ ```
203
+
204
+ **Note:** To use `itcpr.yml`, install PyYAML: `pip install itcpr[yaml]` or `pip install PyYAML`
205
+
189
206
  ## How It Works
190
207
 
191
208
  ### Authentication
@@ -213,10 +230,46 @@ Options:
213
230
 
214
231
  ## Configuration
215
232
 
233
+ ### Global Configuration
234
+
216
235
  Configuration is stored in `~/.itcpr/config.toml`.
217
236
 
218
237
  Repository metadata is stored in `~/.itcpr/repos.db` (SQLite).
219
238
 
239
+ ### Per-Repository Configuration (itcpr.yml)
240
+
241
+ Each repository can have its own `itcpr.yml` file in the repository root to control sync behavior:
242
+
243
+ ```yaml
244
+ sync:
245
+ enabled: true # Enable/disable sync for this repo
246
+ auto_commit: true # Automatically commit local changes
247
+ auto_push: true # Automatically push local commits
248
+ branch: main # Optional: sync specific branch
249
+ ignore: [] # Optional: file patterns to ignore
250
+ ```
251
+
252
+ **Example: Disable auto-push for a repository**
253
+
254
+ ```yaml
255
+ sync:
256
+ auto_push: false
257
+ ```
258
+
259
+ **Example: Disable sync entirely for a repository**
260
+
261
+ ```yaml
262
+ sync:
263
+ enabled: false
264
+ ```
265
+
266
+ **Installation:** To use `itcpr.yml` files, install the optional YAML dependency:
267
+ ```bash
268
+ pip install itcpr[yaml]
269
+ # OR
270
+ pip install PyYAML
271
+ ```
272
+
220
273
  ## Troubleshooting
221
274
 
222
275
  ### "Not logged in" error
@@ -1,4 +1,4 @@
1
1
  """ITCPR Agent - CLI tool for syncing GitHub repositories."""
2
2
 
3
- __version__ = "2.0.6"
3
+ __version__ = "2.0.7"
4
4
 
@@ -3,7 +3,7 @@
3
3
  import time
4
4
  import signal
5
5
  from pathlib import Path
6
- from typing import Optional, Dict, Any
6
+ from typing import Optional, Dict, Any, List
7
7
  from .gitops import GitOps
8
8
  from .api import APIClient
9
9
  from .storage import Storage
@@ -11,6 +11,44 @@ from .utils import get_logger, print_error, print_success, print_info
11
11
 
12
12
  logger = get_logger(__name__)
13
13
 
14
+ # Try to import yaml, but make it optional
15
+ try:
16
+ import yaml
17
+ YAML_AVAILABLE = True
18
+ except ImportError:
19
+ YAML_AVAILABLE = False
20
+ yaml = None
21
+
22
+ def load_sync_rules(repo_path: Path) -> Dict[str, Any]:
23
+ """Load sync rules from itcpr.yml in repository root."""
24
+ config_file = repo_path / "itcpr.yml"
25
+
26
+ if not config_file.exists():
27
+ return {}
28
+
29
+ if not YAML_AVAILABLE:
30
+ logger.warning("YAML not available. Install PyYAML to use itcpr.yml configuration.")
31
+ return {}
32
+
33
+ try:
34
+ with open(config_file, 'r', encoding='utf-8') as f:
35
+ config = yaml.safe_load(f)
36
+ if not isinstance(config, dict):
37
+ return {}
38
+
39
+ # Extract sync rules
40
+ sync_config = config.get('sync', {})
41
+ return {
42
+ 'enabled': sync_config.get('enabled', True),
43
+ 'auto_commit': sync_config.get('auto_commit', True),
44
+ 'auto_push': sync_config.get('auto_push', True),
45
+ 'branch': sync_config.get('branch'),
46
+ 'ignore_patterns': sync_config.get('ignore', []),
47
+ }
48
+ except Exception as e:
49
+ logger.warning(f"Failed to load itcpr.yml from {repo_path}: {e}")
50
+ return {}
51
+
14
52
  class SyncManager:
15
53
  """Manages repository synchronization."""
16
54
 
@@ -25,6 +63,18 @@ class SyncManager:
25
63
  logger.info(f"Syncing repository: {repo_name}")
26
64
 
27
65
  try:
66
+ # Load sync rules from itcpr.yml
67
+ rules = load_sync_rules(repo_path)
68
+
69
+ # Check if sync is disabled for this repo
70
+ if not rules.get('enabled', True):
71
+ logger.info(f"Sync disabled for {repo_name} (itcpr.yml)")
72
+ return {
73
+ "success": True,
74
+ "skipped": True,
75
+ "message": "Sync disabled in itcpr.yml"
76
+ }
77
+
28
78
  git = GitOps(repo_path)
29
79
 
30
80
  if not git.is_repo():
@@ -33,19 +83,33 @@ class SyncManager:
33
83
  "error": f"Not a git repository: {repo_path}"
34
84
  }
35
85
 
86
+ # Check if we need to switch branch
87
+ if rules.get('branch'):
88
+ current_branch = git.get_current_branch()
89
+ if current_branch != rules['branch']:
90
+ logger.info(f"Switching to branch {rules['branch']} for {repo_name}")
91
+ # Note: Branch switching would need to be implemented in GitOps if needed
92
+
36
93
  # Check status
37
94
  status = git.get_status()
38
95
  if not status.get("clean"):
39
96
  if status.get("has_changes"):
40
- print_info(f" Uncommitted changes detected in {repo_name}")
41
- # Commit local changes
42
- try:
43
- git.commit_if_changes()
44
- print_success(f" Committed local changes")
45
- except Exception as e:
97
+ # Check if auto_commit is enabled (default: True)
98
+ if rules.get('auto_commit', True):
99
+ print_info(f" Uncommitted changes detected in {repo_name}")
100
+ # Commit local changes
101
+ try:
102
+ git.commit_if_changes()
103
+ print_success(f" Committed local changes")
104
+ except Exception as e:
105
+ return {
106
+ "success": False,
107
+ "error": f"Failed to commit changes: {e}"
108
+ }
109
+ else:
46
110
  return {
47
111
  "success": False,
48
- "error": f"Failed to commit changes: {e}"
112
+ "error": "Uncommitted changes detected and auto_commit is disabled in itcpr.yml"
49
113
  }
50
114
 
51
115
  # Fetch latest
@@ -68,17 +132,21 @@ class SyncManager:
68
132
  }
69
133
  raise
70
134
 
71
- # Push if ahead
135
+ # Push if ahead (check auto_push rule)
72
136
  if status.get("ahead"):
73
- print_info(f" Pushing local commits...")
74
- try:
75
- git.push()
76
- print_success(f" Pushed local commits")
77
- except Exception as e:
78
- return {
79
- "success": False,
80
- "error": f"Failed to push: {e}"
81
- }
137
+ if rules.get('auto_push', True):
138
+ print_info(f" Pushing local commits...")
139
+ try:
140
+ git.push()
141
+ print_success(f" Pushed local commits")
142
+ except Exception as e:
143
+ return {
144
+ "success": False,
145
+ "error": f"Failed to push: {e}"
146
+ }
147
+ else:
148
+ logger.info(f"Push skipped for {repo_name} (auto_push disabled in itcpr.yml)")
149
+ print_info(f" Local commits not pushed (auto_push disabled)")
82
150
 
83
151
  # Update sync time
84
152
  self.storage.update_sync_time(repo_name)
@@ -96,17 +164,18 @@ class SyncManager:
96
164
  }
97
165
 
98
166
  def sync_all(self) -> Dict[str, Any]:
99
- """Sync all tracked repositories."""
167
+ """Sync all tracked repositories, respecting itcpr.yml rules."""
100
168
  repos = self.storage.list_repos()
101
169
 
102
170
  if not repos:
103
171
  print_info("No repositories to sync")
104
- return {"success": True, "synced": 0, "failed": 0}
172
+ return {"success": True, "synced": 0, "failed": 0, "skipped": 0}
105
173
 
106
174
  print_info(f"Syncing {len(repos)} repositories...")
107
175
 
108
176
  synced = 0
109
177
  failed = 0
178
+ skipped = 0
110
179
 
111
180
  for repo in repos:
112
181
  repo_path = Path(repo["local_path"])
@@ -117,17 +186,21 @@ class SyncManager:
117
186
 
118
187
  result = self.sync_repo(repo["name"], repo_path)
119
188
  if result.get("success"):
120
- synced += 1
189
+ if result.get("skipped"):
190
+ skipped += 1
191
+ else:
192
+ synced += 1
121
193
  else:
122
194
  failed += 1
123
195
  if result.get("error"):
124
196
  print_error(f" {result['error']}")
125
197
 
126
- print_info(f"\nSync complete: {synced} succeeded, {failed} failed")
198
+ print_info(f"\nSync complete: {synced} succeeded, {failed} failed, {skipped} skipped")
127
199
  return {
128
200
  "success": failed == 0,
129
201
  "synced": synced,
130
- "failed": failed
202
+ "failed": failed,
203
+ "skipped": skipped
131
204
  }
132
205
 
133
206
  def watch(self, interval: int = 60):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: itcpr
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: CLI tool for syncing GitHub repositories from ITCPR Cloud
5
5
  Home-page: https://itcpr.org
6
6
  Author: ITCPR
@@ -25,6 +25,8 @@ Provides-Extra: dev
25
25
  Requires-Dist: pytest; extra == "dev"
26
26
  Requires-Dist: black; extra == "dev"
27
27
  Requires-Dist: flake8; extra == "dev"
28
+ Provides-Extra: yaml
29
+ Requires-Dist: PyYAML>=6.0; extra == "yaml"
28
30
  Dynamic: author
29
31
  Dynamic: home-page
30
32
  Dynamic: license-file
@@ -218,6 +220,23 @@ Options:
218
220
  - `--watch, -w`: Run continuous sync loop
219
221
  - `--interval, -i`: Sync interval in seconds (watch mode only, default: 60)
220
222
 
223
+ **Sync Rules (itcpr.yml):**
224
+
225
+ You can configure per-repository sync behavior by creating an `itcpr.yml` file in the repository root:
226
+
227
+ ```yaml
228
+ sync:
229
+ enabled: true # Enable/disable sync for this repo (default: true)
230
+ auto_commit: true # Auto-commit local changes (default: true)
231
+ auto_push: true # Auto-push local commits (default: true)
232
+ branch: main # Optional: specific branch to sync
233
+ ignore: # Optional: patterns to ignore
234
+ - "*.log"
235
+ - "temp/"
236
+ ```
237
+
238
+ **Note:** To use `itcpr.yml`, install PyYAML: `pip install itcpr[yaml]` or `pip install PyYAML`
239
+
221
240
  ## How It Works
222
241
 
223
242
  ### Authentication
@@ -245,10 +264,46 @@ Options:
245
264
 
246
265
  ## Configuration
247
266
 
267
+ ### Global Configuration
268
+
248
269
  Configuration is stored in `~/.itcpr/config.toml`.
249
270
 
250
271
  Repository metadata is stored in `~/.itcpr/repos.db` (SQLite).
251
272
 
273
+ ### Per-Repository Configuration (itcpr.yml)
274
+
275
+ Each repository can have its own `itcpr.yml` file in the repository root to control sync behavior:
276
+
277
+ ```yaml
278
+ sync:
279
+ enabled: true # Enable/disable sync for this repo
280
+ auto_commit: true # Automatically commit local changes
281
+ auto_push: true # Automatically push local commits
282
+ branch: main # Optional: sync specific branch
283
+ ignore: [] # Optional: file patterns to ignore
284
+ ```
285
+
286
+ **Example: Disable auto-push for a repository**
287
+
288
+ ```yaml
289
+ sync:
290
+ auto_push: false
291
+ ```
292
+
293
+ **Example: Disable sync entirely for a repository**
294
+
295
+ ```yaml
296
+ sync:
297
+ enabled: false
298
+ ```
299
+
300
+ **Installation:** To use `itcpr.yml` files, install the optional YAML dependency:
301
+ ```bash
302
+ pip install itcpr[yaml]
303
+ # OR
304
+ pip install PyYAML
305
+ ```
306
+
252
307
  ## Troubleshooting
253
308
 
254
309
  ### "Not logged in" error
@@ -7,3 +7,6 @@ tomli-w>=1.0.0
7
7
  pytest
8
8
  black
9
9
  flake8
10
+
11
+ [yaml]
12
+ PyYAML>=6.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "itcpr"
7
- version = "2.0.6"
7
+ version = "2.0.7"
8
8
  description = "CLI tool for syncing GitHub repositories from ITCPR Cloud"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -34,6 +34,7 @@ itcpr = "itcpr.cli:main"
34
34
 
35
35
  [project.optional-dependencies]
36
36
  dev = ["pytest", "black", "flake8"]
37
+ yaml = ["PyYAML>=6.0"] # For itcpr.yml support
37
38
 
38
39
  [tool.setuptools]
39
40
  packages = ["itcpr"]
@@ -9,7 +9,7 @@ long_description = readme_file.read_text() if readme_file.exists() else ""
9
9
 
10
10
  setup(
11
11
  name="itcpr",
12
- version="2.0.6",
12
+ version="2.0.7",
13
13
  description="CLI tool for syncing GitHub repositories from ITCPR Cloud",
14
14
  long_description=long_description,
15
15
  long_description_content_type="text/markdown",
@@ -24,9 +24,10 @@ setup(
24
24
  "keyring>=23.0.0",
25
25
  "tomli-w>=1.0.0",
26
26
  ],
27
- # Optional dependency for Python < 3.11
27
+ # Optional dependencies
28
28
  extras_require={
29
29
  "dev": ["pytest", "black", "flake8"],
30
+ "yaml": ["PyYAML>=6.0"], # For itcpr.yml support
30
31
  },
31
32
  entry_points={
32
33
  "console_scripts": [
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes