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.2.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.2-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.2.tar.gz.

File metadata

  • Download URL: cg_atv2_python_insert-1!1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 8de02644fe8ab7c6c20da4b8df5b5a8846b5440d21e7984c9230b78adb53d0ef
MD5 1024fd0ae61ad6f2b927931b908dd545
BLAKE2b-256 801425784ed0eafe0f28b41a5cf5975208767c801caa85a54202253cb7c2cc01

See more details on using hashes here.

Provenance

The following attestation bundles were made for cg_atv2_python_insert-1!1.0.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for cg_atv2_python_insert-1!1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 74bbaf3cae52a7e3dd77e0ae400b3d8c6b97bd84c59d313e13746e0dc334b24c
MD5 47eeae9c792e8b78ccdd519855d3c9fa
BLAKE2b-256 425ac64aa719d0c0f43ea01dbf185432655cc8ff8bcf15fa0839865ecbd25804

See more details on using hashes here.

Provenance

The following attestation bundles were made for cg_atv2_python_insert-1!1.0.2-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