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

ue4cli depends on 'pkg_resources' which prevents it from running on vanilla python #71

Open
sleeptightAnsiC opened this issue May 10, 2024 · 1 comment

Comments

@sleeptightAnsiC
Copy link
Contributor

sleeptightAnsiC commented May 10, 2024

Looks like I missed this one during #59

ue4cli still depends on package outside of vanilla python and cannot be run directly from source without it:

$ python ~/ue4cli
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/korn/ue4cli/__main__.py", line 1, in <module>
    from ue4cli.cli import main
  File "/home/korn/ue4cli/ue4cli/cli.py", line 2, in <module>
    from .PluginManager import PluginManager
  File "/home/korn/ue4cli/ue4cli/PluginManager.py", line 2, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

For now, I only spotted pkg_resources (provided by setuptools) which is used in two places:

  1. pkg_resources.iter_entry_points
    # Retrieve the list of detected entry points in the ue4cli.plugins group
    plugins = {
    entry_point.name: entry_point.load()
    for entry_point
    in pkg_resources.iter_entry_points('ue4cli.plugins')
    }
  2. pkg_resources.parse_version
    def _editorPathSuffix(self, cmdVersion):
    version = parse_version(self.getEngineVersion())
    if version < parse_version('5.0.0'):
    return '.app/Contents/MacOS/UE4Editor'
    else:
    return '.app/Contents/MacOS/UnrealEditor'
    def _transformBuildToolPlatform(self, platform):
    # Prior to 4.22.2, Build.sh under Mac requires "macosx" as the platform name for macOS
    version = parse_version(self.getEngineVersion())
    return 'macosx' if platform == 'Mac' and version < parse_version('4.22.2') else platform

First one is tricky, we have to use it for loading ue4cli-plugins which is invoked in ue4cli/cli.py.
Second one should be fairly easy to replace (I hope).

TODO:
I gotta make sure there is no more dependencies like this one and find good workaround for this.
Perhaps we can try; import pkg_resources: and load ue4cli-plugins only if said dependency is resolved.

Either way, I'll probably take this one :)

@sleeptightAnsiC
Copy link
Contributor Author

sleeptightAnsiC commented Aug 11, 2024

Potential fix for 1.
This already makes it work on Windows and Linux

diff --git a/ue4cli/PluginManager.py b/ue4cli/PluginManager.py
index e157394..8df7b13 100644
--- a/ue4cli/PluginManager.py
+++ b/ue4cli/PluginManager.py
@@ -1,5 +1,14 @@
 from inspect import signature
-import pkg_resources
+from .Utility import Utility
+
+# HACK: dummy iter_entry_points in case package 'setuptools' hasn't been provided
+try:
+	from pkg_resources import iter_entry_points
+except ModuleNotFoundError as e:
+	Utility.printStderr(f'Warning: ue4cli plugins are unavailable due to: {str(e)}')
+	def iter_entry_points(unused):
+		return {}
+
 
 class PluginManager:
 	"""
@@ -16,7 +25,7 @@ class PluginManager:
 		plugins = {
 			entry_point.name: entry_point.load()
 			for entry_point
-			in pkg_resources.iter_entry_points('ue4cli.plugins')
+			in iter_entry_points('ue4cli.plugins')
 		}
 		
 		# Filter out any invalid plugins

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

No branches or pull requests

1 participant