Skip to content

edgarrmondragon/pep610

Repository files navigation

pep610

PyPI - Version PyPI - Python Version PyPI - Downloads codecov Documentation Status

A Python library for parsing the Direct URL Origin structure from installed packages.

PEP 610 initially specified how the Direct URL Origin of installed distributions should be recorded, but the up-to-date, canonical specification is maintained on the PyPA specs page.


Table of Contents

Installation

pip install pep610

Usage

You can use pep610.read_from_distribution to parse the Direct URL Origin structure from a Distribution object:

from importlib import metadata

import pep610

dist = metadata.distribution("pep610")

if (
    (data := pep610.read_from_distribution(dist))
    and isinstance(data, pep610.DirData)
    and data.dir_info.is_editable()
):
    print("Editable installation, a.k.a. in development mode")
else:
    print("Not an editable installation")

Or, in Python 3.10+ using pattern matching:

from importlib import metadata

import pep610

dist = metadata.distribution("pep610")

match data := pep610.read_from_distribution(dist):
    case pep610.DirData(url, pep610.DirInfo(editable=True)):
        print("Editable installation, a.k.a. in development mode")
    case _:
        print("Not an editable installation")

Development

This project uses Hatch.

Testing

  1. Run the unit tests:

    hatch run all:cov
  2. Compute the coverage report:

    hatch run coverage:report

Linting

  1. Run the linters:

    hatch env run --force-continue --env=lint all

Documentation

  1. Build the documentation:

    hatch run docs:build

License

pep610 is distributed under the terms of the Apache License 2.0.