Cache lines and file information which are generally Python programs
Project description
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.
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 Distributions
Hashes for pyficache-2.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9582857887bc3a0940547386ab30b4d2fc677d9b73127a653bfc07e7915e55d |
|
MD5 | a59aadbf5d88b2ba549387a8a84557b1 |
|
BLAKE2b-256 | 6972e2f360262d0aa79deb4db8605084f9d5d844d8769232621ef28af8ca5501 |
Hashes for pyficache-2.0.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3de85dc038ff8d579a4a3251dfec84e6d0596721a197dac86c1a6e33ef3f6497 |
|
MD5 | 6e8392626ca4ab07eec626b512eebbc0 |
|
BLAKE2b-256 | 6c27bc555ae2d8a1a7d76c5a7a62da3830d3e765abac9e89d3a73c4263d430e2 |