Skip to main content

PyPI version Python package Coverage Status Checked with mypy

Callscript

Not worth it to refactor your script into a bunch of functions? This is a simple python library that lets you run your script as though you had, so you can call results = callscript('myscript.py', x=3, y=4). Just add comments in your scirpt to show where the inputs and outputs are, and callscript will make the function work properly:

# myscript.py
x = 1      # input
y = 2      # input
w = x * y
v = x / y  # output
z = x + y  # output
print(z)   # ignore

Why does this exist? Because sometimes you don't want to touch your old code or want to keep working with it using an interactive coding tool like Spyder, VSCode's interactive mode, or Jupyter, but you still want to be able to test your script using new parameters, or wrap it with a user interface.

Or maybe you're not sure how to go about changing the script's code to make it work in a new context and don't have a lot of time at the moment to work it out, or maybe you're collaborating with someone who isn't ready to refactor the script yet.

In any case, with callscript, you can leave the original script alone and wrap it with your new functionality.

Installation

Install callscript with PyPI

  pip install callscript

Usage / Examples

Simple Input-Output Labeling

If you label your script with the "input" or "output" comments, callscript can call it!

# examples/script.py
x = 3  # input
y = 5  # input
z = x + y  # output

Then from your other code, you can call it with the callscript() function:

>>> from callscript import callscript
>>> callscript('examples/script.py', x=10, y=20)
{'z': 30}

Modifying Input-Output Variable Names for your Function's API

Want to change your variable names? You can do that, too!

# examples/script2.py
x = 3  # input:FirstWeek
y = 5  # input:SecondWeek
z = x + y  # output:sum
>>> callscript('examples/script2.py', FirstWeek=10, SecondWeek=20)
{'sum': 30}

Ignoring Lines When the Script is Called as a Function

Want some lines to be ignored when being called by callscript()? Use the # ignore tag!

# examples/script3.py
x = 3  # input
y = 5  # input
input('What is your name?')  # ignore
z = x + y  # output
z = 100000   # ignore
>>> callscript('examples/script3.py', x=10, y=20)
{'z': 30}

Using the Orignal Script Values as Function Defaults

callscript() will automatically use the original values of the inputs in the script as defaults.

# examples/script4.py
name = 'Nick'          # input
greeting = 'Hello, '   # input
msg = greeting + name  # output
>>> callscript('examples/script4.py', name='Emma')
{'msg': 'Hello, Emma'}

Authors

Running Tests

To run tests, run the following command

  tox

Contributing

Adding to the Changelog

Don't modify the CHANGELOG.rst file directly! Instead, usescriv create make a new entry for the changelog. After you've written a contribution, add the entry and write what you did into the template. When we are ready to make a release, we'll use the scriv collect command to aggregate these fragments into a new changeelog entry.

Metadata

Release files for callscript 0.7.2

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

Source distribution (sdist)

Source distribution for callscript 0.7.2
File Size Uploaded
callscript-0.7.2.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for callscript 0.7.2
File Interpreter ABI Platform
callscript-0.7.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / callscript-0.7.2.tar.gz

Download URL callscript-0.7.2.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
38fd4aff88121a902935b362d8680f985cce5a968f509b36b510232be8a81c99
BLAKE2b-256 checksum
How to use checksums
b71808edabecb948f1c5fff294bc625932323893882ec8d4ed9a991131ba53b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / callscript-0.7.2-py3-none-any.whl

Download URL callscript-0.7.2-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22e5e173d3fb067685dfd2fefbde6b6b7172f0a4daa3d44f7145ebf2c4c9922f
BLAKE2b-256 checksum
How to use checksums
f63a38a7bc72ccc470ed997c5f7f28c7c9358288133a48210ab9dc3efc48dc8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.7.2 This release

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.24

2 release files

0.6.23

2 release files

0.6.22

2 release files

0.6.21

2 release files

0.6.20

2 release files

0.6.19

2 release files

0.6.11

2 release files

0.6.10

2 release files

0.6.9

2 release files

0.6.1

2 release files

0.6

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

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