python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.16k stars 2.25k forks source link

Regression: `poetry show -o` fails with some github repos #8112

Closed aqeelat closed 1 year ago

aqeelat commented 1 year ago

Issue

In 1.5.1, when I try to run poetry show -o, the command fails and provides the error listed below. I was able to isolate the issue to a specific github dependency in my project. This dependency hasn't been updated in a few years. Things worked fine in 1.5.0 and below.

Possible duplication of #7744 but decided to open a new ticket because the conversation stalled in that ticket.


  AssertionError

  at /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/dulwich/pack.py:698 in _object_offset
       694│ 
       695│         Args:
       696│           sha: A *binary* SHA string. (20 characters long)_
       697│         """
    →  698│         assert len(sha) == 20
       699│         idx = ord(sha[:1])
       700│         if idx == 0:
       701│             start = 0
       702│         else:
Verbose Output

``` Loading configuration file /Users/aqeelat/Library/Application Support/pypoetry/config.toml Using virtualenv: /Users/aqeelat/lab/venv/pythonProject1 [keyring.backend] Loading KWallet [keyring.backend] Loading SecretService [keyring.backend] Loading Windows [keyring.backend] Loading chainer [keyring.backend] Loading libsecret [keyring.backend] Loading macOS Creating new session for pypi.org Source (PyPI): 1 packages found for certifi >=2023.5.7 Source (PyPI): 1 packages found for charset-normalizer >=3.1.0 Source (PyPI): 1 packages found for idna >=3.4 Stack trace: 24 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/cleo/application.py:327 in run 325│ 326│ try: → 327│ exit_code = self._run(io) 328│ except BrokenPipeError: 329│ # If we are piped to another process, it may close early and send a 23 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/console/application.py:190 in _run 188│ self._load_plugins(io) 189│ → 190│ exit_code: int = super()._run(io) 191│ return exit_code 192│ 22 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/cleo/application.py:431 in _run 429│ io.input.interactive(interactive) 430│ → 431│ exit_code = self._run_command(command, io) 432│ self._running_command = None 433│ 21 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/cleo/application.py:473 in _run_command 471│ 472│ if error is not None: → 473│ raise error 474│ 475│ return terminate_event.exit_code 20 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/cleo/application.py:457 in _run_command 455│ 456│ if command_event.command_should_run(): → 457│ exit_code = command.run(io) 458│ else: 459│ exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED 19 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/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: 18 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/cleo/commands/command.py:62 in execute 60│ 61│ try: → 62│ return self.handle() 63│ except KeyboardInterrupt: 64│ return 1 17 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/console/commands/show.py:133 in handle 131│ return self._display_packages_tree_information(locked_repo, root) 132│ → 133│ return self._display_packages_information(locked_repo, root) 134│ 135│ def _display_single_package_information( 16 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/console/commands/show.py:255 in _display_packages_information 253│ 254│ if show_latest: → 255│ latest = self.find_latest_package(locked, root) 256│ if not latest: 257│ latest = locked 15 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/console/commands/show.py:551 in find_latest_package 549│ if dep.name == package.name and dep.source_type == package.source_type: 550│ provider = Provider(root, self.poetry.pool, NullIO()) → 551│ return provider.search_for_direct_origin_dependency(dep) 552│ 553│ allow_prereleases = False 14 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/puzzle/provider.py:232 in search_for_direct_origin_dependency 230│ elif dependency.is_vcs(): 231│ dependency = cast("VCSDependency", dependency) → 232│ package = self._search_for_vcs(dependency) 233│ 234│ elif dependency.is_file(): 13 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/puzzle/provider.py:310 in _search_for_vcs 308│ and get the information we need by checking out the specified reference. 309│ """ → 310│ package = self._direct_origin.get_package_from_vcs( 311│ dependency.vcs, 312│ dependency.source, 12 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/packages/direct_origin.py:111 in get_package_from_vcs 109│ raise ValueError(f"Unsupported VCS dependency {vcs}") 110│ → 111│ return _get_package_from_git( 112│ url=url, 113│ branch=branch, 11 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/packages/direct_origin.py:32 in _get_package_from_git 30│ source_root: Path | None = None, 31│ ) -> Package: → 32│ source = Git.clone( 33│ url=url, 34│ source_root=source_root, 10 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/vcs/git/backend.py:438 in clone 436│ try: 437│ if not cls.is_using_legacy_client(): → 438│ local = cls._clone(url=url, refspec=refspec, target=target) 439│ cls._clone_submodules(repo=local) 440│ return local 9 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/vcs/git/backend.py:257 in _clone 255│ local = Repo(str(target)) 256│ → 257│ remote_refs = cls._fetch_remote_refs(url=url, local=local) 258│ 259│ logger.debug( 8 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/poetry/vcs/git/backend.py:202 in _fetch_remote_refs 200│ 201│ with local: → 202│ result: FetchPackResult = client.fetch( 203│ path, 204│ local, 7 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/dulwich/client.py:784 in fetch 782│ path, 783│ determine_wants, → 784│ target.get_graph_walker(), 785│ f.write, 786│ progress=progress, 6 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/dulwich/repo.py:566 in get_graph_walker 564│ """ 565│ if heads is None: → 566│ heads = [ 567│ sha 568│ for sha in self.refs.as_dict(b"refs/heads").values() 5 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/dulwich/repo.py:569 in 567│ sha 568│ for sha in self.refs.as_dict(b"refs/heads").values() → 569│ if sha in self.object_store 570│ ] 571│ parents_provider = ParentsProvider(self.object_store) 4 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/dulwich/object_store.py:382 in __contains__ 380│ This method makes no distinction between loose and packed objects. 381│ """ → 382│ if self.contains_packed(sha) or self.contains_loose(sha): 383│ return True 384│ for alternate in self.alternates: 3 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/dulwich/object_store.py:371 in contains_packed 369│ for pack in self.packs: 370│ try: → 371│ if sha in pack: 372│ return True 373│ except PackFileDisappeared: 2 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/dulwich/pack.py:2371 in __contains__ 2369│ """Check whether this pack contains a particular SHA1.""" 2370│ try: → 2371│ self.index.object_offset(sha1) 2372│ return True 2373│ except KeyError: 1 /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/dulwich/pack.py:685 in object_offset 683│ sha = hex_to_sha(sha) 684│ try: → 685│ return self._object_offset(sha) 686│ except ValueError as exc: 687│ closed = getattr(self._contents, "closed", None) AssertionError at /opt/homebrew/Cellar/poetry/1.5.1/libexec/lib/python3.11/site-packages/dulwich/pack.py:698 in _object_offset 694│ 695│ Args: 696│ sha: A *binary* SHA string. (20 characters long)_ 697│ """ → 698│ assert len(sha) == 20 699│ idx = ord(sha[:1]) 700│ if idx == 0: 701│ start = 0 702│ else: ```

aqeelat commented 1 year ago

possibly caused by #7973

dimbleby commented 1 year ago

eg #7744 stalled because no one could provide a way to reproduce it. You also haven't provided a way to reproduce this, so it won't do any better

Possible duplication of https://github.com/python-poetry/poetry/issues/7744 but decided to open a new ticket because the conversation stalled in that ticket.

That doesn't stop it from being a duplicate! Please close, and continue the conversation there.

aqeelat commented 1 year ago

@dimbleby you can use the pyproject I provided, or:

  1. run poetry show -o
  2. run poetry add "git+https://github.com/joaobarbosa/onesignal-python.git@master"
  3. run poetry show -o

7744 is about installing a private package but install works fine in my example. The issue here is just with show.

If you think I should still close, then please confirm and I will do so.

aqeelat commented 1 year ago

Additional details: I copied https://raw.githubusercontent.com/python-poetry/poetry/master/src/poetry/vcs/git/backend.py locally and ran:

source = Git.clone(
    url="https://github.com/joaobarbosa/onesignal-python.git",
    source_root=Path("/Users/aqeelat/lab/pythonProject1/src/"),
    revision="master",
    clean=False,
 )

and it worked fine.

dimbleby commented 1 year ago

Your pyproject.toml is not sufficient to reproduce this:

$ poetry --version
Poetry (version 1.5.1)
$ poetry install
Updating dependencies
Resolving dependencies... (7.8s)

Package operations: 6 installs, 0 updates, 0 removals

  • Installing certifi (2023.5.7)
  • Installing charset-normalizer (3.1.0)
  • Installing idna (3.4)
  • Installing urllib3 (2.0.3)
  • Installing requests (2.31.0)
  • Installing onesignal-python (0.1.1.dev1 fc37e75)

Writing lock file
$ poetry show -o
$

I now recall that #7744 itself should be closed as a duplicate of two others, we certainly don't need a fourth open issue.

aqeelat commented 1 year ago

Closing and moving the conversation to #7744

github-actions[bot] commented 6 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.