Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from using .par files to pure python for piptool and whltool #81

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.lo
*.o
*.obj
*.pyc

# Precompiled Headers
*.gch
Expand Down
2 changes: 1 addition & 1 deletion python/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pip_import = repository_rule(
),
"_script": attr.label(
executable = True,
default = Label("//tools:piptool.par"),
default = Label("//tools:piptool_wrapper.py"),
cfg = "host",
),
},
Expand Down
2 changes: 1 addition & 1 deletion python/whl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ whl_library = repository_rule(
"extras": attr.string_list(),
"_script": attr.label(
executable = True,
default = Label("//tools:whltool.par"),
default = Label("//tools:whltool_wrapper.py"),
cfg = "host",
),
},
Expand Down
60 changes: 10 additions & 50 deletions rules_python/piptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,76 +25,36 @@
import tempfile
import zipfile

# Note: We carefully import the following modules in a particular
# order, since these modules modify the import path and machinery.
import pkg_resources


def extract_packages(package_names):
"""Extract zipfile contents to disk and add to import path"""

# Set a safe extraction dir
extraction_tmpdir = tempfile.mkdtemp()
atexit.register(lambda: shutil.rmtree(
extraction_tmpdir, ignore_errors=True))
pkg_resources.set_extraction_path(extraction_tmpdir)

# Extract each package to disk
dirs_to_add = []
for package_name in package_names:
req = pkg_resources.Requirement.parse(package_name)
extraction_dir = pkg_resources.resource_filename(req, '')
dirs_to_add.append(extraction_dir)

# Add extracted directories to import path ahead of their zip file
# counterparts.
sys.path[0:0] = dirs_to_add
existing_pythonpath = os.environ.get('PYTHONPATH')
if existing_pythonpath:
dirs_to_add.extend(existing_pythonpath.split(':'))
os.environ['PYTHONPATH'] = ':'.join(dirs_to_add)


# Wheel, pip, and setuptools are much happier running from actual
# files on disk, rather than entries in a zipfile. Extract zipfile
# contents, add those contents to the path, then import them.
extract_packages(['pip', 'setuptools', 'wheel'])

# Defeat pip's attempt to mangle sys.path
saved_sys_path = sys.path
sys.path = sys.path[:]
import pip
sys.path = saved_sys_path

import setuptools
import wheel


def pip_main(argv):
# Extract the certificates from the PAR following the example of get-pip.py
# https://github.com/pypa/get-pip/blob/430ba37776ae2ad89/template.py#L164-L168
cert_path = os.path.join(tempfile.mkdtemp(), "cacert.pem")
with open(cert_path, "wb") as cert:
cert.write(pkgutil.get_data("pip._vendor.requests", "cacert.pem"))
argv = ["--disable-pip-version-check", "--cert", cert_path] + argv
argv = ["--disable-pip-version-check"] + argv
return pip.main(argv)

from rules_python.whl import Wheel
from whl import Wheel

parser = argparse.ArgumentParser(
description='Import Python dependencies into Bazel.')

parser.add_argument('--name', action='store',
help=('The namespace of the import.'))
help=('The namespace of the import.'),
required=True)

parser.add_argument('--input', action='store',
help=('The requirements.txt file to import.'))
help=('The requirements.txt file to import.'),
required=True)

parser.add_argument('--output', action='store',
help=('The requirements.bzl file to export.'))
help=('The requirements.bzl file to export.'),
required=True)

parser.add_argument('--directory', action='store',
help=('The directory into which to put .whl files.'))
help=('The directory into which to put .whl files.'),
required=True)

def determine_possible_extras(whls):
"""Determines the list of possible "extras" for each .whl
Expand Down
20 changes: 20 additions & 0 deletions third_party/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Vendored third_party software

All software is licensed and copyrighted as described by appropriate
license and copyright notices in its subdirectory.

## Implementation note

This directory intentionally does not have an `__init__.py` file.

## Updates

Run the following commands to update a third-party package:

``` shell
rm -r third_party/package_name*
pip install --target=third_party package_name
```

Then edit the files `tools/*wrapper.py`, updating the version number checks
under the line `# Sanity check that vendoring logic worked`.
39 changes: 39 additions & 0 deletions third_party/pip-9.0.3.dist-info/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pip
===

The `PyPA recommended
<https://packaging.python.org/en/latest/current/>`_
tool for installing Python packages.

* `Installation <https://pip.pypa.io/en/stable/installing.html>`_
* `Documentation <https://pip.pypa.io/>`_
* `Changelog <https://pip.pypa.io/en/stable/news.html>`_
* `Github Page <https://github.com/pypa/pip>`_
* `Issue Tracking <https://github.com/pypa/pip/issues>`_
* `User mailing list <http://groups.google.com/group/python-virtualenv>`_
* `Dev mailing list <http://groups.google.com/group/pypa-dev>`_
* User IRC: #pypa on Freenode.
* Dev IRC: #pypa-dev on Freenode.


.. image:: https://img.shields.io/pypi/v/pip.svg
:target: https://pypi.python.org/pypi/pip

.. image:: https://img.shields.io/travis/pypa/pip/master.svg
:target: http://travis-ci.org/pypa/pip

.. image:: https://img.shields.io/appveyor/ci/pypa/pip.svg
:target: https://ci.appveyor.com/project/pypa/pip/history

.. image:: https://readthedocs.org/projects/pip/badge/?version=stable
:target: https://pip.pypa.io/en/stable

Code of Conduct
---------------

Everyone interacting in the pip project's codebases, issue trackers, chat
rooms, and mailing lists is expected to follow the `PyPA Code of Conduct`_.

.. _PyPA Code of Conduct: https://www.pypa.io/en/latest/code-of-conduct/


1 change: 1 addition & 0 deletions third_party/pip-9.0.3.dist-info/INSTALLER
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
70 changes: 70 additions & 0 deletions third_party/pip-9.0.3.dist-info/METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Metadata-Version: 2.0
Name: pip
Version: 9.0.3
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: python-virtualenv@groups.google.com
License: MIT
Keywords: easy_install distutils setuptools egg virtualenv
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Software Development :: Build Tools
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=2.6,!=3.0.*,!=3.1.*,!=3.2.*
Provides-Extra: testing
Provides-Extra: testing
Requires-Dist: pytest; extra == 'testing'
Requires-Dist: virtualenv (>=1.10); extra == 'testing'
Requires-Dist: scripttest (>=1.3); extra == 'testing'
Requires-Dist: mock; extra == 'testing'
Requires-Dist: pretend; extra == 'testing'

pip
===

The `PyPA recommended
<https://packaging.python.org/en/latest/current/>`_
tool for installing Python packages.

* `Installation <https://pip.pypa.io/en/stable/installing.html>`_
* `Documentation <https://pip.pypa.io/>`_
* `Changelog <https://pip.pypa.io/en/stable/news.html>`_
* `Github Page <https://github.com/pypa/pip>`_
* `Issue Tracking <https://github.com/pypa/pip/issues>`_
* `User mailing list <http://groups.google.com/group/python-virtualenv>`_
* `Dev mailing list <http://groups.google.com/group/pypa-dev>`_
* User IRC: #pypa on Freenode.
* Dev IRC: #pypa-dev on Freenode.


.. image:: https://img.shields.io/pypi/v/pip.svg
:target: https://pypi.python.org/pypi/pip

.. image:: https://img.shields.io/travis/pypa/pip/master.svg
:target: http://travis-ci.org/pypa/pip

.. image:: https://img.shields.io/appveyor/ci/pypa/pip.svg
:target: https://ci.appveyor.com/project/pypa/pip/history

.. image:: https://readthedocs.org/projects/pip/badge/?version=stable
:target: https://pip.pypa.io/en/stable

Code of Conduct
---------------

Everyone interacting in the pip project's codebases, issue trackers, chat
rooms, and mailing lists is expected to follow the `PyPA Code of Conduct`_.

.. _PyPA Code of Conduct: https://www.pypa.io/en/latest/code-of-conduct/


Loading