Skip to content

Commit

Permalink
keep file permissions when unpacking
Browse files Browse the repository at this point in the history
add zipextended.py to BUILD

fix import path

use pip internal unzip

use pip internal unzip tools

remove custom zipfile implementation

Add documentation of community / Bazel team ownership (bazelbuild#308)

This adds a more nuanced CODEOWNERS and explains its purpose in CONTRIBUTING.md.

Fixes bazelbuild#291.

point README readers to new 0.0.2 release (bazelbuild#302)

update version in version.bzl (bazelbuild#303)

Fix for when there are so many file arguments it creates the Command To Long error (bazelbuild#320)

Fix failing build on CI by specifying pip package version (bazelbuild#329)

`bazel build //...` was failing due to "googleapis-common-protos[grpc]"
pip package being unavailable.

It seems to be caused by latest googleapis-common-protos release.
Specify googleapis-common-protos in requirements.txt to be in the previous
version (1.51.0) to fix this.

Fixes bazelbuild#321.

"Skylark" is an outdated name of the language, please use "starlark" instead (bazelbuild#327)

Co-authored-by: Andy Scott <andyscott@users.noreply.github.com>

Support python interpreter target in pip_import. (bazelbuild#312)

* Support python interpreter target in pip_import.

This allows users to use a custom python interpreter that is built by
another repository rule instead of using a pre-built interpreter binary
that is checked-in.

This tangentially addresses bazelbuild#257 since a common setup is to use the
custom built interpreter in the python toolchain.

For example, see: https://github.com/kku1993/bazel-hermetic-python

* Actually use interpreter path.

Co-authored-by: Andy Scott <andyscott@users.noreply.github.com>

Address bazelbuild#289 (bazelbuild#328)

Co-authored-by: Andy Scott <andyscott@users.noreply.github.com>

Fix errors with incompatible_disallow_empty_glob (bazelbuild#315)

Allow py_library sources to be empty.
If --incompatible_disallow_empty_glob is set then generated py_library
targets will fail if there are no .py files.

Examples are pymssql==2.1.4 and cx-Oracle==7.2.3.

Set `allow_empty = True` for glob().

Bazel issue for incompatible_disallow_empty_glob:
bazelbuild/bazel#8195

Co-authored-by: Andy Scott <andyscott@users.noreply.github.com>

rebuild piptool and whltool

update filename, add links to pip function definitions

remove typing checks

chore: github setup improvements (bazelbuild#334)

Remove mention and usage of Bazel Federation (bazelbuild#339)

It's currently a stalled project so it's not useful for us to direct new users there in our README.
Separately it is harder to develop on rules_python since it is currently not self-contained.
For example it's hard to find or adjust the version of rules_pkg without looking/editing in the federation repo.
Tony says this is an okay change: bazelbuild/bazel-federation@63f9746#commitcomment-40577834

leaner implementation of pip unzip

remove unzip.py

temp test with tools

2nd test with tools

final test with tools

replace with master tools

merge original tools

feat(examples): move examples to a nested WORKSPACE (bazelbuild#337)

This lets users understand the example in isolation. They can copy/paste the example directory
and it works correctly.

This refactors the existing examples which are quite weak, only really demonstrating pip usage.
This makes room for examples demonstrating other features (like protocol buffers) or package
managers (like poetry).

In a later commit I'll add bazel-integration-testing so we get a test target that confirms
the examples build (including their WORKSPACE being self-contained)

warn against putting .par file changes in PR. (bazelbuild#342)
  • Loading branch information
Garrett Weaver authored and Jonathon Belotti committed Jul 31, 2020
1 parent 0f8183b commit 6742ef2
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions packaging/whl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,25 @@
import os
import pkg_resources
import re
import stat
import zipfile


def current_umask():
"""Get the current umask which involves having to set it temporarily."""
mask = os.umask(0)
os.umask(mask)
return mask


def set_extracted_file_to_default_mode_plus_executable(path):
"""
Make file present at path have execute for user/group/world
(chmod +x) is no-op on windows per python docs
"""
os.chmod(path, (0o777 & ~current_umask() | 0o111))


class Wheel(object):

def __init__(self, path):
Expand Down Expand Up @@ -107,8 +123,21 @@ def extras(self):
return self.metadata().get('extras', [])

def expand(self, directory):
with zipfile.ZipFile(self.path(), 'r') as whl:
whl.extractall(directory)
with zipfile.ZipFile(self.path(), "r", allowZip64=True) as whl:
whl.extractall(directory)
# The following logic is borrowed from Pip:
# https://github.com/pypa/pip/blob/cc48c07b64f338ac5e347d90f6cb4efc22ed0d0b/src/pip/_internal/utils/unpacking.py#L240
for info in whl.infolist():
name = info.filename
# Do not attempt to modify directories.
if name.endswith("/") or name.endswith("\\"):
continue
mode = info.external_attr >> 16
# if mode and regular file and any execute permissions for
# user/group/world?
if mode and stat.S_ISREG(mode) and mode & 0o111:
name = os.path.join(directory, name)
set_extracted_file_to_default_mode_plus_executable(name)

# _parse_metadata parses METADATA files according to https://www.python.org/dev/peps/pep-0314/
def _parse_metadata(self, content):
Expand Down

0 comments on commit 6742ef2

Please sign in to comment.