Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

KeyError in exporting package with extras #107

Closed
mikicz opened this issue Aug 31, 2022 · 2 comments · Fixed by #109
Closed

KeyError in exporting package with extras #107

mikicz opened this issue Aug 31, 2022 · 2 comments · Fixed by #109

Comments

@mikicz
Copy link

mikicz commented Aug 31, 2022

Hi,

I have an a bug when exporting certain dependencies. It does happen to me in the minimal example of https://github.com/mikicz/poetry-export-keyerror. When I run the command

poetry export  -f requirements.txt --with dev --without-hashes --without-urls -vvv

I (sometimes) get the following error:

$ poetry export  -f requirements.txt --with dev --without-hashes --without-urls -vvv
Loading configuration file /home/miki/.config/pypoetry/config.toml
Loading configuration file /home/miki/.config/pypoetry/auth.toml
Using virtualenv: /home/miki/oss/test-export/venv
Project environment contains an empty path in sys_path, ignoring.
Source (poetry-locked): 1 packages found for moto >=4.0.1,<5.0.0

  Stack trace:

  13  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/cleo/application.py:329 in run
       327│ 
       328│             try:
     → 329│                 exit_code = self._run(io)
       330│             except Exception as e:
       331│                 if not self._catch_exceptions:

  12  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/poetry/console/application.py:185 in _run
       183│         self._load_plugins(io)
       184│ 
     → 185│         exit_code: int = super()._run(io)
       186│         return exit_code
       187│ 

  11  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/cleo/application.py:423 in _run
       421│             io.input.set_stream(stream)
       422│ 
     → 423│         exit_code = self._run_command(command, io)
       424│         self._running_command = None
       425│ 

  10  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/cleo/application.py:465 in _run_command
       463│ 
       464│         if error is not None:
     → 465│             raise error
       466│ 
       467│         return event.exit_code

   9  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/cleo/application.py:449 in _run_command
       447│ 
       448│             if event.command_should_run():
     → 449│                 exit_code = command.run(io)
       450│             else:
       451│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

   8  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/cleo/commands/base_command.py:119 in run
       117│         io.input.validate()
       118│ 
     → 119│         status_code = self.execute(io)
       120│ 
       121│         if status_code is None:

   7  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/cleo/commands/command.py:83 in execute
        81│ 
        82│         try:
     →  83│             return self.handle()
        84│         except KeyboardInterrupt:
        85│             return 1

   6  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/poetry_plugin_export/command.py:91 in handle
        89│         exporter.with_credentials(self.option("with-credentials"))
        90│         exporter.with_urls(not self.option("without-urls"))
     →  91│         exporter.export(fmt, self.poetry.file.parent, output or self.io)
        92│ 

   5  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/poetry_plugin_export/exporter.py:72 in export
        70│             raise ValueError(f"Invalid export format: {fmt}")
        71│ 
     →  72│         getattr(self, self.EXPORT_METHODS[fmt])(cwd, output)
        73│ 
        74│     def _export_requirements_txt(self, cwd: Path, output: IO | str) -> None:

   4  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/poetry_plugin_export/exporter.py:85 in _export_requirements_txt
        83│         )
        84│ 
     →  85│         for dependency_package in get_project_dependency_packages(
        86│             self._poetry.locker,
        87│             project_requires=root.all_requires,

   3  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/poetry_plugin_export/walker.py:95 in get_project_dependency_packages
        93│         selected.append(dependency)
        94│ 
     →  95│     for package, dependency in get_project_dependencies(
        96│         project_requires=selected,
        97│         locked_packages=repository.packages,

   2  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/poetry_plugin_export/walker.py:121 in get_project_dependencies
       119│         )
       120│ 
     → 121│     nested_dependencies = walk_dependencies(
       122│         dependencies=project_requires,
       123│         packages_by_name=packages_by_name,

   1  ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/poetry_plugin_export/walker.py:162 in walk_dependencies
       160│ 
       161│         for require in locked_package.requires:
     → 162│             if require.is_optional() and not any(
       163│                 require in locked_package.extras[feature]
       164│                 for feature in locked_package.features

  KeyError

  'iam'

  at ~/.local/share/pypoetry/venv/lib64/python3.9/site-packages/poetry_plugin_export/walker.py:163 in <genexpr>
      159│         requirement.constraint = constraint
      160│ 
      161│         for require in locked_package.requires:
      162│             if require.is_optional() and not any(
    → 163│                 require in locked_package.extras[feature]
      164│                 for feature in locked_package.features
      165│             ):
      166│                 continue
      167│ 

I do have the latest export plugin version (AFAIK):

$ poetry self show plugins

  • poetry-plugin-export (1.0.6) Poetry plugin to export the dependencies to various formats
      1 application plugin

      Dependencies
        - poetry (>=1.2.0b3,<2.0.0)
        - poetry-core (>=1.1.0b3,<2.0.0)

My poetry installation:

$ poetry debug info

Poetry
Version: 1.2.0
Python:  3.9.13

Virtualenv
Python:         3.9.13
Implementation: CPython
Path:           /home/miki/oss/test-export/venv
Executable:     /home/miki/oss/test-export/venv/bin/python
Valid:          True

System
Platform:   linux
OS:         posix
Python:     3.9.13
Path:       /usr
Executable: /usr/bin/python3.9
@mikicz mikicz changed the title Keyerror KeyError in exporting package with extras Aug 31, 2022
@dimbleby
Copy link
Contributor

iam is not a valid extra for moto.

Of course the plugin should not fall over on that, but you'll likely want to fix your pyproject.toml.

@mikicz
Copy link
Author

mikicz commented Sep 1, 2022

Ah, that would explain it! I honestly didn't expect poetry to let that stand, so I didn't even consider this!

Will fix my own pyproject and thanks for fixing the error in #109!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants