-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
425 lines (312 loc) Β· 10.4 KB
/
Copy pathtasks.py
File metadata and controls
425 lines (312 loc) Β· 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
"""
Invoke tasks for DevSync development.
Install invoke: pip install invoke
Usage: invoke <task-name>
List all tasks: invoke --list
"""
import sys
from pathlib import Path
from invoke import task
# Project paths
ROOT = Path(__file__).parent
SRC = ROOT / "devsync"
TESTS = ROOT / "tests"
# Check if pty is available (not available on Windows)
PTY_SUPPORTED = sys.platform != "win32"
# ============================================================================
# Testing Tasks
# ============================================================================
@task
def test(c, verbose=False, coverage=False, marker=None):
"""
Run all tests.
Options:
-v, --verbose: Verbose output
-c, --coverage: Generate coverage report
-m, --marker: Run tests with specific marker (e.g., 'unit', 'integration')
"""
cmd = "pytest tests/"
if verbose:
cmd += " -vv"
else:
cmd += " -q"
if coverage:
cmd += " --cov=devsync --cov-report=term-missing --cov-report=xml --cov-report=html"
if marker:
cmd += f" -m {marker}"
c.run(cmd, pty=PTY_SUPPORTED)
@task
def test_unit(c, verbose=False):
"""Run unit tests only."""
cmd = "pytest tests/unit/"
if verbose:
cmd += " -vv"
else:
cmd += " -q"
c.run(cmd, pty=PTY_SUPPORTED)
@task
def test_integration(c, verbose=False):
"""Run integration tests only."""
cmd = "pytest tests/integration/"
if verbose:
cmd += " -vv"
else:
cmd += " -q"
c.run(cmd, pty=PTY_SUPPORTED)
@task
def test_watch(c):
"""Run tests in watch mode (requires pytest-watch)."""
c.run("ptw tests/ -- -q", pty=PTY_SUPPORTED)
@task
def coverage(c, html=True):
"""
Generate test coverage report.
Options:
--html: Generate HTML coverage report (default: True)
"""
cmd = "pytest tests/ --cov=devsync --cov-report=term-missing --cov-report=xml"
if html:
cmd += " --cov-report=html"
print("\nπ HTML coverage report: htmlcov/index.html")
print("π XML coverage report: coverage.xml")
c.run(cmd, pty=PTY_SUPPORTED)
# ============================================================================
# Code Quality Tasks
# ============================================================================
@task
def lint(c, fix=False):
"""
Run ruff linter.
Options:
-f, --fix: Automatically fix issues
"""
cmd = "ruff check devsync/ tests/"
if fix:
cmd += " --fix"
c.run(cmd, pty=PTY_SUPPORTED)
@task
def format(c, check=False):
"""
Format code with black.
Options:
-c, --check: Check formatting without making changes
"""
cmd = "black devsync/ tests/"
if check:
cmd += " --check"
c.run(cmd, pty=PTY_SUPPORTED)
@task
def typecheck(c):
"""Run mypy type checking."""
c.run("mypy devsync/", pty=PTY_SUPPORTED)
@task
def quality(c, fix=False):
"""
Run all code quality checks.
Options:
-f, --fix: Automatically fix issues where possible
"""
print("π Running linter...")
lint(c, fix=fix)
print("\nπ¨ Checking formatting...")
format(c, check=not fix)
print("\nπ Type checking...")
typecheck(c)
print("\nβ
Quality checks complete!")
# ============================================================================
# Build & Installation Tasks
# ============================================================================
@task
def clean(c):
"""Clean build artifacts and caches."""
patterns = [
"build/",
"dist/",
"*.egg-info/",
"__pycache__/",
"*.pyc",
"*.pyo",
".pytest_cache/",
".mypy_cache/",
".ruff_cache/",
"htmlcov/",
".coverage",
"*.log",
]
for pattern in patterns:
c.run(f"find . -type d -name '{pattern}' -exec rm -rf {{}} + 2>/dev/null || true")
c.run(f"find . -type f -name '{pattern}' -delete 2>/dev/null || true")
print("π§Ή Cleaned all build artifacts and caches")
@task(pre=[clean])
def build(c):
"""Build the package."""
c.run("python -m build", pty=PTY_SUPPORTED)
print("\nπ¦ Package built successfully!")
@task
def install(c, dev=False, editable=True):
"""
Install the package.
Options:
-d, --dev: Install with development dependencies
-e, --editable: Install in editable mode (default: True)
"""
if editable:
cmd = "pip install -e ."
else:
cmd = "pip install ."
if dev:
cmd += "[dev]"
c.run(cmd, pty=PTY_SUPPORTED)
print("β
Package installed successfully!")
@task
def uninstall(c):
"""Uninstall the package."""
c.run("pip uninstall -y devsync", pty=PTY_SUPPORTED)
print("β
Package uninstalled successfully!")
# ============================================================================
# Development Tasks
# ============================================================================
@task
def dev_setup(c):
"""Set up development environment."""
print("π§ Setting up development environment...")
print("\nπ¦ Installing package in editable mode with dev dependencies...")
c.run("pip install -e .[dev]", pty=PTY_SUPPORTED)
print("\nβ
Development environment ready!")
print("\nπ‘ Quick commands:")
print(" invoke test - Run all tests")
print(" invoke quality - Run code quality checks")
print(" invoke lint --fix - Auto-fix linting issues")
print(" invoke --list - See all available tasks")
@task
def repl(c):
"""Start Python REPL with devsync imported."""
c.run("python -i -c 'import devsync; print(\"DevSync imported\")'", pty=PTY_SUPPORTED)
# ============================================================================
# CLI Tasks
# ============================================================================
@task
def cli(c, args="--help"):
"""
Run the devsync CLI.
Usage: invoke cli --args="download --repo https://..."
"""
c.run(f"devsync {args}", pty=PTY_SUPPORTED)
@task
def list_tools(c):
"""List detected AI tools."""
c.run("devsync tools", pty=PTY_SUPPORTED)
@task
def list_library(c):
"""List instructions in library."""
c.run("devsync list library", pty=PTY_SUPPORTED)
# ============================================================================
# Documentation Tasks
# ============================================================================
@task
def docs_serve(c, port=8000):
"""
Serve documentation locally (if using MkDocs or similar).
Options:
-p, --port: Port to serve on (default: 8000)
"""
print(f"π Serving documentation on http://localhost:{port}")
# Placeholder - add when docs are set up
print("β οΈ Documentation server not yet configured")
# ============================================================================
# Release Tasks
# ============================================================================
@task
def version(c):
"""Show current version."""
result = c.run("grep 'version =' pyproject.toml | cut -d'\"' -f2", hide=True)
version = result.stdout.strip()
print(f"π Current version: {version}")
return version
@task(pre=[clean, quality, test])
def release_check(c):
"""
Run all checks before release.
Runs: clean, quality checks, and full test suite
"""
print("\nβ
All release checks passed!")
print("\nπ Next steps:")
print(" 1. Update version in pyproject.toml")
print(" 2. Update CHANGELOG")
print(" 3. Run: invoke build")
print(" 4. Run: git tag v<version>")
print(" 5. Run: git push --tags")
@task(pre=[build])
def publish(c, repository="pypi", skip_existing=True):
"""Publish the current build to PyPI using twine.
Options:
--repository: Target repository alias (default: "pypi")
--skip-existing: Skip packages that already exist on the server (default: True)
"""
dist_path = ROOT / "dist"
if not dist_path.exists() or not any(dist_path.iterdir()):
raise RuntimeError("No distributions found in dist/. Run 'invoke build' first.")
skip_flag = " --skip-existing" if skip_existing else ""
cmd = f"twine upload -r {repository}{skip_flag} dist/*"
c.run(cmd, pty=PTY_SUPPORTED)
print("\nπ Upload complete!")
print("π¦ Repository:", repository)
print("π Uploaded artifacts from:", dist_path)
# ============================================================================
# Utility Tasks
# ============================================================================
@task
def count(c):
"""Count lines of code."""
print("π Lines of Code:\n")
# Source code
result = c.run("find devsync -name '*.py' | xargs wc -l | tail -1", hide=True)
src_lines = result.stdout.strip().split()[0]
print(f" Source: {src_lines:>6} lines")
# Test code
result = c.run("find tests -name '*.py' | xargs wc -l | tail -1", hide=True)
test_lines = result.stdout.strip().split()[0]
print(f" Tests: {test_lines:>6} lines")
# Total
total = int(src_lines) + int(test_lines)
print(f" Total: {total:>6} lines")
@task
def tree(c, level=2):
"""
Show project structure.
Options:
-l, --level: Tree depth level (default: 2)
"""
ignore = "__pycache__|*.pyc|*.egg-info|htmlcov|.pytest_cache|.mypy_cache|.ruff_cache"
cmd = f"tree -L {level} -I '{ignore}'"
c.run(cmd, pty=PTY_SUPPORTED)
@task(name="security-check")
def security_check(c):
"""Run security checks with bandit and safety."""
print("π Running security checks...\n")
print("1. Checking for known vulnerabilities (safety)...")
c.run("pip install safety", hide=True)
c.run("safety check", warn=True)
print("\n2. Checking for security issues in code (bandit)...")
c.run("pip install bandit", hide=True)
c.run("bandit -r devsync/ -ll", warn=True)
print("\nβ
Security checks complete!")
# ============================================================================
# Aliases
# ============================================================================
@task
def t(c, verbose=False):
"""Alias for 'test'."""
test(c, verbose=verbose)
@task
def cov(c):
"""Alias for 'coverage'."""
coverage(c)
@task
def fmt(c, check=False):
"""Alias for 'format'."""
format(c, check=check)
@task
def check(c):
"""Alias for 'quality'."""
quality(c)