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

got a expected string or bytes-like object when running install #4311

Closed
3 tasks done
ElricleNecro opened this issue Jul 23, 2021 · 5 comments
Closed
3 tasks done

got a expected string or bytes-like object when running install #4311

ElricleNecro opened this issue Jul 23, 2021 · 5 comments
Labels
kind/bug Something isn't working as expected

Comments

@ElricleNecro
Copy link

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Arch Linux
  • Poetry version: 1.1.7
  • [tool.poetry]
    name = "testy"
    version = "0.1.0"
    description = ""
    authors = ["Test user"]
    
    [tool.poetry.dependencies]
    python = ">=3.7,<4.0"
    dgl = [
    	{ git = "https://github.com/dmlc/dgl.git", tag = "v0.7.0", markers = "sys_platform == 'linux'"},
    	{ version="^0.7", markers = "sys_platform == 'darwin'"}
    ]
    
    [build-system]
    requires = ["poetry-core>=1.0.0"]
    build-backend = "poetry.core.masonry.api"

Issue

When using this pyproject.toml, I get the following exception:

  TypeError

  expected string or bytes-like object

  at /usr/lib/python3.9/site-packages/poetry/core/utils/helpers.py:27 in canonicalize_name
       23│ _canonicalize_regex = re.compile(r"[-_]+")
       24│ 
       25│ 
       26│ def canonicalize_name(name):  # type: (str) -> str
    →  27│     return _canonicalize_regex.sub("-", name).lower()
       28│ 
       29│ 
       30│ def module_name(name):  # type: (str) -> str
       31│     return canonicalize_name(name).replace(".", "_").replace("-", "_")
@ElricleNecro ElricleNecro added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jul 23, 2021
@duncm
Copy link

duncm commented Oct 13, 2021

I encountered this issue as well but in a different context. Poetry version: 1.1.11.

In my case, I had an existing empty .dist-info directory (not sure why) but it was still discoverable, so in the following block, distribution.metadata["name"] was None, hence the later type error. I fixed it by deleting the empty directory.

for distribution in sorted(
metadata.distributions(path=[entry]), key=lambda d: str(d._path),
):
name = distribution.metadata["name"]

Debug output:

$ poetry lock -vvv
Skipping virtualenv creation, as specified in config file.

  Stack trace:

  11  ~/.poetry/lib/poetry/_vendor/py3.9/clikit/console_application.py:131 in run
       129│             parsed_args = resolved_command.args
       130│
     → 131│             status_code = command.handle(parsed_args, io)
       132│         except KeyboardInterrupt:
       133│             status_code = 1

  10  ~/.poetry/lib/poetry/_vendor/py3.9/clikit/api/command/command.py:120 in handle
       118│     def handle(self, args, io):  # type: (Args, IO) -> int
       119│         try:
     → 120│             status_code = self._do_handle(args, io)
       121│         except KeyboardInterrupt:
       122│             if io.is_debug():

   9  ~/.poetry/lib/poetry/_vendor/py3.9/clikit/api/command/command.py:163 in _do_handle
       161│         if self._dispatcher and self._dispatcher.has_listeners(PRE_HANDLE):
       162│             event = PreHandleEvent(args, io, self)
     → 163│             self._dispatcher.dispatch(PRE_HANDLE, event)
       164│
       165│             if event.is_handled():

   8  ~/.poetry/lib/poetry/_vendor/py3.9/clikit/api/event/event_dispatcher.py:22 in dispatch
        20│
        21│         if listeners:
     →  22│             self._do_dispatch(listeners, event_name, event)
        23│
        24│         return event

   7  ~/.poetry/lib/poetry/_vendor/py3.9/clikit/api/event/event_dispatcher.py:89 in _do_dispatch
        87│                 break
        88│
     →  89│             listener(event, event_name, self)
        90│
        91│     def _sort_listeners(self, event_name):  # type: (str) -> None

   6  ~/.poetry/lib/poetry/console/config/application_config.py:141 in set_installer
       139│
       140│         poetry = command.poetry
     → 141│         installer = Installer(
       142│             event.io,
       143│             command.env,

   5  ~/.poetry/lib/poetry/installation/installer.py:65 in __init__
        63│         self._installer = self._get_installer()
        64│         if installed is None:
     →  65│             installed = self._get_installed()
        66│
        67│         self._installed_repository = installed

   4  ~/.poetry/lib/poetry/installation/installer.py:558 in _get_installed
       556│
       557│     def _get_installed(self):  # type: () -> InstalledRepository
     → 558│         return InstalledRepository.load(self._env)
       559│

   3  ~/.poetry/lib/poetry/repositories/installed_repository.py:118 in load
       116│                 path = Path(str(distribution._path))
       117│                 version = distribution.metadata["version"]
     → 118│                 package = Package(name, version, version)
       119│                 package.description = distribution.metadata.get("summary", "")
       120│

   2  ~/.poetry/lib/poetry/_vendor/py3.9/poetry/core/packages/package.py:67 in __init__
        65│         Creates a new in memory package.
        66│         """
     →  67│         super(Package, self).__init__(
        68│             name,
        69│             source_type=source_type,

   1  ~/.poetry/lib/poetry/_vendor/py3.9/poetry/core/packages/specification.py:19 in __init__
        17│     ):
        18│         self._pretty_name = name
     →  19│         self._name = canonicalize_name(name)
        20│         self._source_type = source_type
        21│         self._source_url = source_url

  TypeError

  expected string or bytes-like object

  at ~/.poetry/lib/poetry/_vendor/py3.9/poetry/core/utils/helpers.py:27 in canonicalize_name
       23│ _canonicalize_regex = re.compile(r"[-_]+")
       24│
       25│
       26│ def canonicalize_name(name):  # type: (str) -> str
    →  27│     return _canonicalize_regex.sub("-", name).lower()
       28│
       29│
       30│ def module_name(name):  # type: (str) -> str
       31│     return canonicalize_name(name).replace(".", "_").replace("-", "_")

@aalok-sathe
Copy link

aalok-sathe commented Nov 2, 2021

Indeed, the bug seems to be stemming from this line.

it was exactly similar as you described, I too had an empty .egg-info directory causing the issue.

@aalok-sathe
Copy link

But yes, I am encountering this bug quite often, and arbitrarily, so it's pretty annoying.
Sometimes poetry works fine, but then suddenly it will start throwing this error out of nowhere.

aalok-sathe added a commit to aalok-sathe/poetry that referenced this issue Nov 2, 2021
Addresses issue python-poetry#4311 and others, related to `canonicalize_name` throwing TypeError because a str or bytes like object was expected.
@abn
Copy link
Member

abn commented May 19, 2022

Closing as a duplicate of #3628 as it has more information.

@abn abn closed this as completed May 19, 2022
@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Jun 11, 2022
Copy link

github-actions bot commented Mar 1, 2024

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 1, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants