Skip to main content
https://img.shields.io/travis/h4l/rnginline.svg https://img.shields.io/codecov/c/github/h4l/rnginline/master.svg https://img.shields.io/pypi/v/rnginline.svg https://img.shields.io/badge/docs-latest-brightgreen.svg

rnginline is a Python library and command-line tool for loading multi-file RELAX NG schemas from arbitary URLs, and flattening them into a single RELAX NG schema.

Features

  • Convert multi-file RNG schemas into one file without breaking or restructuring the schemas

    • Great care is taken to maintain the semantics of the separate schema files in the single output

    • The input documents are changed as little as possible, so the output is as readable as the input

  • Load schemas from:

    • The filesystem

    • From a Python package’s data (without unpacking it to the filesystem)

  • command-line interface as well as a Python API

  • Test suite covering lots of edge cases, e.g. namespace handling

    • 100% line & branch code coverage

Quickstart

Install with pip:

$ pip install rnginline

You can use it from Python like this:

>>> import rnginline
>>> rnginline.inline('my-nested-schema-root.rng')
<lxml.etree.RelaxNG object at ...>

You can load a multi-file schema from a Python package’s data like this:

>>> import rnginline
>>> from rnginline.urlhandlers import pydata
>>> url = pydata.makeurl('rnginline.test',
...                      'data/testcases/external-ref-1/schema.rng')
>>> url
'pydata://rnginline.test/data/testcases/external-ref-1/schema.rng'
>>> rnginline.inline(url)
<lxml.etree.RelaxNG object at ...>

You can use it from the command line like this:

$ rnginline my-nested-schema-root.rng flattened-output.rng

Documentation

Documentation is available at http://rnginline.readthedocs.org/

Motivation

lxml has good support for using RELAX NG schemas, but lacks support for loading multi-file schemas from anywhere other than the filesystem. This is a problem if you wish to bundle a multi-file schema with your Python package/module. You’d have to depend on setuptools being available to use its resource extraction, or use one of the existing RELAX NG merging tools to convert your schema into a single file.

Existing RELAX NG flattening tools

The following projects didn’t quite fit my needs, leading me to write rnginline. They may work for you though.

  • rng2srng - Implements full simplification, so the structure of the input schema will be lost

  • rng-incelim - A similar project to this, implemented in XSLT. Unfortunately doesn’t handle namespace declarations on <include> elements correctly. XSLT 1.0 doesn’t support creating namespace nodes, so to fix this rng-incelim would have to resolve all QNames in the schema to NCNames with ns attributes, which would be undesirable for me.

Developing

An invoke tasks file contains testing, doc building, linting tasks. The tox config uses invoke to run tests over various Python versions.

To do a full test run, install tox ($ pip install tox) then run $ tox from within the checked-out repo. This will take several minutes on the first run, mainly due to the amount of time lxml takes to build from source.

To run invoke tasks, ensure all the dev dependencies are installed:

$ pip install -r requirements/all.txt
$ invoke -l
Available tasks:

  […]
  coverage    Combine coverage of Python 2 and Python 3 test runs
  docs        Build sphinx documentation
  docs_test   Test the doctests in the Sphinx docs. Must be run with Python 3.
  pep8        Lint code for PEP 8 violations
  readme      Lint the README for reStructuredText syntax issues
  test        Run rnginline test suite
$ invoke test
============================= test session starts ==============================
platform darwin -- Python 2.7.8 -- py-1.4.26 -- pytest-2.6.4
plugins: cov
collected 346 items

[…]

Prebuilding Wheels

To mitigate the time lxml takes to build, you can pre-build all the dependencies as Wheels into ./wheelhouse and have pip use the pre-built wheels on every install. To do so, run:

$ invoke cache_all_requirement_wheels
$ export PIP_FIND_LINKS=$(pwd)/wheelhouse

Release files for rnginline 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rnginline 0.0.1
File Size Uploaded
rnginline-0.0.1.tar.gz 63.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rnginline 0.0.1
File Interpreter ABI Platform
rnginline-0.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 142.5 kB

Release files / rnginline-0.0.1.tar.gz

Download URL rnginline-0.0.1.tar.gz
Size 63.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2add350efdec569ec308eaefc74564753bec53d39649d24de83858e06cc21e93
BLAKE2b-256 checksum
How to use checksums
4c281e5a94b18665100f629a291056374f7cec2883f48c14953e379875e1f080
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / rnginline-0.0.1-py2.py3-none-any.whl

Download URL rnginline-0.0.1-py2.py3-none-any.whl
Size 78.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c61aef50caed2a012f4f521568905c1d48a2bdb65930a40fb241ce425bb1e821
BLAKE2b-256 checksum
How to use checksums
abd3c98e0fd4a99621741d7d21b6c4b357cd90f0305cc4cc5b1d14b707bb9c75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.0.0

2 release files

0.0.2

2 release files

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page