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

Replace all external programs/libraries with Python extensions #87

Merged
merged 4 commits into from
Dec 12, 2022

Conversation

zao
Copy link
Collaborator

@zao zao commented May 30, 2022

Abstract

PyPoE currently has several implicit external dependencies for tasks:

  1. ooz.exe/libooz.dll for decompressing game data;
  2. process-image.exe from poe-utils for converting and slicing BC7 and other modern DDS pixel formats to PNGs;
  3. convert.exe/magick.exe from ImageMagick for DDS decoding and compositing/coloring of map items and atlas sigils.

These must be manually installed and sometimes even built by the end user before some parts of the software are operable and it's not immediately obvious where this is documented.

Action Taken

ooz has been replaced with a Python extension (https://pypi.org/project/pyooz/) built on the same codebase.
poe-utils has been replaced with a Python extension (https://pypi.org/project/pydds/) ported from the same codebase leveraging GLI for DDS scaffolding and Compressonator's cmp_core for decompressing BCn formats.
ImageMagick has been replaced with Pillow package (https://pypi.org/project/Pillow/) for and the pydds extension.

Caveats

As the map compositing was approximate I took the opportunity to improve the coloring and blending of map sigils onto the map base item, producing an outcome closer to what is seen in game. Map item icons on the wiki should probably be regenerated to be consistent and prettier.

As this adds new packages both as base install requirements and as extras requirements for cli, a development installation of PyPoE may need to be reinstalled to apply these changes in requirements.
pydds and pyooz were authored and uploaded by @zao to PyPI as a source dist and binary wheels. While there's a full set of wheels for macOS, Windows and Linux there might be a need to build more wheels in the future when new Python versions are released. As a fallback the source dists ought to build out of the box but requires the person installing them to have C++ build tools installed for their Python.

Despite being core tech unrelated to PoE releases this PR is made against patches as it touches code that has had improvements made in patches since the last dev merge.

FAO

@angelic-knight @pm5k

zao added 3 commits May 25, 2022 16:54
With usable prebuilt bindings to ooz decompression at https://pypi.org/project/pyooz/ we can unify decompression across all platforms, removing the need for manual adding of `ooz.exe` or `libooz.dll` to the execution environment. This should make PyPoE more self-contained and has the benefit of being able to decompress without intermediary files on non-Windows platforms.
With the porting of `process-image` from poe-utils to a Python extension at https://pypi.org/project/pydds/ we can now remove all subprocess invocations of both ImageMagick and `process-image`. This change still writes a number of intermediary files to disk and could be optimized to keep them in memory in some circumstances.
@zao zao changed the title Patches no subprocess Replace all external programs/libraries with Python extensions May 30, 2022
Comment on lines +1549 to +1550
with open(out_path, 'wb') as f:
f.write(self.file_system.extract_dds(data))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could import Path from pathlib to make use of Path's built-in context manager to avoid this.
Instead the whole thing could be written as:

Path(out_path).write_text | .write_bytes (self.file_system.extract_dds(data))

Comment on lines +4128 to +4129
img = Image.open(ico)
img.save(ico)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not familiar with this. Why is the image saved after being just opened?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The save here is indeed superfluous, I was probably trying to keep the same disk I/O as the original version as I don't know which files are temporary and which ones are expected to be there for further editor work or upload.

@AlphSpirit AlphSpirit added this to the 3.19 MVP milestone Dec 5, 2022
@pm5k pm5k deleted the branch Project-Path-of-Exile-Wiki:dev December 9, 2022 19:28
@pm5k pm5k closed this Dec 9, 2022
@pm5k pm5k reopened this Dec 9, 2022
@pm5k pm5k changed the base branch from patches to dev December 9, 2022 19:42
@pm5k pm5k merged commit c361632 into Project-Path-of-Exile-Wiki:dev Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants