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

Editable install of screenpy in IDE fails to recognize code #26

Closed
MarcelWilson opened this issue Sep 22, 2022 · 1 comment
Closed

Editable install of screenpy in IDE fails to recognize code #26

MarcelWilson opened this issue Sep 22, 2022 · 1 comment

Comments

@MarcelWilson
Copy link
Contributor

MarcelWilson commented Sep 22, 2022

When using screepy package via editable install (i.e. pip install -e ~/projects/screenpy) IDE code editors fail to recognize the package is installed (imports appear with red underlines). The package will work at runtime but the editor is rendered useless because the IDE can't figure out where the code is on the drive.

This appears to have started with the introduction of the pyproject.toml file in 352c97c .

Further explanation about what's happening can be found here:
python/mypy#13392 (comment)

I also experienced this problem and traced it down to setuptools v64 causing the issue. This version of setuptools seems to cause editable packages to no longer be installed with an egg-link file and now uses another mechanism. See release notes here: https://setuptools.pypa.io/en/latest/history.html#v64-0-0

If the editable package belongs to you, you could modify your pyproject.toml like this:

requires = [
  "setuptools==63.4.3",
  "wheel"
]

Apparently pip prioritizes using the pyproject.toml over the setup.py when installing the package. In its current state, our pyproject.toml doesn't define [build-system] so pip defaults to the Fallback Behavior by using the latest version of setuptools. As mentioned in the quote above, v64 setuptools changed how editable installations work. See python/mypy#13392 (comment)

Oh, so setuptools has switched to using some import hook based approach instead of static entries in pth files? Note that the super standard pth file static directory install that everyone has been using for decades is perfectly valid under PEP 660.

I don't think there's any way for IDEs and static analysis tools to support import hooks. See
https://mail.python.org/archives/list/[email protected]/thread/IIVBPYDZR5T5BGPAWFVYS5ZPYDXGVHQN/#OSWHT5VSRGKPSPYD7PQWR2M4OCSL5WO3 where maintainers of PyCharm, VSCode, Pyright, Pyre, etc are all on the same page about this.

The immediate solution would be to configure the toml to use setuptools 63 until pypa/setuptools#3518 is resolved. Or we could consider using a different backend to install the project (e.g. poetry, flit, etc).

Since python is moving away from using setup.py to pyproject.toml to configure the install of packages this might be the perfect time to look at what we want in the toml beyond the immediate issue of editable installs.

@MarcelWilson
Copy link
Contributor Author

As mentioned above, there are alternatives to setuptool we could consider.

At the risk of sounding self-serving, I have found poetry-core configured as the backend in the pyproject.toml works when doing editable installs. poetry-core handles the installation of the packages whereas poetry is a full fledged project management tool. Users would not need install poetry in order for us to take advantage of their installer.

It also has the added benefit of allowing screenpy contributors to use poetry to fully manage their environments when branch switching without having to manually manipulate dependencies.

MarcelWilson pushed a commit to bandophahita/screenpy that referenced this issue Sep 22, 2022
MarcelWilson pushed a commit to bandophahita/screenpy that referenced this issue Sep 22, 2022
MarcelWilson pushed a commit to bandophahita/screenpy that referenced this issue Sep 22, 2022
MarcelWilson pushed a commit to bandophahita/screenpy that referenced this issue Sep 22, 2022
bandophahita added a commit that referenced this issue Oct 12, 2022
* #26 using pyproject.toml to configure installation of package

Co-authored-by: Marcel Wilson <[email protected]>
bandophahita added a commit to bandophahita/screenpy that referenced this issue Oct 14, 2022
)

* ScreenPyHQ#26 using pyproject.toml to configure installation of package

Co-authored-by: Marcel Wilson <[email protected]>
bandophahita added a commit to bandophahita/screenpy that referenced this issue Oct 14, 2022
)

* ScreenPyHQ#26 using pyproject.toml to configure installation of package

Co-authored-by: Marcel Wilson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants