ericvsmith / dataclasses

Apache License 2.0
587 stars 53 forks source link

Adding a python_requires < 3.7 #146

Closed georgealton closed 5 years ago

georgealton commented 5 years ago

Would adding a python_requires = '<3.7', configuration to the setup.py, to prevent this package from being installed in python environments >=3.7, be helpful?

This would help to prevent accidental shadowing of the builtin dataclass package, and then triggering some of the incompatability issues

ericvsmith commented 5 years ago

Does that actually work? It's an honest question: I never specify versions in setup.py, only in requirements.txt.

If I'm installing a 3.7 venv with a requirements.txt that specifies dataclasses, with no python_requires, will pip not install dataclasses if its setup.py says python_requires = '<3.7'?

georgealton commented 5 years ago

That's my interpretation of the option from the guide; https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires

I just had a go at creating that scenario - pip refused to install my local modified version of dataclasses with the marker;

image

Here usage of this functionality in hypothesis https://github.com/HypothesisWorks/hypothesis/blob/f6642662f9f56687817e49c6fd25c30e79d2b2a6/setup.py#L77

edo248 commented 5 years ago

It indeed works, by adding data value in the pip index which pip honors. You can see this data by looking at the source of index for some package. Even for pip itself, check source code of https://pypi.org/simple/pip

An example lines looks like this:

<a href="https://files.pythonhosted.org/....." 
      data-requires-python="&gt;=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*">
                 pip-19.2.tar.gz
</a>
<br/>
ericvsmith commented 5 years ago

I just released 0.7 on pypi to address this issue. Sorry for the long delay.

luckydonald commented 5 years ago

With typing already being present in python 3.5, why is this backport 3.6 only?

ericvsmith commented 5 years ago

Because variable annotations (PEP 526) didn't show up until 3.6, and dataclasses requires them.

luckydonald commented 5 years ago

Oh I thought it would only be the format strings

f"Some {variable!r}"

which could be "downgraded" to

"Some {variable!r}".format(variable=variable)

Thanks for clarifying.