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

Relative import error related to the importlib_metadata/__init__.py file #844

Open
atos-ghassen-bchir opened this issue Jan 5, 2022 · 7 comments

Comments

@atos-ghassen-bchir
Copy link

After upgrading from v0.12.10 to v0.13.3, we noticed a new error:
`
File "/ws/.venv/lib/python3.8/site-packages/pybuilder/_vendor/importlib_metadata/init.py", line 6, in
from .. import zipp
ValueError: attempted relative import beyond top-level package

--------------------------------------------------------------------------------`

This importlib_metadata seems to have been added in v0.13.0

@arcivanov
Copy link
Member

Thanks for your report. Is there a reproducible case?

@arcivanov
Copy link
Member

Could you please provide the logs as well?

@arcivanov
Copy link
Member

@atos-ghassen-bchir Could you please provide the full logs?

@atos-ghassen-bchir
Copy link
Author

atos-ghassen-bchir commented Jan 11, 2022

@arcivanov sorry for the delay. Unfortunately, I still have not found a simple case to reproduce. So far, it seems that the error appears in the following case:

  • In the build.py I have a dependency on importlib_metadata
  • When I upgraded pybuilder v0.12.10 to v0.13.3, the importlib_metadata/init.py file was added
  • The python interpreter then calls this file when I run "import importlib_metadata" in my own code (see logs below)

Here are the full logs. I still have untangled this on my side. The only ways I found to get rid of that error are:

  • By going into pybuilder's importlib_metadata/init.py file and replace "from .. import zipp" by "import zipp" (not a real solution, just an attempt to understand what's going on)
  • By not calling importlib_metadata in my own code...
`[2022-01-06T21:33:27.710830 *** Starting test: myTest in class: TestParams ***]

Invalid argument(s). Please use --help command./ws/target/venv/build/cpython-3.8.12.final.0/lib/python3.8/site-packages/marshmallow_dataclass/__init__.py:330: UserWarning: ****** WARNING ****** marshmallow_dataclass was called on the class <class 'sortedcontainers.sortedlist.SortedKeyList'>, which is not a dataclass. It is going to try and convert the class into a dataclass, which may have undesirable side effects. To avoid this message, make sure all your classes and all the classes of their fields are either explicitly supported by marshmallow_dataclass, or define the schema explicitly using field(metadata=dict(marshmallow_field=...)). For more information, see https://github.com/lovasoa/marshmallow_dataclass/issues/51 ****** WARNING ******
  warnings.warn(


--------------------------------------------------------------------------------
LokyProcess-1:118 failed with traceback: 
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/ws/target/venv/build/cpython-3.8.12.final.0/lib/python3.8/site-packages/joblib/externals/loky/backend/popen_loky_posix.py", line 199, in <module>
    process_obj = pickle.load(from_parent)
  File "/ws/src/main/python/[myproject_path]/joblib_backend/context_initializer/monitor_initializer.py", line 14, in <module>
    from my_module.learning.learning.learning import Learning
  File "/ws/src/main/python/[myproject_path]/learning/learning/learning.py", line 33, in <module>
    from my_module.learning.learning.sigterm_context_manager import SigTermContextManager
  File "/ws/src/main/python/[myproject_path]/learning/learning/sigterm_context_manager.py", line 17, in <module>
    from my_module.monitor.learning_reporter import LearningStoppedRecord
  File "/ws/src/main/python/[myproject_path]/monitor/learning_reporter.py", line 24, in <module>
    from my_module.libraries import get_libraries_version
  File "/ws/src/main/python/[myproject_path]/libraries.py", line 11, in <module>
    import importlib_metadata
  File "/ws/.venv/lib/python3.8/site-packages/pybuilder/_vendor/importlib_metadata/__init__.py", line 6, in <module>
    from .. import zipp
ValueError: attempted relative import beyond top-level package


--------------------------------------------------------------------------------
/ws/target/venv/build/cpython-3.8.12.final.0/lib/python3.8/site-packages/marshmallow_dataclass/__init__.py:330: UserWarning: ****** WARNING ****** marshmallow_dataclass was called on the class <class 'sortedcontainers.sortedlist.SortedKeyList'>, which is not a dataclass. It is going to try and convert the class into a dataclass, which may have undesirable side effects. To avoid this message, make sure all your classes and all the classes of their fields are either explicitly supported by marshmallow_dataclass, or define the schema explicitly using field(metadata=dict(marshmallow_field=...)). For more information, see https://github.com/lovasoa/marshmallow_dataclass/issues/51 ****** WARNING ******
  warnings.warn(


--------------------------------------------------------------------------------
LokyProcess-1:120 failed with traceback: 
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/ws/target/venv/build/cpython-3.8.12.final.0/lib/python3.8/site-packages/joblib/externals/loky/backend/popen_loky_posix.py", line 199, in <module>
    process_obj = pickle.load(from_parent)
  File "/ws/src/main/python/[myproject_path]/joblib_backend/context_initializer/monitor_initializer.py", line 14, in <module>
    from my_module.learning.learning.learning import Learning
  File "/ws/src/main/python/[myproject_path]/learning/learning/learning.py", line 33, in <module>
    from my_module.learning.learning.sigterm_context_manager import SigTermContextManager
  File "/ws/src/main/python/[myproject_path]/learning/learning/sigterm_context_manager.py", line 17, in <module>
    from my_module.monitor.learning_reporter import LearningStoppedRecord
  File "/ws/src/main/python/[myproject_path]/monitor/learning_reporter.py", line 24, in <module>
    from my_module.libraries import get_libraries_version
  File "/ws/src/main/python/[myproject_path]/libraries.py", line 11, in <module>
    import importlib_metadata
  File "/ws/.venv/lib/python3.8/site-packages/pybuilder/_vendor/importlib_metadata/__init__.py", line 6, in <module>
    from .. import zipp
ValueError: attempted relative import beyond top-level package


--------------------------------------------------------------------------------
/ws/target/venv/build/cpython-3.8.12.final.0/lib/python3.8/site-packages/marshmallow_dataclass/__init__.py:330: UserWarning: ****** WARNING ****** marshmallow_dataclass was called on the class <class 'sortedcontainers.sortedlist.SortedKeyList'>, which is not a dataclass. It is going to try and convert the class into a dataclass, which may have undesirable side effects. To avoid this message, make sure all your classes and all the classes of their fields are either explicitly supported by marshmallow_dataclass, or define the schema explicitly using field(metadata=dict(marshmallow_field=...)). For more information, see https://github.com/lovasoa/marshmallow_dataclass/issues/51 ****** WARNING ******
  warnings.warn(


--------------------------------------------------------------------------------
LokyProcess-1:119 failed with traceback: 
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/ws/target/venv/build/cpython-3.8.12.final.0/lib/python3.8/site-packages/joblib/externals/loky/backend/popen_loky_posix.py", line 199, in <module>
    process_obj = pickle.load(from_parent)
  File "/ws/src/main/python/[myproject_path]/joblib_backend/context_initializer/monitor_initializer.py", line 14, in <module>
    from my_module.learning.learning.learning import Learning
  File "/ws/src/main/python/[myproject_path]/learning/learning/learning.py", line 33, in <module>
    from my_module.learning.learning.sigterm_context_manager import SigTermContextManager
  File "/ws/src/main/python/[myproject_path]/learning/learning/sigterm_context_manager.py", line 17, in <module>
    from my_module.monitor.learning_reporter import LearningStoppedRecord
  File "/ws/src/main/python/[myproject_path]/monitor/learning_reporter.py", line 24, in <module>
    from my_module.libraries import get_libraries_version
  File "/ws/src/main/python/[myproject_path]/libraries.py", line 11, in <module>
    import importlib_metadata
  File "/ws/.venv/lib/python3.8/site-packages/pybuilder/_vendor/importlib_metadata/__init__.py", line 6, in <module>
    from .. import zipp
ValueError: attempted relative import beyond top-level package


--------------------------------------------------------------------------------
/ws/target/venv/build/cpython-3.8.12.final.0/lib/python3.8/site-packages/marshmallow_dataclass/__init__.py:330: UserWarning: ****** WARNING ****** marshmallow_dataclass was called on the class <class 'sortedcontainers.sortedlist.SortedKeyList'>, which is not a dataclass. It is going to try and convert the class into a dataclass, which may have undesirable side effects. To avoid this message, make sure all your classes and all the classes of their fields are either explicitly supported by marshmallow_dataclass, or define the schema explicitly using field(metadata=dict(marshmallow_field=...)). For more information, see https://github.com/lovasoa/marshmallow_dataclass/issues/51 ****** WARNING ******
  warnings.warn(


--------------------------------------------------------------------------------
LokyProcess-1:121 failed with traceback: 
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/ws/target/venv/build/cpython-3.8.12.final.0/lib/python3.8/site-packages/joblib/externals/loky/backend/popen_loky_posix.py", line 199, in <module>
    process_obj = pickle.load(from_parent)
  File "/ws/src/main/python/[myproject_path]/joblib_backend/context_initializer/monitor_initializer.py", line 14, in <module>
    from my_module.learning.learning.learning import Learning
  File "/ws/src/main/python/[myproject_path]/learning/learning/learning.py", line 33, in <module>
    from my_module.learning.learning.sigterm_context_manager import SigTermContextManager
  File "/ws/src/main/python/[myproject_path]/learning/learning/sigterm_context_manager.py", line 17, in <module>
    from my_module.monitor.learning_reporter import LearningStoppedRecord
  File "/ws/src/main/python/[myproject_path]/monitor/learning_reporter.py", line 24, in <module>
    from my_module.libraries import get_libraries_version
  File "/ws/src/main/python/[myproject_path]/libraries.py", line 11, in <module>
    import importlib_metadata
  File "/ws/.venv/lib/python3.8/site-packages/pybuilder/_vendor/importlib_metadata/__init__.py", line 6, in <module>
    from .. import zipp
ValueError: attempted relative import beyond top-level package`

@arcivanov
Copy link
Member

    In the build.py I have a dependency on importlib_metadata
    When I upgraded pybuilder v0.12.10 to v0.13.3, the importlib_metadata/init.py file was added
    The python interpreter then calls this file when I run "import importlib_metadata" in my own code (see logs below)

Have you tried removing the dependency?

@arcivanov
Copy link
Member

arcivanov commented Jan 12, 2022

Unfortunately, the importlib_metadata dependency is an artifact of the virtualenv being integrated and vendored. Since importlib_metadata is now part of PyBuilder you no longer need to depend on it separately.

This is quite a unique case. Could you share your build.py?

@arcivanov
Copy link
Member

Here are the full logs. I still have untangled this on my side. The only ways I found to get rid of that error are:

    By going into pybuilder's importlib_metadata/init.py file and replace "from .. import zipp" by "import zipp" (not a real solution, just an attempt to understand what's going on)
    By not calling importlib_metadata in my own code...

You could import the importlib_metadata in your functions instead of globally. Since zipp is there, there shouldn't be an issue with this, especially considering importlib_metadata actually works from inside PyBuilder itself.

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

2 participants