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

refactor(Photoshop): Restructure logic that establishes a Dispatch object #318

Merged
merged 6 commits into from
Nov 8, 2023

Conversation

Investigamer
Copy link
Contributor

@Investigamer Investigamer commented Nov 5, 2023

Motivation for this Commit

After the popularity of Photoshop Beta due to the Generative Fill feature, as well as the Photoshop version rollover from v24 to v25, there has been increased occurrence of strange issues such as:

  • Failing to establish a valid Dispatch object, despite Photoshop being installed
  • Resolving Dispatch objects that conflict with one another, likely due to a version conflict i.e. having two versions of Photoshop installed, or having lingering registry data from an uninstalled version of Photoshop.
  • Other issues I've been unable to diagnose but we've seen on multiple users' systems. Some of these probably stem from "cracked" Photoshop installations that improperly install registry data, however I've personally seen cases where the registry entries appear to be fine and issues persist.
  • Some of these issues remain a mystery and require further investigation, some may be unfixable (for example, entirely missing registry data due to a portable or poorly designed "cracked" Photoshop installation, these are not our responsibility).

Goals of this Commit

  • Restructure the sequence of events that attempt to resolve a valid Dispatch object in Photoshop.__init__(), ensuring the sequence is optimized. My current solution:
    • Check if a Photoshop version was provided manually. If valid, attempt to resolve a Dispatch object using this version.
    • Pull a list of version ID strings found in registry data (e.g. 170, 180, etc), add a final fallback case of empty string.
    • For each version ID (in descending order) attempt to resolve a Dispatch object, with the last attempt being an empty version (e.g. Photoshop.Application).
    • Finally, if all attempts to resolve a Dispatch object fail, raise a PhotoshopPythonAPIError.
  • Implement an internal logger for providing optional debug warnings, which can be toggled with environment variable 'PS_DEBUG' ahead of time.
  • Refactor and simplify code for readability, make small adjustments to improve efficiency.
  • Adjust the nomenclature of a couple internal attributes and methods.
  • Reinforce docstrings and type declarations.

Note on Limitations

These changes surely don't address every Dispatch related issue we've seen, and unfortunately I cannot replicate many of these reported issues on a local system, so its impossible for me to test each scenario. Nevertheless, I put in a few days of deep dive research into the topic, and I'm confident my proposed methodology is a step in the right direction.

@Investigamer Investigamer force-pushed the main branch 3 times, most recently from b076c6f to 4f477c0 Compare November 5, 2023 03:33
@Investigamer
Copy link
Contributor Author

Investigamer commented Nov 5, 2023

Additional Commit: application.py

  • Wrap failed app.colorSettings setter call with human readable exception
  • Allow app.load() to receive str or Path
  • Fix app.purge() docstring to match definitions in PurgeTarget
  • Reinforce type declarations and improve docstring grammar

… initialize a valid Dispatch object

The goal of restructuring is to hopefully reduce the recent issues arising from broken or mismatched registry data that results in the API failing to establish a valid Dispatch object. These recent occurences appear to coincide with Photoshop's rollover to v25 and the occurence of mixed registry data between Photoshop and Photoshop beta. This commit also attempts to refactor for readability and performance. Additionally: I deprecated the use of `GetActiveObject`, at the time I introduced it I didn't realize this spawner *only* seems to work for the initial Application object, so spawning any other object (ActionDescriptor, SolidCOlor, etc) just pads the execution time with zero benefit. We should definitely cut it loose.

Signed-off-by: MrTeferi <[email protected]>
…ath objects for app.load, wrap colorSettings exceptions

Additionally make some grammar corrections and reinforce type declarations

Signed-off-by: MrTeferi <[email protected]>
@Investigamer Investigamer changed the title refactor(Photoshop) Restructure logic that establishes a Dispatch object refactor(Photoshop): Restructure logic that establishes a Dispatch object Nov 5, 2023
…), add support for Python 3.12

Additionally attempt to fix mkdocs error

Signed-off-by: MrTeferi <[email protected]>
@Investigamer
Copy link
Contributor Author

Investigamer commented Nov 6, 2023

Additional Commit: Deprecate Python 3.7

  • I recommend we move to deprecate support of Python 3.7 since it reached End of Life earlier this year. Currently my commit is not compatible with Python 3.7 since @cached_property wasn't implemented until 3.8. I went ahead and removed Python 3.7 from our workflows and project files, let me know if you prefer to try and maintain support for 3.7 and I will reverse this change and find a replacement for my @cached_property solution. 👍
  • Fixed an error when trying to publish docs with mkdocs, appears to be caused by an outdated version of importlib_metadata.
  • Added support for Python 3.12 to workflows and project files. Python 3.12 appears to work just fine with the API on my system and has passed the import test workflow!
  • Fixed circular import error

@loonghao loonghao merged commit 235c2d0 into loonghao:main Nov 8, 2023
9 checks passed
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.

2 participants