Code Monkey home page Code Monkey logo

pysnapshot's Introduction

PySnapShot

Keep code reproducible by taking SnapShots

Build PyPI version codecov Lines of code

This is a tiny helper package for saving code associated with an experiment, and reloading it at a later time. There are two main functions:

  1. pysnapshot.capture: Captures the code associated with a module into a snapshot at a given path.
  2. pysnapshot.load: Loads the code from the snapshot into a module of a specified name. If no name is given, then the module name is whatever the folder name is for the snapshot.

Installation

Install from PyPI:

python -m pip install pysnapshot

Usage

Let's say I'm working on the code in examples/hello_world.py. Let's save the current version (working in the examples/ directory):

import pysnapshot
import hello_world

# First let's take a snapshot of the 
# hello_world package.

path = pysnapshot.capture(hello_world, '/tmp/hello_world_snap/', overwrite=True)
hello_world_snap = pysnapshot.load(path)
print(hello_world_snap.__file__)

# The snapshot is loaded from the specified directory. The code was all copied to
# and is under the snapshot:

print("From original package code", hello_world.func1())
print("From snapshot", hello_world_snap.hello_world.func1())

# You can import from the snapshot as if it were a regular package

from hello_world_snap import hello_world
print("From snapshot, overwriting the original package code", hello_world.func1())

This has the output:

cd examples/
❯ python demo.py
/private/tmp/hello_world_snap/__init__.py
/Users/prem/research/snapshot/examples/hello_world/hello.py TEST
From original package code TEST
/private/tmp/hello_world_snap/hello_world/hello.py TEST
From snapshot TEST
/private/tmp/hello_world_snap/hello_world/hello.py TEST
From snapshot, overwriting the original package code TEST

And it created a Python module with this directory structure:

❯ tree '/tmp/hello_world_snap/'
/tmp/hello_world_snap/
├── __init__.py
└── hello_world
    ├── __init__.py
    ├── hello.py
    └── nested
        └── __init__.py

Releasing

Do the following steps:

python setup.py sdist

Upload it to test PyPI:

pip install twine
twine upload --repository testpypi dist/*
pip install -U --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple -U pysnapshot

Make sure you can install it and it works (e.g. run the examples). Now upload to actual PyPI:

twine upload dist/*

pysnapshot's People

Stargazers

Benjamin Scholtz avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.