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

[BUG] [easy_install] bug on checking the path of the distribution location #4088

Open
spxd opened this issue Oct 21, 2023 · 4 comments · May be fixed by #4098
Open

[BUG] [easy_install] bug on checking the path of the distribution location #4088

spxd opened this issue Oct 21, 2023 · 4 comments · May be fixed by #4098
Labels
bug deprecated Deprecated functionality is *partially* supported in a "best effort" manner help wanted

Comments

@spxd
Copy link

spxd commented Oct 21, 2023

setuptools version

setuptools===68.2.2

Python version

Python 3.10

OS

Windows 11

Additional environment information

No response

Description

I can see if the package source path is already added to the PYTHONPATH then it's failing add the package source directory to the easy-install.pth when I run the "pip install -e ."
 
easy_install.py

    def add(self, dist):
        """Add `dist` to the distribution map"""
        new_path = dist.location not in self.paths and (
            dist.location not in self.sitedirs
            or
            # account for '.' being in PYTHONPATH
            dist.location == os.getcwd()
        )
        if new_path:
            self.paths.append(dist.location)
            self.dirty = True
        super().add(dist)

In def add(self, dist) function in easy_install.py

dist.location == os.getcwd()

This code will return False, because the dist.location is already normcased during finalize_options in develop.py

target = _path.normpath(self.egg_base)

This target is passed as the location in Distribution

   # Make a distribution for the package's source
   self.dist = pkg_resources.Distribution(
       target,
       pkg_resources.PathMetadata(target, os.path.abspath(ei.egg_info)),
       project_name=ei.egg_name,
   )

For example, if the dist.location and os.getcwd() is
dist.location = 'c:\users\abc\work\helloworld'
os.getcwd() = 'C:\Users\abc\work\helloworld'

The result is False, even though they are pointing same path.

it should be updated to

dist.location == os.path.normcase(os.getcwd())

easy_install.py

    def add(self, dist):
        """Add `dist` to the distribution map"""
        new_path = dist.location not in self.paths and (
            dist.location not in self.sitedirs
            or
            # account for '.' being in PYTHONPATH
            # dist.location is _path.nomcased but the os.getcwd() is not
            dist.location == os.path.normcase(os.getcwd())
        )
        if new_path:
            self.paths.append(dist.location)
            self.dirty = True
        super().add(dist)

Expected behavior

The path of source code should be added to the easy-install.pth file when it's installed as editable.

How to Reproduce

Add "." (current path) to the PYTHONPATH then run the "pip install -e ."

Output

If the easy-install.pth is not exist. it will not dump any error.
But if there is easy-install.pth file exist, it will show this erro.

      File "C:\Users\...\lib\site-packages\setuptools\command\easy_install.py", line 1690, in save
        self.dirty |= last_dirty or self.paths != self._init_paths
    TypeError: unsupported operand type(s) for |=: 'list' and 'bool'
@spxd spxd added bug Needs Triage Issues that need to be evaluated for severity and status. labels Oct 21, 2023
@abravalheri
Copy link
Contributor

abravalheri commented Oct 24, 2023

Hi @spxd, I can see that you already did a very in-depth investigation. Thank you very much for that. Would you like to provide a PR as well?

I can see if the package source path is already added to the PYTHONPATH then it's failing add the package source directory to the easy-install.pth when I run the "pip install -e ."

Note however that the latest versions of pip may not use the develop command, but instead rely on PEP 660.
It was planned that pip 23.1+ would already adopt this behaviour by default, but that got postponed for a while. Instead pip will use internal heuristics to decide when to run python setup.py develop or when to use PEP 660 build APIs.

If you want to opt-in for the "new behaviour" you can use pip install --use-pep517 -e .

@abravalheri abravalheri added help wanted deprecated Deprecated functionality is *partially* supported in a "best effort" manner and removed Needs Triage Issues that need to be evaluated for severity and status. labels Oct 24, 2023
@spxd
Copy link
Author

spxd commented Oct 28, 2023

Hi @abravalheri,

Thanks for the response, I tried to upload the code updated but it seems I don't have permission.

remote: Permission to pypa/setuptools.git denied to spxd.

Can I have permission ?
Thanks.

spxd added a commit to spxd/setuptools that referenced this issue Oct 29, 2023
@spxd spxd linked a pull request Oct 29, 2023 that will close this issue
2 tasks
@spxd
Copy link
Author

spxd commented Oct 29, 2023

Thanks @abravalheri !
I could make PR successfully.

spxd added a commit to spxd/setuptools that referenced this issue Oct 31, 2023
spxd added a commit to spxd/setuptools that referenced this issue Nov 4, 2023
abravalheri pushed a commit to spxd/setuptools that referenced this issue Nov 20, 2023
abravalheri pushed a commit to spxd/setuptools that referenced this issue Nov 20, 2023
abravalheri pushed a commit to spxd/setuptools that referenced this issue Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug deprecated Deprecated functionality is *partially* supported in a "best effort" manner help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants