The Python module pip_accel defines the classes and functions that implement the functionality of the pip accelerator and the pip-accel command. Instead of using the pip-accel command you can also use the pip accelerator as a Python module. In this case you’ll probably want to start by taking a look at the following functions:
Required to call pip as a Python module instead of a subprocess.
The pip.commands.install.InstallCommand.run() method returns a RequirementSet object which pip-accel is interested in, however pip.basecommand.Command.main() swallows the requirement set (based on my reading of the pip 1.3.x source code).
To work around the problem described above, we subclass InstallCommand to wrap the run() method. Yes this is a bit sneaky, but I don’t fancy reimplementing pip.basecommand.Command.main() inside pip-accel!
Easy to use timer to keep track of long during operations.
Get the number of seconds elapsed since the timer object was created.
Make sure all cached source distributions have the right file extension, because not all distribution sites provide URLs with proper filenames in them while we really need the proper filenames to build the local source index.
Parameters: |
|
---|---|
Returns: | The (possibly modified) pathname of the distribution archive in the source index directory. |
Previously this used the file executable, now it checks the magic file headers itself. I could have used any of the numerous libmagic bindings on PyPI, but that would add a binary dependency to pip-accel and I don’t want that :-).
Convert source distributions to binary distributions.
Parameters: | requirements – A list of tuples in the format of the return value of the unpack_source_dists() function. |
---|---|
Returns: | True if it succeeds in building a binary distribution, False otherwise (probably because of missing binary dependencies like system libraries). |
Transform a binary distribution archive created with python setup.py bdist_dumb --format=gztar into a form that can be cached for future use. This comes down to making the pathnames inside the archive relative to the prefix that the binary distribution was built for.
Parameters: |
|
---|
Download missing source distributions.
Parameters: | arguments – A list with the arguments intended for pip. |
---|
InstallRequirement objects in RequirementSet objects have a req member, which apparently can be either a string or a pkg_resources.Requirement object. This function makes sure we’re dealing with a pkg_resources.Requirement object.
This was “copied” from the pip source code, I’m not sure if this code is actually necessary but it doesn’t hurt and pip probably did it for a reason. Right? :-)
Parameters: | install_requirement – An InstallRequirement object produced by pip. |
---|---|
Returns: | A pkg_resources.Requirement object. |
Variant of os.path.expanduser() that doesn’t use $HOME but instead uses the home directory of the effective user id. This is basically a workaround for sudo -s not resetting $HOME.
Parameters: | pathname – A pathname that may start with ~/, indicating the path should be interpreted as being relative to the home directory of the current (effective) user. |
---|
Find all previously cached binary distributions.
Returns: | A dictionary with (package-name, package-version, python-version) tuples as keys and pathnames of binary archives as values. |
---|
Rewrite the hashbang in an executable script so that the Python program inside the virtual environment is used instead of a system wide Python.
Parameters: |
|
---|---|
Returns: | The modified contents of the script as a string. |
Return a string identifying the currently running Python version.
Returns: | A string like “py2.6” or “py2.7” containing a short mnemonic prefix followed by the major and minor version numbers. |
---|
Create the directories for the download cache, the source index and the binary index if any of them don’t exist yet and reset the binary index when its format changes.
Install a binary distribution created with python setup.py bdist into the given prefix (a directory like /usr, /usr/local or a virtual environment).
Parameters: |
|
---|
Manually install all requirements from binary distributions.
Parameters: |
|
---|---|
Returns: | True if it succeeds in installing all requirements from binary distribution archives, False otherwise. |
Main logic of the pip-accel command.
Report the usage of the pip-accel command to the console.
Execute a modified pip install command. This function assumes that the arguments concern a pip install command (main() makes sure of this).
Parameters: |
|
---|---|
Returns: | A RequirementSet object created by pip, unless an exception is raised by pip (in which case the exception will bubble up). |
Sort the requirements in a RequirementSet.
Parameters: | requirement_set – A RequirementSet object produced by pip. |
---|---|
Returns: | A list of sorted InstallRequirement objects. |
Check whether there are local source distributions available for all requirements, unpack the source distribution archives and find the names and versions of the requirements. By using the pip install --no-install command we avoid reimplementing the following pip features:
Parameters: | arguments – A list of strings with the command line arguments to be passed to the pip command. |
---|---|
Returns: | A list of tuples with three strings each: The name of a requirement (package), its version number and the directory where the unpacked source distribution is located. If pip fails, an exception will be raised by pip. |
Link newly downloaded source distributions into the local index directory using symbolic links.