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

JSONDecodeError installing from requirements.txt #4949

Closed
3 tasks done
karambaq opened this issue Dec 29, 2021 · 3 comments
Closed
3 tasks done

JSONDecodeError installing from requirements.txt #4949

karambaq opened this issue Dec 29, 2021 · 3 comments
Labels
kind/question User questions (candidates for conversion to discussion)

Comments

@karambaq
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: macOS Monterey 12.1

  • Poetry version: latest

Issue

My requirements.txt:

attrs==19.3.0             # via pytest
beautifulsoup4
certifi==2019.9.11        # via requests
chardet==3.0.4            # via requests
django-debug-toolbar==2.2
django==2.2.6
idna==2.8                 # via requests
importlib-metadata==1.5.0  # via pluggy, pytest
mixer==7.1.2
more-itertools==8.2.0     # via pytest
packaging==20.1           # via pytest
pluggy==0.13.1            # via pytest
py==1.8.1                 # via pytest
pyparsing==2.4.6          # via packaging
pytest-django==3.8.0
pytest-pythonpath==0.7.3
pytest==5.3.5             # via pytest-django
pytz==2019.3              # via django
requests==2.22.0
six==1.14.0               # via packaging
sorl-thumbnail==12.6.3
sqlparse==0.3.0           # via django, django-debug-toolbar
urllib3==1.25.6           # via requests
wcwidth==0.1.8            # via pytest
zipp==2.2.0               # via importlib-metadata

I'm executing: cat requirements.txt | xargs poetry add

Trace:

% cat requirements.txt | xargs poetry add -vvv
Using virtualenv: /Users/maksim/Library/Caches/pypoetry/virtualenvs/hw03-forms-rwMTKORS-py3.9
PyPI: 1 packages found for attrs 19.3.0

  Stack trace:

  19  ~/.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

  18  ~/.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():

  17  ~/.poetry/lib/poetry/_vendor/py3.9/clikit/api/command/command.py:171 in _do_handle
       169│         handler_method = self._config.handler_method
       170│ 
     → 171│         return getattr(handler, handler_method)(args, io, self)
       172│ 
       173│     def __repr__(self):  # type: () -> str

  16  ~/.poetry/lib/poetry/_vendor/py3.9/cleo/commands/command.py:92 in wrap_handle
        90│         self._command = command
        91│ 
     →  92│         return self.handle()
        93│ 
        94│     def handle(self):  # type: () -> Optional[int]

  15  ~/.poetry/lib/poetry/console/commands/add.py:106 in handle
       104│             return 0
       105│ 
     → 106│         requirements = self._determine_requirements(
       107│             packages,
       108│             allow_prereleases=self.option("allow-prereleases"),

  14  ~/.poetry/lib/poetry/console/commands/init.py:328 in _determine_requirements
       326│             elif "version" not in requirement:
       327│                 # determine the best version automatically
     → 328│                 name, version = self._find_best_version_for_package(
       329│                     requirement["name"],
       330│                     allow_prereleases=allow_prereleases,

  13  ~/.poetry/lib/poetry/console/commands/init.py:361 in _find_best_version_for_package
       359│ 
       360│         selector = VersionSelector(self._get_pool())
     → 361│         package = selector.find_best_candidate(
       362│             name, required_version, allow_prereleases=allow_prereleases, source=source
       363│         )

  12  ~/.poetry/lib/poetry/version/version_selector.py:32 in find_best_candidate
       30│             },
       31│         )
     → 32│         candidates = self._pool.find_packages(dependency)
       33│         only_prereleases = all([c.version.is_prerelease() for c in candidates])
       34│ 

  11  ~/.poetry/lib/poetry/repositories/pool.py:170 in find_packages
       168│         packages = []
       169│         for repo in self._repositories:
     → 170│             packages += repo.find_packages(dependency)
       171│ 
       172│         return packages

  10  ~/.poetry/lib/poetry/repositories/pypi_repository.py:101 in find_packages
        99│ 
       100│         try:
     → 101│             info = self.get_package_info(dependency.name)
       102│         except PackageNotFound:
       103│             self._log(

   9  ~/.poetry/lib/poetry/repositories/pypi_repository.py:202 in get_package_info
       200│             return self._get_package_info(name)
       201│ 
     → 202│         return self._cache.store("packages").remember_forever(
       203│             name, lambda: self._get_package_info(name)
       204│         )

   8  ~/.poetry/lib/poetry/_vendor/py3.9/cachy/repository.py:174 in remember_forever
       172│             return val
       173│ 
     → 174│         val = value(callback)
       175│ 
       176│         self.forever(key, val)

   7  ~/.poetry/lib/poetry/_vendor/py3.9/cachy/helpers.py:6 in value
       4│ def value(val):
       5│     if callable(val):
     → 6│         return val()
       7│ 
       8│     return val

   6  ~/.poetry/lib/poetry/repositories/pypi_repository.py:203 in <lambda>
       201│ 
       202│         return self._cache.store("packages").remember_forever(
     → 203│             name, lambda: self._get_package_info(name)
       204│         )
       205│ 

   5  ~/.poetry/lib/poetry/repositories/pypi_repository.py:207 in _get_package_info
       205│ 
       206│     def _get_package_info(self, name):  # type: (str) -> dict
     → 207│         data = self._get("pypi/{}/json".format(name))
       208│         if data is None:
       209│             raise PackageNotFound("Package [{}] not found.".format(name))

   4  ~/.poetry/lib/poetry/repositories/pypi_repository.py:325 in _get
       323│             return None
       324│ 
     → 325│         json_data = json_response.json()
       326│ 
       327│         return json_data

   3  ~/.poetry/lib/poetry/_vendor/py3.9/requests/models.py:900 in json
       898│                     # used.
       899│                     pass
     → 900│         return complexjson.loads(self.text, **kwargs)
       901│ 
       902│     @property

   2  /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py:346 in loads
       344│             parse_int is None and parse_float is None and
       345│             parse_constant is None and object_pairs_hook is None and not kw):
     → 346│         return _default_decoder.decode(s)
       347│     if cls is None:
       348│         cls = JSONDecoder

   1  /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py:337 in decode
       335│ 
       336│         """
     → 337│         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
       338│         end = _w(s, end).end()
       339│         if end != len(s):

  JSONDecodeError

  Expecting value: line 7 column 1 (char 6)

  at /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py:355 in raw_decode
      351│         """
      352│         try:
      353│             obj, end = self.scan_once(s, idx)
      354│         except StopIteration as err:
    → 355│             raise JSONDecodeError("Expecting value", s, err.value) from None
      356│         return obj, end
      357│ 
@karambaq karambaq added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Dec 29, 2021
@IMSUVEN
Copy link

IMSUVEN commented Dec 31, 2021

Best solution:
Remove all the comments like (# via pytest) in the requirements.txt

Reason:
cat requirements.txt | xargs poetry add
this command will input all the contents of requirements.txt as parameters to poetry (including comments like # via pytest)

😭 I hope poetry will support installation using requirements.txt.

@mkniewallner
Copy link
Member

The comments are indeed preventing the command from working, so you would need to strip them out, for instance by running:

cat requirements.txt | sed 's/#.*//' | xargs poetry add

As for the feature of importing packages from requirements.txt, given that this is usually a one-time operation, it is unlikely to be implemented directly on Poetry.
But with the next 1.2 release that makes it possible to build plugins, there may be a way to implement that as a Poetry plugin if people really want that feature.

See #1701 and #663 for previous discussions on the subject.

@mkniewallner mkniewallner added kind/question User questions (candidates for conversion to discussion) and removed status/triage This issue needs to be triaged kind/bug Something isn't working as expected labels Jun 10, 2022
Copy link

github-actions bot commented Mar 2, 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 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/question User questions (candidates for conversion to discussion)
Projects
None yet
Development

No branches or pull requests

3 participants