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

Prevent .whl installation (OOTB) on non Win #405

Closed
wants to merge 5 commits into from

Conversation

CristiFati
Copy link
Contributor

@CristiFati CristiFati commented Dec 13, 2022

This is the same as #394, but somehow I got the branches messed up, and ended in a situation that some other commits (already present in the target branch) were included in my PR.

Cherry-picked the commits from the old branch in this one.

The .whl will no longer:

  • Install on non Win
  • Install on Python < 3.7
  • Build on Python 2

junkmd added a commit to junkmd/pywinauto that referenced this pull request Dec 13, 2022
@junkmd junkmd added the drop_py2 dev based on supporting only Python3, see #392 label Dec 13, 2022
@junkmd
Copy link
Collaborator

junkmd commented Dec 14, 2022

@junkmd
Copy link
Collaborator

junkmd commented Dec 14, 2022

@CristiFati

super() in Python3 needs no args. This is a Py2 legacy.
other references:
https://stackoverflow.com/a/576183

I searched bdist_wheel usecases, using super like this is hard to find.
Please let us know what you refer to.

@CristiFati
Copy link
Contributor Author

CristiFati commented Dec 14, 2022

@junkmd: aaargh I forgot about this in my 3rd commit. thank you for pointing it out and sorry for the inconvenience.

junkmd added a commit to junkmd/pywinauto that referenced this pull request Dec 14, 2022
@junkmd
Copy link
Collaborator

junkmd commented Dec 14, 2022

Out of curiosity, do you know where a cheat sheet of wheel module or bdist_wheel class?

When I look up bdist_wheel, almost I see are commands, and it is difficult to find class and function descriptions even in the wheel documentation.

@CristiFati
Copy link
Contributor Author

I don't have a clear location in mind (I'm not an expert in that area). There's always the source code (bdist_wheel.py), and for clear tasks (and source is too vast while time is too short) I browse the web.

@junkmd
Copy link
Collaborator

junkmd commented Dec 14, 2022

@junkmd
Copy link
Collaborator

junkmd commented Dec 14, 2022

@jaraco
You are member of Python Packaging Authority.
You are the expert in these cases and should know much more than I do.

Do you see any concerns with this PR?

Comment on lines +91 to +96
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to try to keep up with all of the supported Python versions, but found it to be a maintenance nightmare. Moreover, it's redundant with the python_requires directive. Just declare Python :: 3 and ignore the sub versions.

Copy link
Collaborator

@jaraco jaraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this change aims to make wheels not installable, it's still not going to prevent their sdist counterparts from being downloaded and installed:

$ py -3.10 -m pip-run --use-pep517 git+https://github.com/CristiFati/comtypes@cfati_dev01
Python 3.10.8 (main, Oct 13 2022, 09:48:40) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import comtypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/folders/sx/n5gkrgfx6zd91ymxr2sr9wvw00n8zm/T/pip-run-m5g6fgu_/comtypes/__init__.py", line 7, in <module>
    from _ctypes import COMError
ImportError: cannot import name 'COMError' from '_ctypes' (/opt/homebrew/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload/_ctypes.cpython-310-darwin.so)

Let's not accept this and the maintenance burden it adds. Instead, if Cristi would like to pursue a more robust fix, I recommend to contribute a feature to the Python packaging ecosystem that allows any project to provide metadata that would satisfy this need.

Comment on lines +69 to +85
try:
from wheel.bdist_wheel import bdist_wheel
class bdist_wheel_win(bdist_wheel):
def get_tag(self):
win_plats = ( # Copied the list from DistUtils
"win-amd64",
"win32",
"win-arm64",
"win-arm32",
)
tag = super().get_tag()
return tuple(tag[:-1]) + (".".join(wp.replace("-", "_") for wp in win_plats),)

except ImportError:
bdist_wheel_win = None


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code feels really brittle. I'd like to see this project and others move away from setup.py altogether. It feels wrong or at least a hack to try to present this module as requiring Windows. It does have a runtime dependency on Windows or at least an implementation of Ctypes that supports the com types, but none of that is part of this package. Moreover, there's nothing special about the wheel that it's not installable on Unix but the sdist is. I'm not confident this unusual, mangled bdist name is going to be supported or useful. It may block releasing to PyPI (though I suspect you've tested this design).

I'm inclined to say no, let's not try to implement platform specificity here. Instead, I'd say to bring this problem to pypa/packaging-problems and explain the use case and request/contribute a solution that any package can avail to declare platform specificity.

@@ -162,6 +183,9 @@ def run(self):
"comtypes.tools",
"comtypes.test",
],

platforms=["Windows"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field is poorly documented, non-standardized, and ineffective. Let's avoid it.

@CristiFati
Copy link
Contributor Author

Considering latest remarks, should I close this PR as well?

@junkmd
Copy link
Collaborator

junkmd commented Dec 24, 2022

After reading @jaraco's review, I now understand why I could not find sufficient description in the setup.py or setutools documentation.

It means that setup.py is no longer recommended in modern Python packages, and it is recommended to write configuration values in setup.cfg or pyproject.toml.

I think @CristiFati can contribute to this project by moving the package settings to setup.cfg or pyproject.toml.

As for introducing a configuration value that would limit installation to Windows only, I think that will come after pypa implements that feature.

I am trying to install an auto-formatter in #418, which may cause conflicts in setup.cfg or pyproject.toml depending on when we PR.

If @CristiFati can contribute on the migration from setup.py, we can discuss them.

@junkmd junkmd deleted the branch enthought:drop_py2 December 24, 2022 04:16
@junkmd junkmd closed this Dec 24, 2022
@junkmd junkmd reopened this Dec 24, 2022
@junkmd
Copy link
Collaborator

junkmd commented Dec 24, 2022

I’m sorry. I restored branch.

@junkmd
Copy link
Collaborator

junkmd commented Dec 24, 2022

@CristiFati

test_pip_install.py and appveyor.yml call setup.py.

It will probably change to a command like running pip install https://github.com/USERNAME/comtypes/archive/refs/heads/BRANCHNAME.

@CristiFati
Copy link
Contributor Author

CristiFati commented Dec 24, 2022

I didn't work with pyproject.toml or setup.cfg, I don't know the differences between them and why someone would choose one over the other. So, even if I'd try doing it, I'm sure that an expert on the area would be able to complete it much faster and better.

I was aiming to solve a problem (although it's not such a big deal, and I also mentioned this package in [SO]: Install win32com on MacOs and Linux (@CristiFati's answer)) that I discovered accidentally on SO, (also the place / way that I chose to solve it was a bad one), but apparently there's way more going on, that people like me (outside main maintainers group) are unaware of.

Therefore I propose to close this, and when things will settle (and directions will be clear), "outsiders" will have more chances to contribute.

@junkmd
Copy link
Collaborator

junkmd commented Dec 25, 2022

@CristiFati

OK. I will close this in the coming days. Thank you for your suggestion.

Followings is that I have been able to find out.

Previous versions of xlwings (which used to use this package as a dependency) and the current pywinauto use a conditional branch using sys.platform in setup.py to select the package to be dependencies.

https://github.com/pywinauto/pywinauto/blob/f78302c7df7a71980953d3007ed72de6a2a8e604/setup.py#L59-L74
https://github.com/xlwings/xlwings/blob/0.20.8/setup.py#L15-L32

From these examples, I believe that the responsibility for not allowing the package to be installed that cannot be used with the OS type lies not with pypa or the package itself, but with the project that uses it as a dependency.

So, if you propose to set up the sys.platform conditional branch in setup.py (or equivalent) of the project that uses comtypes, I think that would do what you want to do for a start.

@CristiFati CristiFati deleted the cfati_dev01 branch December 26, 2022 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drop_py2 dev based on supporting only Python3, see #392
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants