Skip to main content

A better way to manage and import dependencies.

Project description

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.

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

requirepy-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file requirepy-0.1.0.tar.gz.

File metadata

  • Download URL: requirepy-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for requirepy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 54458257476e064aa518559ef43ea8604469fdc2540f67fd60059574da209ac7
MD5 ee0e06ff1c8d776aba556663fc59920b
BLAKE2b-256 c964cec65aba797b880b5970e1afd678d49d4e47712854d7dbce7d4f9aaf6e1f

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