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

create_package_from_pep610 breaks without "requested_revision" #4290

Closed
xkortex opened this issue Jul 16, 2021 · 6 comments
Closed

create_package_from_pep610 breaks without "requested_revision" #4290

xkortex opened this issue Jul 16, 2021 · 6 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@xkortex
Copy link

xkortex commented Jul 16, 2021

  • [ x] I am on the latest Poetry version.
  • [ x ] I have searched the issues of this repo and believe that this is not a duplicate.
  • [ x ] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: macOS 10.15
  • Poetry version: 1.2.0a1

Issue

Any poetry command which hits create_package_from_pep610 when a URL installed package is installed, and the direct_url.json lacks "requested_revision", causes a KeyError. This is not PEP610 compliant:

source_reference = url_reference["vcs_info"]["requested_revision"]

A requested_revision key (type string) MAY be present naming a branch/tag/ref/commit/revision/etc (in a format compatible with the VCS) to install.

https://www.python.org/dev/peps/pep-0610/#:~:text=a%20requested_revision%20key%20(type%20string)%20may%20be%20present%20naming%20a%20branch%2Ftag%2Fref%2Fcommit%2Frevision%2Fetc%20(in%20a%20format%20compatible%20with%20the%20vcs)%20to%20install.

The offending direct_url.json:

{"url": "https://github.com/encode/uvicorn.git", "vcs_info": {"commit_id": "62825d3c1c2897e414b72318a079d0d8657ade34", "vcs": "git"}}

Steps to reproduce

docker run -it python:3.9.6 bash  # or some other fresh env
pip install poetry-version-plugin  # install a plugin and poetry 1.2.0a1
poetry plugin show
# works
pip install 'git+https://github.com/encode/uvicorn.git'  # install offending package
poetry plugin show 

Trace:

  KeyError

  'requested_revision'

  at /usr/local/lib/python3.9/site-packages/poetry/repositories/installed_repository.py:201 in create_package_from_pep610
      197│         elif "vcs_info" in url_reference:
      198│             # VCS distribution
      199│             source_type = url_reference["vcs_info"]["vcs"]
      200│             source_url = url_reference["url"]
    → 201│             source_reference = url_reference["vcs_info"]["requested_revision"]
      202│             source_resolved_reference = url_reference["vcs_info"]["commit_id"]
      203│
      204│         package = Package(
      205│             distribution.metadata["name"],
root@d98543c446e4:/# poetry plugin show -vvv

  Stack trace:

  10  /usr/local/lib/python3.9/site-packages/cleo/application.py:314 in run
       312│
       313│             try:
     → 314│                 exit_code = self._run(io)
       315│             except Exception as e:
       316│                 if not self._catch_exceptions:

   9  /usr/local/lib/python3.9/site-packages/poetry/console/application.py:167 in _run
       165│         self._load_plugins(io)
       166│
     → 167│         return super()._run(io)
       168│
       169│     def _configure_io(self, io: IO) -> None:

   8  /usr/local/lib/python3.9/site-packages/cleo/application.py:409 in _run
       407│                 io.set_input(ArgvInput(argv))
       408│
     → 409│         exit_code = self._run_command(command, io)
       410│         self._running_command = None
       411│

   7  /usr/local/lib/python3.9/site-packages/cleo/application.py:451 in _run_command
       449│
       450│         if error is not None:
     → 451│             raise error
       452│
       453│         return event.exit_code

   6  /usr/local/lib/python3.9/site-packages/cleo/application.py:435 in _run_command
       433│
       434│             if event.command_should_run():
     → 435│                 exit_code = command.run(io)
       436│             else:
       437│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

   5  /usr/local/lib/python3.9/site-packages/cleo/commands/base_command.py:118 in run
       116│         io.input.validate()
       117│
     → 118│         status_code = self.execute(io)
       119│
       120│         if status_code is None:

   4  /usr/local/lib/python3.9/site-packages/cleo/commands/command.py:85 in execute
        83│
        84│         try:
     →  85│             return self.handle()
        86│         except KeyboardInterrupt:
        87│             return 1

   3  /usr/local/lib/python3.9/site-packages/poetry/console/commands/plugin/show.py:42 in handle
        40│
        41│         system_env = EnvManager.get_system_env(naive=True)
     →  42│         installed_repository = InstalledRepository.load(
        43│             system_env, with_dependencies=True
        44│         )

   2  /usr/local/lib/python3.9/site-packages/poetry/repositories/installed_repository.py:247 in load
       245│                     continue
       246│
     → 247│                 package = cls.create_package_from_distribution(distribution, env)
       248│
       249│                 if with_dependencies:

   1  /usr/local/lib/python3.9/site-packages/poetry/repositories/installed_repository.py:111 in create_package_from_distribution
       109│             and path.joinpath("direct_url.json").exists()
       110│         ):
     → 111│             return cls.create_package_from_pep610(distribution)
       112│
       113│         is_standard_package = env.is_path_relative_to_lib(path)

  KeyError

  'requested_revision'

  at /usr/local/lib/python3.9/site-packages/poetry/repositories/installed_repository.py:201 in create_package_from_pep610
      197│         elif "vcs_info" in url_reference:
      198│             # VCS distribution
      199│             source_type = url_reference["vcs_info"]["vcs"]
      200│             source_url = url_reference["url"]
    → 201│             source_reference = url_reference["vcs_info"]["requested_revision"]
      202│             source_resolved_reference = url_reference["vcs_info"]["commit_id"]
      203│
      204│         package = Package(
      205│             distribution.metadata["name"],
@xkortex xkortex added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jul 16, 2021
@xkortex
Copy link
Author

xkortex commented Jul 16, 2021

Trying to write tests for my PR and something is working unexpectedly:

https://github.com/xkortex/poetry/tree/issues-4290-requested_revision

 tests/installation/test_executor.py::test_executor_should_write_pep610_url_references_for_git ✓                                                                                                                                                                  

test_executor_should_write_pep610_url_references_for_git_no_reference 

tmp_venv = VirtualEnv("/var/folders/l8/nn7l8p1j5l5f4nkp36pvgmnr0000gn/T/poetry_n_jdojav/venv"), pool = <poetry.repositories.pool.Pool object at 0x107ed4640>, config = <tests.conftest.Config object at 0x108347100>
io = <cleo.io.buffered_io.BufferedIO object at 0x10805d160>, mock_file_downloads = None

    def test_executor_should_write_pep610_url_references_for_git_no_reference(
        tmp_venv, pool, config, io, mock_file_downloads
    ):
        package = Package(
            "demo",
            "0.1.2",
            source_type="git",
            source_resolved_reference="123456",
            source_url="https://github.com/demo/demo.git",
        )
>       verify_installed_distribution(
            tmp_venv,
            package,
            {
                "vcs_info": {
                    "vcs": "git",
                    "commit_id": "123456",
                },
                "url": package.source_url,
            },
        )

tests/installation/test_executor.py:480:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

venv = VirtualEnv("/var/folders/l8/nn7l8p1j5l5f4nkp36pvgmnr0000gn/T/poetry_n_jdojav/venv"), package = Package('demo', '0.1.2', source_type='git', source_url='https://github.com/demo/demo.git', source_resolved_reference='123456')
url_reference = {'url': 'https://github.com/demo/demo.git', 'vcs_info': {'commit_id': '123456', 'vcs': 'git'}}

    def verify_installed_distribution(venv, package, url_reference=None):
        distributions = list(venv.site_packages.distributions(name=package.name))
        print(distributions)
>       assert len(distributions) == 1
E       assert 0 == 1
E         +0
E         -1

tests/installation/test_executor.py:351: AssertionError

 tests/installation/test_executor.py::test_executor_should_write_pep610_url_references_for_git_no_reference ⨯                                                                                                                                                    100% ██████████
...
FAILED tests/installation/test_executor.py::test_executor_should_write_pep610_url_references_for_git_no_reference - assert 0 == 1

I have no clue why it's failing to populate venv.site_packages.distributions(name=package.name) when source_reference is missing since it's an optional field.

@hwalinga
Copy link

This is not present in 1.1.7, but is in the preview release 1.2.0a2.

@xkortex
Copy link
Author

xkortex commented Aug 31, 2021

Yes, this is just with the 1.2 alpha. I'm itching to use https://github.com/tiangolo/poetry-version-plugin, which requires 1.2, which I believe is when plugin capability is introduced.

@tsuga
Copy link

tsuga commented Sep 19, 2021

I have the same issue with 1.2.0a2.

@dimbleby
Copy link
Contributor

dimbleby commented Nov 6, 2022

fixed at #5274

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

5 participants