Skip to main content

A system for anchoring metadata in external files to source code

Project description

Python version Build Status

spor

NB: This Python implementation of spor has been superseded by a Rust implementation. This version might be kept compatible with the Rust version, but don’t count on it for now.

A system for anchoring metadata in external files to source code.

spor lets you define metadata for elements of your source code. The metadata is kept in a separate file from your source code, meaning that you don’t need to clutter your source file with extra information encoded into comments. To accomplish this while dealing with the fact that source code changes over time, spor uses various “anchoring” techniques to keep the metadata in sync with the source code (or let you know when they become unmanageably out of sync).

Quickstart

Before you can use spor to anchor metadata to files, you need to initialize a repository with the init command:

$ spor init

This is very similar in spirit to git init. It creates a new directory in your current directory called .spor, and this is where spor will keep the information it needs.

Now you can create anchors. Suppose you’ve got a file, example.py, like this:

# example.py


def func(x):
    return x * 2

You can anchor metadata to line 4 (the function definition) by specifying the starting offset and anchor width like this:

$ echo "{\"meta\": \"data\"}" | spor add example.py 32 12 10

You don’t have to pipe the metadata into the add command. If you don’t, spor will pop up an editor so that you can enter the metadata there.

The 10 at the end specifies the size of the “context” around the anchored code that we use for updating anchors.

This will associate the dictionary {meta: data} with the code return x * 2. You can see this metadata by using the list command:

$ spor list example.py
example.py:32 => {'meta': 'data'}

The metadata can be any valid JSON. spor doesn’t look at the data at all, so it’s entirely up to you to decide what goes there.

Motivation

My main motivation for this tool comes from my work on the mutation testing tool Cosmic Ray. CR users need to be able to specify sections of their source code which should not be mutated, or which should only be mutated in specific ways. Rather than having them embed these processing directives in the source code, I thought it would be cleaner and neater to let them do so with a separate metadata file.

Features

spor needs support for the following functionality:

  1. Add/edit/delete metadata to a specific range of text in a source file

  2. Query existing metadata

  3. Automatically update metadata when possible, or report errors when not

  4. Provide facilities facilities for “updating” metadata with new anchoring data

The design needs to be sensitive to both human users (i.e. since they may need to manually work with the metadata from time to time) as well as programmatic users. I’m sure the design will evolve as we go, so I’m going to try to keep it simple and explicit at first.

Ideally spor will work on any programming language (and, really, any text document), though its initial target will be Python source code.

Development

Spor is new and small enough that we do fun things like try out new tools. Instead of setuptools et al., we’re using poetry. So if you want to contribute to spor, the first thing you need to do is to install poetry.

To install the package, use:

poetry install

Tests

The installation command above will install all of the test dependencies as well. To run all of the tests, run tox:

tox

To run just the pytests unit tests, run:

poetry run pytest tests/unittests

To run the radish tests, run:

poetry run radish tests/e2e/features -b tests/e2e/radish

Notes

The field of “anchoring” is not new, and there’s some existing work we need to pay attention to:

Project details


Download files

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

Source Distribution

spor-1.1.6.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

spor-1.1.6-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file spor-1.1.6.tar.gz.

File metadata

  • Download URL: spor-1.1.6.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.0 Darwin/18.7.0

File hashes

Hashes for spor-1.1.6.tar.gz
Algorithm Hash digest
SHA256 5f8783d92cb866ea27374a7957e85f3b8b958303f6b2585590f7303bc040afbc
MD5 505fa64707284e432f58959b8c8764e8
BLAKE2b-256 249ff9a37aeb778762c503df86ce71474d7052864c2ab27662b01b2dcb152d6f

See more details on using hashes here.

File details

Details for the file spor-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: spor-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.0 Darwin/18.7.0

File hashes

Hashes for spor-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e68c84d30856a44fe2bf4af6866ae5f93bf1d2220557f9e45b3219c800a77049
MD5 bfaa20c66a7dc1f8ea7d865e10bed4a1
BLAKE2b-256 2a279f8d7fc97b2e537055532e4c6ba46dc512fe40ca51660d505277fecd8310

See more details on using hashes here.

Supported by

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