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

poetry show gives a RunTimeError when not in the right directory #5411

Closed
3 tasks done
ergut opened this issue Apr 5, 2022 · 7 comments
Closed
3 tasks done

poetry show gives a RunTimeError when not in the right directory #5411

ergut opened this issue Apr 5, 2022 · 7 comments
Assignees
Labels
kind/bug Something isn't working as expected

Comments

@ergut
Copy link

ergut commented Apr 5, 2022

  • 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 Big Sur 11.4
  • Poetry version: 1.1.13
  • Link of a Gist with the contents of your pyproject.toml file:

Issue

When you run "poetry show" command outside a poetry directory we get a RunTimeError with the following tracking information. Wouldn't it be preferable to show an error message in this case and exit the program gracefully?


  RuntimeError

  Poetry could not find a pyproject.toml file in ... or its parents

  at ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/factory.py:369 in locate
      365│             if poetry_file.exists():
      366│                 return poetry_file
      367│ 
      368│         else:
    → 369│             raise RuntimeError(
      370│                 "Poetry could not find a pyproject.toml file in {} or its parents".format(
      371│                     cwd
      372│                 )
      373│             )

For example, running git status on a non-git directory gives the following output:

fatal: not a git repository (or any of the parent directories): .git
@ergut ergut added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Apr 5, 2022
@branchvincent branchvincent self-assigned this May 20, 2022
@tunayokumus
Copy link

This happens to me with every poetry command, when pyproject.toml is not present.
E.g. here is the output from 'poetry init', which should actually create the pyproject.toml if it doesn't exist already.

Ubuntu 20.04
poetry 1.2.0b1 (installed via the new install-poetry.py installer)

poetry init -vvv 
  Stack trace:

  8  ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/cleo/application.py:330 in run
      328│ 
      329│             try:
    → 330│                 exit_code = self._run(io)
      331│             except Exception as e:
      332│                 if not self._catch_exceptions:

  7  ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/console/application.py:172 in _run
      170│         self._disable_plugins = io.input.parameter_option("--no-plugins")
      171│ 
    → 172│         self._load_plugins(io)
      173│ 
      174│         return super()._run(io)

  6  ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/console/application.py:320 in _load_plugins
      318│             manager = PluginManager("application.plugin")
      319│             manager.load_plugins()
    → 320│             manager.activate(self)
      321│ 
      322│         self._plugins_loaded = True

  5  ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/plugins/plugin_manager.py:48 in activate
       46│     def activate(self, *args: Any, **kwargs: Any) -> None:
       47│         for plugin in self._plugins:
    →  48│             plugin.activate(*args, **kwargs)
       49│ 
       50│     def _load_plugin_entrypoint(self, entrypoint: entrypoints.EntryPoint) -> None:

  4  ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry_dynamic_versioning/plugin.py:96 in activate
       94│         )
       95│ 
    →  96│         config = _get_config(self._application.poetry.pyproject.data)
       97│         if not config["enable"]:
       98│             return

  3  ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/console/application.py:119 in poetry
      117│             return self._poetry
      118│ 
    → 119│         self._poetry = Factory().create_poetry(
      120│             Path.cwd(), io=self._io, disable_plugins=self._disable_plugins
      121│         )

  2  ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/factory.py:39 in create_poetry
       37│             io = NullIO()
       38│ 
    →  39│         base_poetry = super().create_poetry(cwd)
       40│ 
       41│         locker = Locker(

  1  ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/core/factory.py:37 in create_poetry
       35│         from poetry.core.pyproject.toml import PyProjectTOML
       36│ 
    →  37│         poetry_file = self.locate(cwd)
       38│         local_config = PyProjectTOML(path=poetry_file).poetry_config
       39│ 

  RuntimeError

  Poetry could not find a pyproject.toml file in /home/user/some_dir/ or its parents

  at ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/core/factory.py:455 in locate
      451│             if poetry_file.exists():
      452│                 return poetry_file
      453│ 
      454│         else:
    → 455│             raise RuntimeError(
      456│                 f"Poetry could not find a pyproject.toml file in {cwd} or its parents"
      457│             )
      458│ 

@dimbleby
Copy link
Contributor

There are several open issues talking about the ugly output poetry gives on any error, #5559 looks like the furthest progressed try at doing something about it (and lists some duplicates).

@branchvincent
Copy link
Member

This was fixed with #5766, and will be part of the upcoming 1.2 release. It now looks like:

$ poetry show

Poetry could not find a pyproject.toml file in /path/to/cwd or its parents

@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Jun 11, 2022
@msoutopico
Copy link

This was fixed with #5766, and will be part of the upcoming 1.2 release. It now looks like:

$ poetry show

Poetry could not find a pyproject.toml file in /path/to/cwd or its parents

I have a question about this, if I may. Does this mean that it's necessary to change directory to the poetry project folder (where the pyproject.toml is) to execute the python code in that project? Isn't there any way to do so from outside that folder?

I'm pretty sure pipenv allows me to do something like pipenv run python3 /path/to/project/folder/script.py from another location.

Thanks a lot.

@finswimmer
Copy link
Member

@msoutopico: Since Poetry 1.3 you can use the global parameter -C/--directory to point to the directory where the project is located.

-C, --directory=DIRECTORY  The working directory for the Poetry command (defaults to the current working directory).

@msoutopico
Copy link

msoutopico commented Jan 3, 2023

@msoutopico: Since Poetry 1.3 you can use the global parameter -C/--directory to point to the directory where the project is located.

-C, --directory=DIRECTORY  The working directory for the Poetry command (defaults to the current working directory).

Thanks a lot @finswimmer . I had tried that with poetry 1.3.1 but I might be doing something wrong. I do:

~ poetry --directory=$app_root run python foo.py

but that gives me "Poetry could not find a pyproject.toml file in /home/souto/ or its parents".

It does work however if I do:

~ cd $app_root && poetry run python foo.py && cd -                                                          

Could you give me any tip?

I hope this is a good place to ask. Apologies if it's not, in which case I'll try in Discord.

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 Feb 29, 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

No branches or pull requests

7 participants