9201ef759e
Harness Compat / harness compat (push) Failing after 0s
CI / test on 3.12 (standard) (push) Has been cancelled
CI / test on 3.13 (standard) (push) Has been cancelled
CI / test on 3.14 (standard) (push) Has been cancelled
CI / test on 3.10 (all-extras) (push) Has been cancelled
CI / test on 3.11 (all-extras) (push) Has been cancelled
CI / test on 3.12 (all-extras) (push) Has been cancelled
CI / test on 3.14 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.10 (pydantic-evals) (push) Has been cancelled
CI / test on 3.11 (pydantic-evals) (push) Has been cancelled
CI / test on 3.12 (pydantic-evals) (push) Has been cancelled
CI / deploy-docs-preview (push) Has been cancelled
CI / build release artifacts (push) Has been cancelled
CI / publish to PyPI (push) Has been cancelled
CI / Send tweet (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / mypy (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / test on 3.10 (standard) (push) Has been cancelled
CI / test on 3.11 (standard) (push) Has been cancelled
CI / test on 3.13 (all-extras) (push) Has been cancelled
CI / test on 3.14 (all-extras) (push) Has been cancelled
CI / test on 3.10 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.11 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.12 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-evals) (push) Has been cancelled
CI / test on 3.14 (pydantic-evals) (push) Has been cancelled
CI / test on 3.10 (lowest-versions) (push) Has been cancelled
CI / test on 3.11 (lowest-versions) (push) Has been cancelled
CI / test on 3.12 (lowest-versions) (push) Has been cancelled
CI / test on 3.13 (lowest-versions) (push) Has been cancelled
CI / test on 3.14 (lowest-versions) (push) Has been cancelled
CI / test examples on 3.11 (push) Has been cancelled
CI / test examples on 3.12 (push) Has been cancelled
CI / test examples on 3.13 (push) Has been cancelled
CI / test examples on 3.14 (push) Has been cancelled
CI / coverage (push) Has been cancelled
CI / check (push) Has been cancelled
CI / deploy-docs (push) Has been cancelled
68 lines
1.6 KiB
Python
68 lines
1.6 KiB
Python
"""Very simply CLI to aid in copying examples code to a new directory.
|
|
|
|
To run examples in place, run:
|
|
|
|
uv run -m pydantic_ai_examples.<example_module_name>
|
|
|
|
For examples:
|
|
|
|
uv run -m pydantic_ai_examples.pydantic_model
|
|
|
|
To copy all examples to a new directory, run:
|
|
|
|
uv run -m pydantic_ai_examples --copy-to <destination_path>
|
|
|
|
See https://ai.pydantic.dev/examples/ for more information.
|
|
"""
|
|
|
|
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def cli():
|
|
this_dir = Path(__file__).parent
|
|
|
|
parser = argparse.ArgumentParser(
|
|
prog='pydantic_ai_examples',
|
|
description=__doc__,
|
|
formatter_class=argparse.RawTextHelpFormatter,
|
|
)
|
|
parser.add_argument(
|
|
'-v', '--version', action='store_true', help='show the version and exit'
|
|
)
|
|
parser.add_argument(
|
|
'--copy-to', dest='DEST', help='Copy all examples to a new directory'
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
if args.version:
|
|
from pydantic_ai import __version__
|
|
|
|
print(f'pydantic_ai v{__version__}')
|
|
elif args.DEST:
|
|
copy_to(this_dir, Path(args.DEST))
|
|
else:
|
|
parser.print_help()
|
|
|
|
|
|
def copy_to(this_dir: Path, dst: Path):
|
|
if dst.exists():
|
|
print(f'Error: destination path "{dst}" already exists', file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
dst.mkdir(parents=True)
|
|
|
|
count = 0
|
|
for file in this_dir.glob('*.*'):
|
|
with open(file, 'rb') as src_file:
|
|
with open(dst / file.name, 'wb') as dst_file:
|
|
dst_file.write(src_file.read())
|
|
count += 1
|
|
|
|
print(f'Copied {count} example files to "{dst}"')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
cli()
|