Commit 40aabe3f authored by Jason R. Coombs's avatar Jason R. Coombs Committed by GitHub

Merge pull request #1479 from jdufresne/bytes

Remove compatibility shim for bytes type
parents 318d6b02 4f165ed9
Remove internal use of six.binary_type
......@@ -3,14 +3,12 @@ Filename globbing utility. Mostly a copy of `glob` from Python 3.5.
Changes include:
* `yield from` and PEP3102 `*` removed.
* `bytes` changed to `six.binary_type`.
* Hidden files are not ignored.
"""
import os
import re
import fnmatch
from setuptools.extern.six import binary_type
__all__ = ["glob", "iglob", "escape"]
......@@ -92,7 +90,7 @@ def _iglob(pathname, recursive):
def glob1(dirname, pattern):
if not dirname:
if isinstance(pattern, binary_type):
if isinstance(pattern, bytes):
dirname = os.curdir.encode('ASCII')
else:
dirname = os.curdir
......@@ -129,8 +127,8 @@ def glob2(dirname, pattern):
# Recursively yields relative pathnames inside a literal directory.
def _rlistdir(dirname):
if not dirname:
if isinstance(dirname, binary_type):
dirname = binary_type(os.curdir, 'ASCII')
if isinstance(dirname, bytes):
dirname = os.curdir.encode('ASCII')
else:
dirname = os.curdir
try:
......@@ -149,7 +147,7 @@ magic_check_bytes = re.compile(b'([*?[])')
def has_magic(s):
if isinstance(s, binary_type):
if isinstance(s, bytes):
match = magic_check_bytes.search(s)
else:
match = magic_check.search(s)
......@@ -157,7 +155,7 @@ def has_magic(s):
def _isrecursive(pattern):
if isinstance(pattern, binary_type):
if isinstance(pattern, bytes):
return pattern == b'**'
else:
return pattern == '**'
......@@ -169,7 +167,7 @@ def escape(pathname):
# Escaping is done by wrapping any of "*?[" between square brackets.
# Metacharacters do not work in the drive part and shouldn't be escaped.
drive, pathname = os.path.splitdrive(pathname)
if isinstance(pathname, binary_type):
if isinstance(pathname, bytes):
pathname = magic_check_bytes.sub(br'[\1]', pathname)
else:
pathname = magic_check.sub(r'[\1]', pathname)
......
import os
from setuptools.extern.six import binary_type
import pkg_resources.py31compat
......@@ -31,7 +30,7 @@ def build_files(file_defs, prefix=""):
pkg_resources.py31compat.makedirs(full_name, exist_ok=True)
build_files(contents, prefix=full_name)
else:
if isinstance(contents, binary_type):
if isinstance(contents, bytes):
with open(full_name, 'wb') as f:
f.write(contents)
else:
......
import pytest
from setuptools.glob import glob
from .files import build_files
@pytest.mark.parametrize('tree, pattern, matches', (
('', b'', []),
('', '', []),
('''
appveyor.yml
CHANGES.rst
LICENSE
MANIFEST.in
pyproject.toml
README.rst
setup.cfg
setup.py
''', '*.rst', ('CHANGES.rst', 'README.rst')),
('''
appveyor.yml
CHANGES.rst
LICENSE
MANIFEST.in
pyproject.toml
README.rst
setup.cfg
setup.py
''', b'*.rst', (b'CHANGES.rst', b'README.rst')),
))
def test_glob(monkeypatch, tmpdir, tree, pattern, matches):
monkeypatch.chdir(tmpdir)
build_files({name: '' for name in tree.split()})
assert list(sorted(glob(pattern))) == list(sorted(matches))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment