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

[Plugin] Unable to load using absolute path #726

Open
moham96 opened this issue Nov 11, 2021 · 5 comments
Open

[Plugin] Unable to load using absolute path #726

moham96 opened this issue Nov 11, 2021 · 5 comments
Labels
Bug Bug report in proxy server Good First Issue Issues for new contributors to pick-up

Comments

@moham96
Copy link

moham96 commented Nov 11, 2021

Describe the bug
This states that one can load a plugin simply by using the absolute path for the plugin but it's not working for me

python -m proxy --log-level d --ca-key-file ca-key.pem --ca-cert-file ca-cert.pem --ca-signing-key-file ca-signing-key.pem --plugins /home/mohammad/repos/plugintest/proxyPlugin.proxyPlugin
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/mohammad/repos/proxy.py/proxy/__main__.py", line 14, in <module>
    entry_point()
  File "/home/mohammad/repos/proxy.py/proxy/proxy.py", line 176, in entry_point
    main(input_args=sys.argv[1:])
  File "/home/mohammad/repos/proxy.py/proxy/proxy.py", line 155, in main
    with Proxy(input_args=input_args, **opts):
  File "/home/mohammad/repos/proxy.py/proxy/proxy.py", line 105, in __init__
    self.flags = FlagParser.initialize(input_args, **opts)
  File "/home/mohammad/repos/proxy.py/proxy/common/flag.py", line 100, in initialize
    Plugins.discover(input_args)
  File "/home/mohammad/repos/proxy.py/proxy/common/plugins.py", line 38, in discover
    Plugins.importer(bytes_(part))
  File "/home/mohammad/repos/proxy.py/proxy/common/plugins.py", line 75, in importer
    importlib.import_module(
  File "/usr/lib/python3.9/importlib/__init__.py", line 122, in import_module
    raise TypeError(msg.format(name))
TypeError: the 'package' argument is required to perform a relative import for '.home.mohammad.repos.plugintest.proxyPlugin'

To Reproduce
Steps to reproduce the behavior:
1- create a simple plugin in a directory outside proxy.py tree for me i created a directory at /home/mohammad/repos/plugintest/ that contains a file named proxyPlugin.py the file contains a plugin class named proxyPlugin
2. Run proxy.py as python -m proxy --log-level d --ca-key-file ca-key.pem --ca-cert-file ca-cert.pem --ca-signing-key-file ca-signing-key.pem --plugins /home/mohammad/repos/plugintest/proxyPlugin.proxyPlugin
3- The following exception is raised TypeError: the 'package' argument is required to perform a relative import for '.home.mohammad.repos.plugintest.proxyPlugin'

Expected behavior
According to the README.md file using the absolute path for the plugin should work just fine

Version information

  • OS: Manjaro linux

  • Device: Desktop pc

  • proxy.py version: git version

@moham96 moham96 added the Bug Bug report in proxy server label Nov 11, 2021
@abhinavsingh
Copy link
Owner

@moham96 IIRC, relative imports are not allowed within plugins. I might have to double check on this, but can you try to make your imports absolute and give it a try. If necessary add your plugin module as PYTHONPATH too. Let me know.

@abhinavsingh abhinavsingh changed the title loading plugin using absolute path not working [Plugin] Unable to load using absolute path Nov 11, 2021
@abhinavsingh
Copy link
Owner

You can also try:

PYTHONPATH=/home/mohammad/repos/plugintest proxy --plugins proxyPlugin.proxyPlugin

Ref: https://github.com/abhinavsingh/proxy.py#unable-to-load-plugins

@moham96
Copy link
Author

moham96 commented Nov 11, 2021

You can also try:

PYTHONPATH=/home/mohammad/repos/plugintest proxy --plugins proxyPlugin.proxyPlugin

Ref: https://github.com/abhinavsingh/proxy.py#unable-to-load-plugins

using PYTHONPATH works fine, but the entry in the README file suggest that it is possible to use the absolute path without setting the PYTHONPATH variable

@abhinavsingh
Copy link
Owner

using PYTHONPATH works fine, but the entry in the README file suggest that it is possible to use the absolute path without setting the PYTHONPATH variable

Correct. In my tests it worked while documenting. But IIRC, I was using absolute imports in my external plugin. Probably, I we must update the README with relevant context. If you wish, please send out a PR.

@abhinavsingh
Copy link
Owner

TypeError: the 'package' argument is required to perform a relative import for '.home.mohammad.repos.plugintest.proxyPlugin'

Can double confirm, absolute path currently doesn't work as advertised. I think code got broken at some point, because this used to work. Let's keep this open until fixed. Thank you again for reporting it.

@abhinavsingh abhinavsingh added Plugin Related to plugin code (not core) and removed Plugin Related to plugin code (not core) labels Nov 18, 2021
@abhinavsingh abhinavsingh pinned this issue Nov 18, 2021
@abhinavsingh abhinavsingh added the Good First Issue Issues for new contributors to pick-up label Dec 22, 2021
@abhinavsingh abhinavsingh removed their assignment Dec 27, 2021
@abhinavsingh abhinavsingh unpinned this issue Jan 25, 2022
@abhinavsingh abhinavsingh pinned this issue Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug report in proxy server Good First Issue Issues for new contributors to pick-up
Projects
None yet
Development

No branches or pull requests

3 participants
@abhinavsingh @moham96 and others