Cogapp, currently at version 3.6.0, is a content generator that executes Python snippets embedded within source files (like Python, C, HTML, or plain text) to produce updated output. It helps keep documentation, code examples, and derived content in sync with their source, primarily operating as a command-line tool. Releases are generally stable, with new versions addressing bug fixes and minor enhancements.
pip install cogappVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use cogapp to generate content within a file. It creates a sample file with a `[[[cog ... ]]]` block, runs cogapp in-place using `python -m cogapp`, and then prints the updated file content. The subprocess call ensures cogapp is run robustly even if the `cog` executable is not directly in PATH.
If calling `cogapp.main()` programmatically, pass command-line arguments as a list of strings directly, e.g., `main(['-r', 'my_file.txt'])` instead of `main(argv=['-r', 'my_file.txt'])`.
To write output to a new file, use `-o <output_file.txt>`. To modify the input file in-place, use the `-r` (replace) flag, e.g., `cog -r my_file.txt`.
Always ensure `[[[cog` blocks are properly closed with `[[[end]]]`. Check for valid Python syntax inside the blocks. Use `cog -v` (verbose) for more detailed output during processing if debugging issues.
First, ensure `pip install cogapp` was successful. If the problem persists, run `python -m cogapp ...` instead of `cog ...` to explicitly invoke the module.
Pass command-line arguments as a list of strings directly to the `main()` function, for example: `from cogapp.cogapp import main; main(['-r', 'my_file.txt'])`.
Verify that the file path and name provided to `cog` are correct and the file exists. Use an absolute path or ensure you are running the command from the correct directory.
No dependency data recorded yet.