Skip to main content

Cache lines and file information which are generally Python programs

Project description

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 trepan3k and trepan2 debuggers, 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 ‘colorful’ line = pyficache.getline(filename, 6, {‘style’: ‘colorful’})

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.

Source Distribution

pyficache-2.4.0.tar.gz (33.6 kB view details)

Uploaded Source

Built Distributions

pyficache-2.4.0-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

pyficache-2.4.0-py2-none-any.whl (33.9 kB view details)

Uploaded Python 2

File details

Details for the file pyficache-2.4.0.tar.gz.

File metadata

  • Download URL: pyficache-2.4.0.tar.gz
  • Upload date:
  • Size: 33.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for pyficache-2.4.0.tar.gz
Algorithm Hash digest
SHA256 c3ce7b49b9d26a34c255a8b6a361e234f1ebb20d37eecc41de1e9ba58ba553d8
MD5 14ffe254634fe204c90eff2b7c095b9f
BLAKE2b-256 619772159ece19a5feec21a2629ad7e02bace110113d832fcd1c754cf24e72f8

See more details on using hashes here.

File details

Details for the file pyficache-2.4.0-py3-none-any.whl.

File metadata

  • Download URL: pyficache-2.4.0-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for pyficache-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6074ef4b004cd0474b3bed34480b3632d4415b5ed6ba2e3e400792858a87b55d
MD5 471b919054ce4a6b09e27e933bda3d85
BLAKE2b-256 37b6acdbc40cdfc6f60e4ddabc6f78ee0d2077b5f7534fbbd00816fa854e3b33

See more details on using hashes here.

File details

Details for the file pyficache-2.4.0-py2-none-any.whl.

File metadata

  • Download URL: pyficache-2.4.0-py2-none-any.whl
  • Upload date:
  • Size: 33.9 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for pyficache-2.4.0-py2-none-any.whl
Algorithm Hash digest
SHA256 be376d8c4b9a9394214a49edd95a4f363a5029dc02c6e3457d715f95afdecbee
MD5 db8e7d4d5c03249032b0aea4f1e4336c
BLAKE2b-256 60b4e7b0cb21c894fe13bb0f027a137a9dedec415a6c20f8e5425ddfcfbfdf2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page