question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InstalledRepository load() breaks if there's an empty string for a env.sys_path variable

See original GitHub issue
  • [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: <Ubuntu 18.04.3>
  • Poetry version: <1.0.0>

Issue

I ran into an error that pops up as: expected string or bytes-like object. I followed the stack trace and found the location where it happens: /.poetry/lib/poetry/repositories/installed_repository.py

The problem is in the load() function where it calls to get a list of paths or something using the env.sys_path variable. For me it looked like this:

‘’’ for distribution in sorted( metadata.distributions(path=env.sys_path), key=lambda d: str(d._path), ): ‘’’

But I know that this is a little different between versions, so I’ll specifically say that the issue was the env.sys_path. My env.sys_path was returning one string that’s empty in it’s list. I don’t know why, I just know it does that. The empty string then is passed along with the rest of the code which assumes that it is a distribution package with metadata. It specifically passes along a None value which then breaks things later. The load() function needs to have logic to handle the case where env.sys_path has an empty string in the return values.

I was able to fix it by adding a simple check after the values are returned:

            name = distribution.metadata["name"]
            if name is None:
                continue

I tried cleaning the names for env.sys_path before they’re used but then I get a different weird error:

[TypeError]
find_distributions() got an unexpected keyword argument 'name'

So I just did the simple fix where I check if name is None.

Simple fix, should be quick to add to the next release.

Stack trace:

[TypeError]
expected string or bytes-like object

Traceback (most recent call last):
  File "/home/.poetry/lib/poetry/_vendor/py3.6/clikit/console_application.py", line 131, in run
    status_code = command.handle(parsed_args, io)
  File "/home/.poetry/lib/poetry/_vendor/py3.6/clikit/api/command/command.py", line 120, in handle
    status_code = self._do_handle(args, io)
  File "/home/.poetry/lib/poetry/_vendor/py3.6/clikit/api/command/command.py", line 171, in _do_handle
    return getattr(handler, handler_method)(args, io, self)
  File "/home/.poetry/lib/poetry/_vendor/py3.6/cleo/commands/command.py", line 92, in wrap_handle
    return self.handle()
  File "/home/.poetry/lib/poetry/console/commands/install.py", line 48, in handle
    self.io, self.env, self.poetry.package, self.poetry.locker, self.poetry.pool
  File "/home/.poetry/lib/poetry/installation/installer.py", line 55, in __init__
    installed = self._get_installed()
  File "/home/.poetry/lib/poetry/installation/installer.py", line 488, in _get_installed
    return InstalledRepository.load(self._env)
  File "/home/.poetry/lib/poetry/repositories/installed_repository.py", line 24, in load
    package = Package(name, version, version)
  File "/home/.poetry/lib/poetry/packages/package.py", line 42, in __init__
    self._name = canonicalize_name(name)
  File "/home/.poetry/lib/poetry/utils/helpers.py", line 31, in canonicalize_name
    return _canonicalize_regex.sub('-', name).lower()

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:25 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
sispcommented, Feb 10, 2020

I’m experiencing the same issue when using tox. pip install tox now installs virtualenv==20.0.0, but a few days ago 16.7.9 was installed. Forcing virtualenv<20, i.e. pip install 'virtualenv<20' tox, solves the problem for me, but it’s only a quick fix.

7reactions
stefsmeetscommented, May 13, 2020

A simple work-around is to change https://github.com/python-poetry/poetry/blob/master/poetry/repositories/installed_repository.py#L25 to:

                name = distribution.metadata["name"]
                if not name:
                    continue
Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Permanently add a directory to PYTHONPATH?
You need to add your new directory to the environment variable PYTHONPATH , separated by a colon from previous contents thereof. In any...
Read more >
Configuration | Documentation
Give the virtual environment access to the system site-packages directory. Applies on virtualenv creation. virtualenvs.path #. Type: string. Default: {cache-dir}/ ...
Read more >
Working with Environment Variables in PHP
In this tutorial, you're going to learn how to set and retrieve environment variables in PHP, so that your applications can access all...
Read more >
Python and the Module Search Path | by Mark Jamison
Previously we've looked at (article here) how various tools (conda, pyenv) manipulate the $PATH variable so that when you type python, ...
Read more >
2. Writing the Setup Script — Python 3.11.1 documentation
The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. The main purpose of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found