Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

building: attempt to preserve parent directories for pywin32 extensions #7627

Merged
merged 2 commits into from May 13, 2023

Commits on May 13, 2023

  1. building: post-process binaries TOC with work-arounds for pywin32

    At the end of the analysis process, post-process the `binaries`
    TOC and apply two work-arounds for the `pywin32` package on
    Windows.
    
    First, we now attempt to preserve the parent directory layout for
    `pywin32` extensions that are originally located in `win32` and
    `pythonwin` directories. The `pywin32.pth` places these directories
    into `sys.path`, so we end up seeing them as top-level modules,
    and collect them into `sys._MEIPASS`. However, some of these
    extensions might be linked to other extensions, and for those our
    binary dependency analysis would preserve the parent directory
    layout. So to keep things consistent, we now explicitly attempt
    to preserve the parent directory of extensons that were discovered
    by the modulegraph as well. This is done as post-processing step
    on the `binaries` TOC, and also requires us to add the
    sub-directories in question to `sys.path` in our bootstrap module
    for `pywin32`.
    
    The second work-around is specific to Anaconda `pywin32` package,
    which installs three copies of `pywintypes3X.dll` and `
    pythoncom3X.dll`, in the following locations:
    - Library/bin
    - Lib/site-packages/pywin32_system32
    - Lib/site-packages/win32
    
    So if, due to order of imports and library location search order,
    we end up collecting from `Library/bin` (into `sys._MEIPASS`) or
    from `Lib/site-packages/win32` (into `sys._MEIPASS/win32`), we need
    to explicitly change the destination directory to
    `sys._MEIPASS/pywin32_system32` to match the layout we expect.
    rokm committed May 13, 2023
    Configuration menu
    Copy the full SHA
    663f9f5 View commit details
    Browse the repository at this point in the history
  2. depend: bindepend: remove special handling for pywin32

    Remove the special handling for `pywin32` from dependency scanner's
    parent directory preservation mechanism. We had code in place that
    explicitly prevented directory preservation for dependent binaries
    from `pythonwin` directory.
    
    This was because we were collecting `win32uiole` extension from that
    directory into `sys._MEIPASS` (due to it being seen as top-level
    module, thanks to `pywin32.pth` adding the directory to `sys.path`);
    but the extension is linked against `win32ui` extension, so when
    discovered by dependency analysis of `win32uiole`, we would place it
    in the `pythonwin` directory. Thus, the two extensions would end
    up in different place, and `win32uiole` would refuse to load due to
    missing dependency.
    
    But now, our analysis/build process explicitly forces collection
    of extensions from `pythonwin` and `win32` to their original
    subdirectories (by means of `binaries` TOC post-processing), so
    it does not matter if we collect `win32ui` into the subdirectory;
    the `win32uiole` will also be placed next to it in the end.
    rokm committed May 13, 2023
    Configuration menu
    Copy the full SHA
    b1423ef View commit details
    Browse the repository at this point in the history