Skip to main content

cg_atv2_python_insert

This package provides functionality to parse a Python script, identify specific 'magic comments', and substitute these comments with code from other files. It's designed to be used in environments where code templates and supplementary files are involved, such as automated grading or code templating systems.

The script supports command-line interaction, allowing users to specify the file to be processed. It then reads through the specified Python script, looks for magic comments in the format # CG_INSERT filename, and replaces these comments with the contents of the referenced file, executing it as part of the script.

The file to be processed cannot contain any call to sys.exit(), quit(), exit(), os._exit() or any method that raises the SystemExit error. This will raise a ValueError if the filled in template is then run.

Usage:

Run the script from the command line with the filename as an argument.

  • ./example.py
foo = 4

# CG_INSERT other.py

print (foo+bar)
  • ./other.py
bar = 3

Running python -m cg_atv2_python_insert example.py results in the following file being generated

  • ./filled_example.py
foo = 4

try:
    exec(compile(open('other.py').read(), 'other.py', 'exec'), globals())
except SystemExit as e:
    raise ValueError("Call not allowed") from e

print (foo+bar)

If the filled template is then run, the result printed on screen will be 7

Module contains:

  • CLI To generate a python file where each magic comment is substituted by the correct exec call.

Limitation:

This module is not intended to handle complex substitutions or manage dependencies between inserted scripts. The magic comment needs to be placed at the top level, outside of any function or class.

Metadata

Release files for cg-atv2-python-insert 1!1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cg-atv2-python-insert 1!1.0.3
File Size Uploaded Provenance Actions
cg_atv2_python_insert-1!1.0.3.tar.gz 5.1 kB With provenance Details for cg_atv2_python_insert-1!1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cg-atv2-python-insert 1!1.0.3
File Interpreter ABI Platform Actions
cg_atv2_python_insert-1!1.0.3-py3-none-any.whl Python 3 none any Details for cg_atv2_python_insert-1!1.0.3-py3-none-any.whl

Total release size: 10.8 kB

Release files / cg_atv2_python_insert-1!1.0.3.tar.gz

Download URL cg_atv2_python_insert-1!1.0.3.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
88caa43b68132dadcf8d8fded98c4caedc2ec55aa7bd57dbcf813894e8d603cd
BLAKE2b-256 checksum
How to use checksums
848fb2dd08c6d5c5be0771df7998fe22a2544bedb3aec08ab832fd2113529ef0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 19, 2026.

Transparency log

Release files / cg_atv2_python_insert-1!1.0.3-py3-none-any.whl

Download URL cg_atv2_python_insert-1!1.0.3-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
118cbd8f157be690913103788010e2804fa55e04f87036bd85dbcdde2089e645
BLAKE2b-256 checksum
How to use checksums
dbfa612cf87d2c42488f90b53610e4235eb7667db46037dc1d5424eef04e4249
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 19, 2026.

Transparency log

Security for cg-atv2-python-insert 1!1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cg_atv2_python_insert-1!1.0.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page