Skip to content

Commit

Permalink
Removing glob2 and replacing with glob(,recursive=True) where used. (#…
Browse files Browse the repository at this point in the history
…5005)

Co-authored-by: Jannis Leidel <[email protected]>
Co-authored-by: Bianca Henderson <[email protected]>
Co-authored-by: Ken Odegard <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Sep 25, 2023
1 parent ed0ddcc commit ce91aa5
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 32 deletions.
9 changes: 4 additions & 5 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from os.path import dirname, isdir, isfile, islink, join

import conda_package_handling.api
import glob2
import yaml
from bs4 import UnicodeDammit
from conda import __version__ as conda_version
Expand Down Expand Up @@ -1203,11 +1202,11 @@ def get_files_with_prefix(m, replacements, files_in, prefix):
for index, replacement in enumerate(replacements):
all_matches = have_regex_files(
files=[
f
for f in files
file
for file in files
if any(
glob2.fnmatch.fnmatch(f, r)
for r in replacement["glob_patterns"]
fnmatch.fnmatch(file, pattern)
for pattern in replacement["glob_patterns"]
)
],
prefix=prefix,
Expand Down
4 changes: 2 additions & 2 deletions conda_build/cli/main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import logging
import sys
import warnings
from glob import glob
from itertools import chain
from os.path import abspath, expanduser, expandvars
from pathlib import Path

import filelock
from conda.auxlib.ish import dals
from conda.common.io import dashlist
from glob2 import glob

from .. import api, build, source, utils
from ..conda_interface import add_parser_channels, binstar_upload, cc_conda_build
Expand Down Expand Up @@ -542,7 +542,7 @@ def execute(args):
outputs = []
failed_recipes = []
recipes = chain.from_iterable(
glob(abspath(recipe)) if "*" in recipe else [recipe]
glob(abspath(recipe), recursive=True) if "*" in recipe else [recipe]
for recipe in args.recipe
)
for recipe in recipes:
Expand Down
5 changes: 2 additions & 3 deletions conda_build/os_utils/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import os
import stat
import sys
from glob import glob
from os.path import expanduser, isfile, join

from glob2 import glob

from conda_build.conda_interface import root_dir


Expand Down Expand Up @@ -55,7 +54,7 @@ def find_executable(executable, prefix=None, all_matches=False):
result = path
break
if not result and any([f in executable for f in ("*", "?", ".")]):
matches = glob(os.path.join(dir_path, executable))
matches = glob(os.path.join(dir_path, executable), recursive=True)
if matches:
if all_matches:
all_matches_found.extend(matches)
Expand Down
7 changes: 3 additions & 4 deletions conda_build/os_utils/liefldd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import struct
import sys
import threading
from fnmatch import fnmatch
from functools import partial
from subprocess import PIPE, Popen

import glob2

from .external import find_executable

# lief cannot handle files it doesn't know about gracefully
Expand Down Expand Up @@ -146,15 +145,15 @@ def _set_elf_rpathy_thing(binary, old_matching, new_rpath, set_rpath, set_runpat
if (
set_runpath
and e.tag == lief.ELF.DYNAMIC_TAGS.RUNPATH
and glob2.fnmatch.fnmatch(e.runpath, old_matching)
and fnmatch(e.runpath, old_matching)
and e.runpath != new_rpath
):
e.runpath = new_rpath
changed = True
elif (
set_rpath
and e.tag == lief.ELF.DYNAMIC_TAGS.RPATH
and glob2.fnmatch.fnmatch(e.rpath, old_matching)
and fnmatch(e.rpath, old_matching)
and e.rpath != new_rpath
):
e.rpath = new_rpath
Expand Down
22 changes: 7 additions & 15 deletions conda_build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@

import urllib.parse as urlparse
import urllib.request as urllib
from glob import glob as glob_glob
from contextlib import ExitStack # noqa: F401
from glob import glob

from conda.api import PackageCacheData # noqa

Expand Down Expand Up @@ -91,15 +92,6 @@
win_path_to_unix,
)


# stdlib glob is less feature-rich but considerably faster than glob2
def glob(pathname, recursive=True):
return glob_glob(pathname, recursive=recursive)


# NOQA because it is not used in this file.
from contextlib import ExitStack # NOQA

PermissionError = PermissionError # NOQA
FileNotFoundError = FileNotFoundError

Expand Down Expand Up @@ -1037,7 +1029,7 @@ def get_stdlib_dir(prefix, py_ver):
lib_dir = os.path.join(prefix, "Lib")
else:
lib_dir = os.path.join(prefix, "lib")
python_folder = glob(os.path.join(lib_dir, "python?.*"))
python_folder = glob(os.path.join(lib_dir, "python?.*"), recursive=True)
python_folder = sorted(filterfalse(islink, python_folder))
if python_folder:
lib_dir = os.path.join(lib_dir, python_folder[0])
Expand All @@ -1052,7 +1044,7 @@ def get_site_packages(prefix, py_ver):

def get_build_folders(croot):
# remember, glob is not a regex.
return glob(os.path.join(croot, "*" + "[0-9]" * 10 + "*"))
return glob(os.path.join(croot, "*" + "[0-9]" * 10 + "*"), recursive=True)


def prepend_bin_path(env, prefix, prepend_prefix=False):
Expand Down Expand Up @@ -1085,7 +1077,7 @@ def sys_path_prepended(prefix):
sys.path.insert(1, os.path.join(prefix, "lib", "site-packages"))
else:
lib_dir = os.path.join(prefix, "lib")
python_dir = glob(os.path.join(lib_dir, r"python[0-9\.]*"))
python_dir = glob(os.path.join(lib_dir, r"python[0-9\.]*"), recursive=True)
if python_dir:
python_dir = python_dir[0]
sys.path.insert(1, os.path.join(python_dir, "site-packages"))
Expand Down Expand Up @@ -1327,7 +1319,7 @@ def expand_globs(path_list, root_dir):
files.append(os.path.join(root, folder))
else:
# File compared to the globs use / as separator independently of the os
glob_files = glob(path)
glob_files = glob(path, recursive=True)
if not glob_files:
log = get_logger(__name__)
log.error(f"Glob {path} did not match in root_dir {root_dir}")
Expand Down Expand Up @@ -1457,7 +1449,7 @@ def get_installed_packages(path):
Files are assumed to be in 'index.json' format.
"""
installed = dict()
for filename in glob(os.path.join(path, "conda-meta", "*.json")):
for filename in glob(os.path.join(path, "conda-meta", "*.json"), recursive=True):
with open(filename) as file:
data = json.load(file)
installed[data["name"]] = data
Expand Down
3 changes: 3 additions & 0 deletions news/4792-remove-glob2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Enhancements

* Remove `glob2` as a dependency. As of Python 3.5, the '**', operator was available to glob when using `recursive=True`. Builtin glob is also much faster. (#5005)
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ dependencies = [
"conda-index",
"conda-package-handling >=1.3",
"filelock",
"glob2 >=0.6",
"jinja2",
"libarchive-c",
"packaging",
Expand Down
1 change: 0 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ requirements:
- conda-index
- conda-package-handling >=1.3
- filelock
- glob2 >=0.6
- jinja2
- m2-patch >=2.6 # [win]
- packaging
Expand Down
1 change: 0 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ contextlib2
cytoolz
filelock
git
glob2 >=0.6
jinja2
numpy
perl
Expand Down

0 comments on commit ce91aa5

Please sign in to comment.