1.7 KiB
1.7 KiB
applyTo
| applyTo |
|---|
| *.py |
- Do not be chatty, do not summarize the code afterwards.
- Use
#!/usr/bin/env -S uv run --scriptas the shebang line. - Add dependencies under the shebang line as
# /// script
# dependencies = [list of external dependencies as json array]
# ///
and keep them updated as the code changes.
- Keep comments to minimum
- Use
uvfor package management. - Use logging instead of print statements. Use
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s: %(message)s")for configuration. - Use argparse for command-line arguments, keep argument parsing in a func called
parse_args() -> argparse.Namespace, which gets called frommain. Useargparse.ArgumentDefaultsHelpFormatterfor the formatter class. - Use
pathlib.Pathfor file operations. When the CLI args include a path, set itstype=Path - Place imports at the top of the file.
- Use httpx for HTTP requests. Do not use async.
- Always add type annotations to function signatures, prefer built-in types, e.g.
list[str]overtypingmodule types when possible. - Prefer kwargs calling style for function calls, e.g.
func(arg1=value1, arg2=value2)instead offunc(value1, value2). - Use
Path.cwd()for the current working directory. - Prefer
os.getenvoveros.environ.getfor environment variables. - Use
subprocess.runfor running shell commands, prefercheck=Trueto raise an error on failure. - Use
tempfile.TemporaryDirectory()for temporary directories. - Do not shorten parameter names unnecessarily, unless it's an idiomatic abbreviation.
- Use f-strings for string formatting.
- When calling an external command, use the long form of the arguments, e.g.
--outputinstead of-o.