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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88caa43b68132dadcf8d8fded98c4caedc2ec55aa7bd57dbcf813894e8d603cd
|
|
| MD5 |
e19fbd316fe7b271a55dbadc1dfd40a9
|
|
| BLAKE2b-256 |
848fb2dd08c6d5c5be0771df7998fe22a2544bedb3aec08ab832fd2113529ef0
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cg_atv2_python_insert-1!1.0.3.tar.gz -
Subject digest:
88caa43b68132dadcf8d8fded98c4caedc2ec55aa7bd57dbcf813894e8d603cd - Sigstore transparency entry: 834566532
- Sigstore integration time:
-
Permalink:
CodeGra-de/CodeGra.de@5ba70728af938b7dab06021ddd2a74895e0f9d33 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/CodeGra-de
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
production_build.yml@5ba70728af938b7dab06021ddd2a74895e0f9d33 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cg_atv2_python_insert-1!1.0.3-py3-none-any.whl.
File metadata
- Download URL: cg_atv2_python_insert-1!1.0.3-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
118cbd8f157be690913103788010e2804fa55e04f87036bd85dbcdde2089e645
|
|
| MD5 |
445d5bbd978d749b3548711f72df2b65
|
|
| BLAKE2b-256 |
dbfa612cf87d2c42488f90b53610e4235eb7667db46037dc1d5424eef04e4249
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cg_atv2_python_insert-1!1.0.3-py3-none-any.whl -
Subject digest:
118cbd8f157be690913103788010e2804fa55e04f87036bd85dbcdde2089e645 - Sigstore transparency entry: 834566667
- Sigstore integration time:
-
Permalink:
CodeGra-de/CodeGra.de@5ba70728af938b7dab06021ddd2a74895e0f9d33 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/CodeGra-de
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
production_build.yml@5ba70728af938b7dab06021ddd2a74895e0f9d33 -
Trigger Event:
push
-
Statement type: