Skip to content

Prefix replacement with ripgrep might fail on long paths on Windows #4357

Open

Description

Comes from conda-forge/staged-recipes#17519 (comment)

Actual Behavior

Prefix replacement fails with too long paths on Windows if ripgrep is used. The exception is not caught as it should because the subprocess is never launched:

INFO:conda_build.build:Packaging openfisca-france
Packaging openfisca-france
INFO conda_build.build:build(2289): Packaging openfisca-france
INFO:conda_build.build:Packaging openfisca-france-102.0.0-pyh6c4a22f_0
Packaging openfisca-france-102.0.0-pyh6c4a22f_0
INFO conda_build.build:bundle_conda(1529): Packaging openfisca-france-102.0.0-pyh6c4a22f_0
number of files: 2713
Fixing permissions
Packaged license file/s.
Traceback (most recent call last):
  File "D:\a\1\s\.ci_support\build_all.py", line 198, in <module>
    build_all(os.path.join(root_dir, "recipes"), args.arch)
  File "D:\a\1\s\.ci_support\build_all.py", line 101, in build_all
    build_folders(recipes_dir, folders, arch, channel_urls)
  File "D:\a\1\s\.ci_support\build_all.py", line 157, in build_folders
    conda_build.api.build([recipe], config=get_config(arch, channel_urls))
  File "C:\Miniconda\lib\site-packages\conda_build\api.py", line 186, in build
    return build_tree(
  File "C:\Miniconda\lib\site-packages\conda_build\build.py", line 3083, in build_tree
    packages_from_this = build(metadata, stats,
  File "C:\Miniconda\lib\site-packages\conda_build\build.py", line 2366, in build
    newly_built_packages = bundlers[pkg_type](output_d, m, env, stats)
  File "C:\Miniconda\lib\site-packages\conda_build\build.py", line 1672, in bundle_conda
    output['checksums'] = create_info_files(metadata, replacements, files, prefix=metadata.config.host_prefix)
  File "C:\Miniconda\lib\site-packages\conda_build\build.py", line 1285, in create_info_files
    files_with_prefix = get_files_with_prefix(m, replacements, files, prefix)
  File "C:\Miniconda\lib\site-packages\conda_build\build.py", line 949, in get_files_with_prefix
    pfx_matches = have_regex_files([f[2] for f in files_with_prefix], prefix=prefix,
  File "C:\Miniconda\lib\site-packages\conda_build\build.py", line 526, in have_regex_files
    match_records_rg = regex_files_rg(files, prefix, tag,
  File "C:\Miniconda\lib\site-packages\conda_build\build.py", line 324, in regex_files_rg
    raise e
  File "C:\Miniconda\lib\site-packages\conda_build\build.py", line 317, in regex_files_rg
    matches = subprocess.check_output(args, shell=False).rstrip(b'\n').split(b'\n')
  File "C:\Miniconda\lib\subprocess.py", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Miniconda\lib\subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Miniconda\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Miniconda\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 206] The filename or extension is too long

Expected Behavior

Long paths should be handled correctly or, if impossible, fallback safely to the Python implementation. Also, right now, this performance trick is either all-in or nothing. There's no logic to accept individual file errors on the ripgrep approach.

Uninstalling ripgrep or mangling rg path disables this code path and makes everything work at a lower performance.

Steps to Reproduce

Use this recipe.

Full CI logs: full_log.txt

Output of conda info
     active environment : base
    active env location : C:\Miniconda
            shell level : 1
       user config file : C:\Users\VssAdministrator\.condarc
 populated config files : C:\Miniconda\.condarc
                          C:\Users\VssAdministrator\.condarc
          conda version : 4.11.0
    conda-build version : 3.21.7
         python version : 3.9.9.final.0
       virtual packages : __win=0=0
                          __archspec=1=x86_64
       base environment : C:\Miniconda  (writable)
      conda av data dir : C:\Miniconda\etc\conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/win-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : C:\Miniconda\pkgs
                          C:\Users\VssAdministrator\.conda\pkgs
                          C:\Users\VssAdministrator\AppData\Local\conda\conda\pkgs
       envs directories : C:\Miniconda\envs
                          C:\Users\VssAdministrator\.conda\envs
                          C:\Users\VssAdministrator\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/4.11.0 requests/2.27.1 CPython/3.9.9 Windows/10 Windows/10.0.17763
          administrator : True
             netrc file : None
           offline mode : False

==> C:\Miniconda\.condarc <==
aggressive_update_packages:
  - ca-certificates
  - certifi
channels:
  - conda-forge
show_channel_urls: True

==> C:\Users\VssAdministrator\.condarc <==
add_pip_as_python_dependency: False
auto_update_conda: False
channel_priority: strict
channels:
  - conda-forge
show_channel_urls: True

==> envvars <==
bld_path: C:\\bld\\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    backlogissue has been triaged but has not been earmarked for any upcoming releaseos::windowsrelevant to Windowssource::partnercreated by or for an Anaconda, Inc. partner companystale::recovered[bot] recovered after being marked as staletype::bugdescribes erroneous operation, use severity::* to classify the type

    Type

    No type

    Projects

    • Status

      🏗️ In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions