Skip to main content

No project description provided

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cg_atv2_python_insert-1!1.0.3.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cg_atv2_python_insert-1!1.0.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file cg_atv2_python_insert-1!1.0.3.tar.gz.

File metadata

  • Download URL: cg_atv2_python_insert-1!1.0.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cg_atv2_python_insert-1!1.0.3.tar.gz
Algorithm Hash digest
SHA256 88caa43b68132dadcf8d8fded98c4caedc2ec55aa7bd57dbcf813894e8d603cd
MD5 e19fbd316fe7b271a55dbadc1dfd40a9
BLAKE2b-256 848fb2dd08c6d5c5be0771df7998fe22a2544bedb3aec08ab832fd2113529ef0

See more details on using hashes here.

Provenance

The following attestation bundles were made for cg_atv2_python_insert-1!1.0.3.tar.gz:

Publisher: production_build.yml on CodeGra-de/CodeGra.de

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cg_atv2_python_insert-1!1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for cg_atv2_python_insert-1!1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 118cbd8f157be690913103788010e2804fa55e04f87036bd85dbcdde2089e645
MD5 445d5bbd978d749b3548711f72df2b65
BLAKE2b-256 dbfa612cf87d2c42488f90b53610e4235eb7667db46037dc1d5424eef04e4249

See more details on using hashes here.

Provenance

The following attestation bundles were made for cg_atv2_python_insert-1!1.0.3-py3-none-any.whl:

Publisher: production_build.yml on CodeGra-de/CodeGra.de

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page