microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.34k stars 1.19k forks source link

CWD directory is set wrongly for YAPF to format. #9661

Closed rvanlaar closed 4 years ago

rvanlaar commented 4 years ago

Environment data

Expected behaviour

YAPF formats the file

Actual behaviour

Yapf doesn't format the file, and doesn't show error messages.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Can't reproduce outside of client project.
  2. Installed Django 1.11

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

> ~/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/bin/python -m yapf --diff ~/EduWorld/back-end/edu_world/N2L/archive.py
cwd: ~/EduWorld/back-end/edu_world/N2L

Running this command on the terminal results in the following traceback:

Traceback (most recent call last):
  File "/home/roland/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/home/roland/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/home/roland/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/yapf/__init__.py", line 30, in <module>
    import argparse
  File "/home/roland/.pyenv/versions/3.6.9/lib/python3.6/argparse.py", line 87, in <module>
    import copy as _copy
  File "/home/roland/EduWorld/back-end/edu_world/N2L/copy.py", line 8, in <module>
    from django.db.models import QuerySet
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/db/models/__init__.py", line 3, in <module>
    from django.db.models.aggregates import *  # NOQA
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/db/models/aggregates.py", line 5, in <module>
    from django.db.models.expressions import Func, Star
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/db/models/expressions.py", line 6, in <module>
    from django.db.models import fields
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 14, in <module>
    from django import forms
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/forms/__init__.py", line 6, in <module>
    from django.forms.boundfield import *  # NOQA
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/forms/boundfield.py", line 7, in <module>
    from django.forms.widgets import Textarea, TextInput
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/forms/widgets.py", line 14, in <module>
    from django.templatetags.static import static
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/templatetags/static.py", line 1, in <module>
    from django import template
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/template/__init__.py", line 44, in <module>
    from .engine import Engine
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/template/engine.py", line 6, in <module>
    from .base import Context, Template
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/template/base.py", line 59, in <module>
    from django.template.context import (  # NOQA: imported for backwards compatibility
  File "/home/roland/.cache/pypoetry/virtualenvs/eduworld-sNwkCRg1-py3.6/lib/python3.6/site-packages/django/template/context.py", line 3, in <module>
    from copy import copy
ImportError: cannot import name 'copy'

This doesn't happen when the command is run in the project root directory.

brettcannon commented 4 years ago

This is occurring because you have a file named copy.py in your project which is shadowing the copy module from Python's standard library. Please rename that file and the issue should go away.

rvanlaar commented 4 years ago

Indeed, I do have a file named copy.py in my directory.

What a strange way of closing an issue. You point to a solution without seeing the problems it raised.

1) There wasn't any error shown that there was an error formatting, 2) The CWD (current working directory) shouldn't have been inside my package and 3) I can't go about renaming every file because it clashes with a python package name.

So please reconsider opening this issue and work towards a fix so others don't have to hunt this down.