Skip to main content

snip_copy

snip_copy creates copies of a file, snipping away portions of the original.

Our motivating use-case is to allow instructors to manage only a rubric.py copy of their assignment which contains student instructions, solutions to all problems and, grading criteria to be shared with TAs. Using snip_copy one can quickly create solution.py and student.py versions of the same assignment from rubric.py.

Installation

pip install snip_copy

Quick-start

Consider an example input file input.txt:

this text will be left unmodified in all copies

#! snip: a, b
this text will be removed in copies a and b
#! snip-end

this text will (also) be left unmodified in all copies

Running snip_copy as:

    $ python3 -m snip_copy input.txt

generates two files, a.txt and b.txt where each has removed the snipped section.

Keeping only a selection

keep is the complement of snip: a copy named by any keep command contains only the text inside its keep blocks.

this text is left out of copy sol

#! keep: sol
this text appears in copy sol
#! snip: stud
so does this, though copy stud snips it
#! snip-end
#! keep-end

A keep block may overlap a snip block, but not another keep block. As with snip, a keep without a keep-end runs to the end of the text (or the end of the notebook cell).

Output file type

A copy name with a suffix sets the output file's name and type. With --split '_', #! keep: sol.py in hw_rub.ipynb writes hw_sol.py: the copy's code cells, separated by blank lines, with any markdown cells as comments. Combined with keep, this collects a notebook's solutions into a separate script. Link to it from a markdown cell ([hw_sol.py](hw_sol.py)) so readers can open it with a click.

Jupyter Notebooks

You can add snip commands to jupyter notebook cells (code or markdown) to achieve similar behavior as well. For example, given input rubric.ipynb, running the following command:

    $ python3 -m snip_copy rubric.ipynb

generates solution.ipynb and student.ipynb.

Notes:

  • a copy is made for each item which appears in a comma separated list after any snip command in the entire document
  • snip commands are removed in all copies created
  • Each snip command line contains #!, which comments out the line, so it may live unobtrusively in python code. You can modify this string to produce similar behavior in another programming language:
    $ python3 -m snip_copy input.txt --cmd '// !'
  • It can be cumbersome to type the full names of every output file with every snip command. Consider using --split:
    $ python3 -m snip_copy hw_rub.txt --split '_'

which will "split" the input file name at the last occurrence of the given string. For example, if hw_rub.txt has the same contents as input.txt at the top, then the terminal command immediately above creates hw_a.txt and hw_b.txt.

  • cells which do not include any snip commands are left unmodified in all copies (except copies named by a keep command, which drop every cell without a keep block of their own)
  • if a cell's snip command would remove its entire contents, then we remove the cell entirely in the copy generated, rather than give a cell which is empty
  • You can call snip_copy from within jupyter via a code containing:
>>> #! snip: stud, sol
>>> !python3 -m snip_copy hw_rub.ipynb`

which will make copies, removing this cell from each copy.

Metadata

Release files for snip-copy 0.0.4

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

Source distribution (sdist)

Source distribution for snip-copy 0.0.4
File Size Uploaded Provenance Actions
snip_copy-0.0.4.tar.gz 48.0 kB Without provenance Details for snip_copy-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for snip-copy 0.0.4
File Interpreter ABI Platform Actions
snip_copy-0.0.4-py3-none-any.whl Python 3 none any Details for snip_copy-0.0.4-py3-none-any.whl

Total release size: 83.0 kB

Release files / snip_copy-0.0.4.tar.gz

Download URL snip_copy-0.0.4.tar.gz
Size 48.0 kB
Tags Source
SHA-256 checksum
How to use checksums
654193211f5cde1034f7010ddf0a2cff544acd3a6a8d7994a7746f63352b05c5
BLAKE2b-256 checksum
How to use checksums
037726d36570eeee8ed879366df916a6da648884c8d945b691fa5fc827671ea2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / snip_copy-0.0.4-py3-none-any.whl

Download URL snip_copy-0.0.4-py3-none-any.whl
Size 35.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c341345fde36f79972acdf911b8f438b402dba2dc95cec4791dabec332611696
BLAKE2b-256 checksum
How to use checksums
23eef2835e75a295a2566aeabaf5643ac78588b5a5049e1d4b4f25f099465ffa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Security for snip-copy 0.0.4

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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