Skip to main content

require.py

A way to manage dependency conflicts.

What Is require.py?

The core of require.py is a hack of the Python import statement. By default, all Python modules are installed at the global, site-packages level. This makes it difficult, and sometimes impossible, to install libraries with conflicting dependency requirements. To a large extent, virtual environments have solved this problem by providing sandboxes in which Python modules can be installed without affecting other virtual environments. Even virtualenvs, however, do not allow a single Python process to load multiple, conflicting versions of a dependency as the same time.

This project provides tools for managing dependencies at a Python package level. This means each Python package (a directory containing an __init__.py) can have a unique version of a dependency that is isolated from the other packages around it.

Import Behaviour

The import logic, and name for this project, are heavily inspired by the node.js module and import system. The relevant behaviour in node is documented here.

This package exposes a callable named require that can be used to provide the alternate import logic. Alternatively, there are patch_import and unpatch_import available to affect an entire Python process. Here is a scenario to illustrate the import logic. Given the following project structure:

/myproject/__init__.py
/myproject/subpackage/__init__.py
/myproject/subpackage/subsubpackage/__init__.py

Where the __init__.py of subsubpackage has the following content:

from require import require
requests = require('requests')

The custom import logic will first look for a ‘.pymodules’ directory in subsubpackage. If found, it will attempt to import requests from that directory. If not found, it will continue walking the file system upwards until it hits ‘/’. After hitting the root, if no ‘.pymodules’ directories are found the function falls back to the default Python import logic.

Package Management

Keep using pip. This project includes a helper command called requirepy that can be used to help install dependencies into the right subdirectories. It wraps pip.

License

Copyright 2014 Kevin Conway

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributing

All contributions to this project are protected under the agreement found in the CONTRIBUTING file. All contributors should read the agreement but, as a summary:

You give us the rights to maintain and distribute your code and we promise
to maintain an open source distribution of anything you contribute.

Metadata

Release files for requirepy 0.1.0

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

Source distribution (sdist)

Source distribution for requirepy 0.1.0
File Size Uploaded Provenance
requirepy-0.1.0.tar.gz 5.6 kB Without provenance Details

Release files / requirepy-0.1.0.tar.gz

Download URL requirepy-0.1.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
54458257476e064aa518559ef43ea8604469fdc2540f67fd60059574da209ac7
BLAKE2b-256 checksum
How to use checksums
c964cec65aba797b880b5970e1afd678d49d4e47712854d7dbce7d4f9aaf6e1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for requirepy 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

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