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 install incorrectly resolve python files in current folder #6627

Closed
3 of 4 tasks
hms5232 opened this issue Sep 26, 2022 · 3 comments · Fixed by #6628
Closed
3 of 4 tasks

poetry install incorrectly resolve python files in current folder #6627

hms5232 opened this issue Sep 26, 2022 · 3 comments · Fixed by #6628
Labels
area/venv Related to virtualenv management kind/bug Something isn't working as expected status/confirmed Issue is reproduced and confirmed version/1.2.1

Comments

@hms5232
Copy link

hms5232 commented Sep 26, 2022

  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

My project is open source, so I directly put repo url in pyproject.toml item.

The project usage is:

  1. Download or clone repo.
  2. cd into project and run poetry install

but, the poetry install will give me following error:

Command ['/home/hhm/.cache/pypoetry/virtualenvs/0ver-department-keyword-d1mZarpb-py3.8/bin/python', '-W', 'ignore', '-'] errored with the following return code 1, and output:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/json/__init__.py", line 106, in <module>
    from .decoder import JSONDecoder, JSONDecodeError
  File "/usr/lib/python3.8/json/decoder.py", line 3, in <module>
    import re
  File "/usr/lib/python3.8/re.py", line 127, in <module>
    import functools
  File "/usr/lib/python3.8/functools.py", line 18, in <module>
    from collections import namedtuple
  File "/usr/lib/python3.8/collections/__init__.py", line 22, in <module>
    from keyword import iskeyword as _iskeyword
  File "/home/hhm/0ver-department-keyword/keyword.py", line 8, in <module>
    import data_model
  File "/home/hhm/0ver-department-keyword/data_model.py", line 4, in <module>
    from ckiptagger import data_utils
ModuleNotFoundError: No module named 'ckiptagger'
input was : import json
import sys

print(json.dumps(sys.path))

Both keyword.py and data_model.py is project business logic, and depend on ckiptagger package to work. Poetry resolve those files and I don't know why.

Current tree:

hms5232@wsl:~/0ver-department-keyword$ tree
.
├── LICENSE
├── README.md
├── __pycache__
│   ├── data_model.cpython-38.pyc
│   └── keyword.cpython-38.pyc
├── data_model.py
├── keyword.py
├── poetry.lock
├── pyproject.toml
└── school_data.csv

1 directory, 9 files

After googling and getting nothing, I try to change project directory as poetry new: mkdir src && mv *.py src/, and poetry install works!

hms5232@wsl:~/0ver-department-keyword$ tree
.
├── LICENSE
├── README.md
├── __pycache__
│   ├── data_model.cpython-38.pyc
│   └── keyword.cpython-38.pyc
├── poetry.lock
├── pyproject.toml
├── school_data.csv
└── src
    ├── data_model.py
    └── keyword.py

2 directories, 9 files

This is happened after Poetry 1.2. If I remember correctly, Poetry 1.1 had worked well. I'm not sure this is a bug or not, or maybe something (ex: pre-releasing note) I missing?

@hms5232 hms5232 added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Sep 26, 2022
@neersighted
Copy link
Member

This is a weird edgecase triggered by having a module named keyword in sys.path, which includes the current directory as a default. This is related to a correctness fix in Poetry 1.2 where we make use of the json module to serialize data when introspecting a Python environment (we run a script inside the environment).

Mostly, I think this is user error -- you are clobbering the name of a standard library module by having a file named keyword at the top level, and your code will be unable to import any module that depends on the standard library keyword module (e.g. json)...

However, I do think Poetry can do better here. We can't prevent the footgun of clobbering a standard library name, but we can invoke Python with -I to isolate any PYTHON* environmental variables, or files in the CWD from crashing our introspection.

@neersighted neersighted added status/confirmed Issue is reproduced and confirmed area/venv Related to virtualenv management version/1.2.1 and removed status/triage This issue needs to be triaged labels Sep 26, 2022
@hms5232
Copy link
Author

hms5232 commented Sep 26, 2022

This is a weird edgecase triggered by having a module named keyword in sys.path, which includes the current directory as a default. This is related to a correctness fix in Poetry 1.2 where we make use of the json module to serialize data when introspecting a Python environment (we run a script inside the environment).

Mostly, I think this is user error -- you are clobbering the name of a standard library module by having a file named keyword at the top level, and your code will be unable to import any module that depends on the standard library keyword module (e.g. json)...

However, I do think Poetry can do better here. We can't prevent the footgun of clobbering a standard library name, but we can invoke Python with -I to isolate any PYTHON* environmental variables, or files in the CWD from crashing our introspection.

Thanks very much for quickly reply. I change keyword.py to something else, Poetry works fine again! I have not faced this problem. After this, I will decide a more suitable name as filename. Thanks you ❤️ .

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
area/venv Related to virtualenv management kind/bug Something isn't working as expected status/confirmed Issue is reproduced and confirmed version/1.2.1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants