Skip to content

Commit

Permalink
Replace whltool.par with whltool_wrapper.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Greiman committed Mar 28, 2018
1 parent 045f37c commit ee2e83a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
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
6 changes: 2 additions & 4 deletions tools/piptool_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright 2017 The Bazel Authors. All rights reserved.
# Copyright 2018 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -26,8 +26,6 @@
import os
import sys

# Never do what we're about to do.
#
# Add our first-party source, and vendored third_party packages, to
# the start of sys.path, so that we win any collision with already
# installed modules.
Expand Down Expand Up @@ -56,6 +54,6 @@
assert wheel.__version__ == '0.30.0'
assert pip.__version__ == '9.0.1'

# Invoke piptool
# Invoke tool
import piptool
piptool.main()
59 changes: 59 additions & 0 deletions tools/whltool_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python

# Copyright 2018 The Bazel Authors. All rights reserved.
#
# 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.

"""Wrapper to invoke whl.py with vendored third-party dependencies.
This wrapper must work under Python 2.7.*, or any Python 3.* >= 3.4.0.
It must also work under Linux, Mac OS, Windows, and any other
operating system. It must work inside or outside a virtualenv, inside
or outside a runfiles tree, and inside or outside a Bazel execroot.
It must work with arbitrary other packages on the Python import path.
"""

import os
import sys

# Add our first-party source, and vendored third_party packages, to
# the start of sys.path, so that we win any collision with already
# installed modules.

_this_file = __file__
if (_this_file is None) or not os.path.isfile(_this_file):
sys.exit("whltool_wrapper.py failed. Cannot determine __file__")

_tool_dir = os.path.dirname(_this_file)
_root_dir = os.path.abspath(os.path.join(_tool_dir, '..'))
sys.path[0:0] = [
# Vendored third_party packages
os.path.join(_root_dir, 'third_party'),
# First party source (not a Python import package, just a directory)
os.path.join(_root_dir, 'rules_python'),
]

# Safe to import
import setuptools
import pkg_resources
import wheel
import pip

# Sanity check that vendoring logic worked
assert setuptools.__version__ == '38.5.1'
assert wheel.__version__ == '0.30.0'
assert pip.__version__ == '9.0.1'

# Invoke tool
import whl
whl.main()

0 comments on commit ee2e83a

Please sign in to comment.