from gravixlayer import GravixLayer
client = GravixLayer() # defaults to cloud="aws", region="us-east-1"
sandbox = client.runtime.create() # defaults to template="base-small"
sandbox.file.write("/workspace/app.py", "# TODO: retry\nfrom os import path\n")
sandbox.file.write("/workspace/config.yaml", "name: demo\n")
hits = sandbox.file.find("/workspace", pattern="TODO", glob="*.py")
for match in hits:
print(f"{match.path}:{match.line}: {match.content}")
# Name-only search: one result per file, line == 0
configs = sandbox.file.find("/workspace", glob="*.yaml")
print([m.path for m in configs])
# Regular expression search
imports = sandbox.file.find(
"/workspace",
pattern=r"^from\s+(\w+)\s+import",
glob="*.py",
regex=True,
)
print(imports.files_scanned, len(imports))
sandbox.kill()