Skip to main content

Cache lines and file information which are generally Python programs

Project description

TravisCI CircleCI Pypi Installs License Supported Python Versions

packagestatus

Synopsis

The pyficache module allows one to get any line from any file, caching lines of the file on first access to the file. Although the file may be any file, this package is more tailored to the case where the file is a Python script.

Here, the file is parsed to determine statement bounderies, and a copies of the file syntax-highlighted are also saved.

Also saved is file information such as when the file was last modified and a SHA1 of the file. These are useful in determining if the file has changed and verifying the contents of the file.

By caching contents, access is sped up when small small random sets of lines are read from a single file, in particular in a debugger to show source lines.

A file path can be remapped to another path. This is useful for example when debugging remotely and the remote file path may be different from the path on a local filesystem. In the trepan2 debugger, eval and exec strings are saved in a temporary file and then the pseudo-filename <string> is remapped to that temporary file name.

Similarly lines within a file can be remapped to other lines. This may be useful in preprocessors or template systems where ones wants to make a correspondence between the template file and the expanded Python file as seen in a tool using that underlying Python file such as a debugger or profiler.

Summary

import pyficache
filename = __file__ # e.g. '/tmp/myprogram'
 # return all lines of filename as an array
lines = pyficache.getlines(filename)

 # return line 6, and reload all lines if the file has changed.
line = pyficache.getline(filename, 6, {'reload_on_change': True})

# return line 6 syntax highlighted via pygments using style 'emacs'
line = pyficache.getline(filename, 6, {'style': 'emacs'})

pyficache.remap_file('/tmp/myprogram.py', 'another-name')
line_from_alias = pyficache.getline('another-name', 6)

assert __file__, pyficache.remove_remap_file('another-name')

# another-name is no longer an alias for /tmp/myprogram
assert None, pyficache.remove_remap_file('another-name')

# Clear cache for __file__
 pyficache.clear_file_cache(__file__)

# Clear all cached files.
pyficache.clear_file_cache()

# Check for modifications of all cached files.
pyficache.update_cache()

Credits

This is a port of the my Ruby linecache module which in turn is based on the Python linecache module.

xdis provides the cool stuff to figure out the lines containing Python statements.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyficache, version 2.2.1
Filename, size File type Python version Upload date Hashes
Filename, size pyficache-2.2.1-py2.4.egg (39.2 kB) File type Egg Python version 2.4 Upload date Hashes View
Filename, size pyficache-2.2.1-py2.5.egg (38.5 kB) File type Egg Python version 2.5 Upload date Hashes View
Filename, size pyficache-2.2.1-py2.6.egg (34.5 kB) File type Egg Python version 2.6 Upload date Hashes View
Filename, size pyficache-2.2.1-py26-none-any.whl (20.5 kB) File type Wheel Python version py26 Upload date Hashes View
Filename, size pyficache-2.2.1-py2.7.egg (34.2 kB) File type Egg Python version 2.7 Upload date Hashes View
Filename, size pyficache-2.2.1-py27-none-any.whl (30.5 kB) File type Wheel Python version py27 Upload date Hashes View
Filename, size pyficache-2.2.1-py3.2.egg (34.9 kB) File type Egg Python version 3.2 Upload date Hashes View
Filename, size pyficache-2.2.1-py32-none-any.whl (20.5 kB) File type Wheel Python version py32 Upload date Hashes View
Filename, size pyficache-2.2.1-py3.3.egg (35.4 kB) File type Egg Python version 3.3 Upload date Hashes View
Filename, size pyficache-2.2.1-py33-none-any.whl (20.5 kB) File type Wheel Python version py33 Upload date Hashes View
Filename, size pyficache-2.2.1-py3.4.egg (34.9 kB) File type Egg Python version 3.4 Upload date Hashes View
Filename, size pyficache-2.2.1-py34-none-any.whl (30.5 kB) File type Wheel Python version py34 Upload date Hashes View
Filename, size pyficache-2.2.1-py3.5.egg (34.8 kB) File type Egg Python version 3.5 Upload date Hashes View
Filename, size pyficache-2.2.1-py35-none-any.whl (30.5 kB) File type Wheel Python version py35 Upload date Hashes View
Filename, size pyficache-2.2.1-py3.6.egg (34.3 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size pyficache-2.2.1-py3.7.egg (34.3 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size pyficache-2.2.1-py37-none-any.whl (30.5 kB) File type Wheel Python version py37 Upload date Hashes View
Filename, size pyficache-2.2.1-py3.8.egg (34.4 kB) File type Egg Python version 3.8 Upload date Hashes View
Filename, size pyficache-2.2.1-py38-none-any.whl (30.5 kB) File type Wheel Python version py38 Upload date Hashes View
Filename, size pyficache-2.2.1.tar.gz (20.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page