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

Declare missing dependencies #290

Merged
merged 8 commits into from
Dec 14, 2021
Merged

Declare missing dependencies #290

merged 8 commits into from
Dec 14, 2021

Conversation

squahtx
Copy link
Contributor

@squahtx squahtx commented Dec 14, 2021

It's best to look at the commits separately.
The first commit sorts the list of dependencies.

Fixes #289

@squahtx squahtx requested a review from a team as a code owner December 14, 2021 13:51
@squahtx
Copy link
Contributor Author

squahtx commented Dec 14, 2021

The minimum package versions for attrs and typing-extensions are copied from Synapse:
https://github.com/matrix-org/synapse/blob/eb39da6782b57c939450839097f32a14cba3ebfc/synapse/python_dependencies.py#L81-L85

The minimum package version for pyopenssl is copied from aioapns:
https://github.com/Fatal1ty/aioapns/blob/master/setup.py#L30

Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

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

Thanks for this!

setup.py Outdated
Comment on lines 48 to 49
"mypy==0.812",
"mypy-zope==0.3.0",
"tox",
"mypy==0.812",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd put mypy-zope after mypy. But perhaps mypy- comes before mypy=?

Fine as it is, just an aside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot, I'll fix it.

setup.py Outdated
@@ -23,6 +23,7 @@

INSTALL_REQUIRES = [
"aioapns>=1.10",
"attrs>=19.2.0",
"cryptography>=2.6.1",
"idna>=2.8",
"importlib_metadata",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want/have a lower bound here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly to comment on typing-extensions, should we declare this as importlib_metadata; python_version < "3.8" (assuming we don't need the new importlib.metadata bits from 3.10)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps. I have no idea what the lower bound should be

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reference, this is what we do in python-signedjson: matrix-org/python-signedjson#9

@DMRobertson
Copy link
Contributor

Another thought: why did CI miss this? I guess there's no equivalent of the olddeps job that Synapse has?

@callahad
Copy link
Contributor

Another thought: why did CI miss this? I guess there's no equivalent of the olddeps job that Synapse has?

I think we're not testing against older python versions (e.g., I think setting up a matrix of ['3.7', '3.x'] would've found it)

setup.py Outdated
"sentry-sdk>=0.10.2",
"service_identity>=18.1.0",
"Twisted>=19.7",
"typing-extensions>=3.7.4",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make this conditional so it's only installed on Py < 3.8? (And do the same for the import that needs it)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we typically import directly from typing_extensions; would have to change the source to do a try...except ImportError... dance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the import side, mypy does not appreciate the obvious attempt:
https://mypy-play.net/?mypy=latest&python=3.10&gist=9ac99f23480e5c8bc86c68f94ce65b6c

if TYPE_CHECKING or sys.version_info < (3, 8, 0):
    from typing_extensions import Literal
else:
    from typing import Literal

works with mypy but always requires typing_extensions in dev.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a PR to do the same for python-signedjson here: matrix-org/python-signedjson#12

@reivilibre
Copy link
Contributor

Another thought: why did CI miss this? I guess there's no equivalent of the olddeps job that Synapse has?

Possibly because it was brought in by a dev dependency (e.g. mypy) and was present during the tests. :/

@reivilibre
Copy link
Contributor

reivilibre commented Dec 14, 2021

Another thought: why did CI miss this? I guess there's no equivalent of the olddeps job that Synapse has?

I think we're not testing against older python versions (e.g., I think setting up a matrix of ['3.7', '3.x'] would've found it)

3.7, the one we test with, is the oldest version we support iirc.

DMRobertson
DMRobertson previously approved these changes Dec 14, 2021
Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

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

I'm happy if CI is happy. Sanity check: would this have fixed the earlier deployment to matrix.org?

@squahtx
Copy link
Contributor Author

squahtx commented Dec 14, 2021

I'm happy if CI is happy. Sanity check: would this have fixed the earlier deployment to matrix.org?

It ought to, assuming we do a pip install as part of the deployment.
I have no idea how we'd test this apart from doing another deployment.

@DMRobertson
Copy link
Contributor

I have no idea how we'd test this apart from doing another deployment.

Maybe a pip install -e .? But yeah, probably best to try it and see.

@squahtx
Copy link
Contributor Author

squahtx commented Dec 14, 2021

Maybe a pip install -e .? But yeah, probably best to try it and see.

A pip install -r <(./scripts-dev/old_deps.py) seems to be okay.


On another note, mypy really does not like conditional imports. Getting the right combination of type: ignores is far from simple.

Python 3.7:

sygnal/__init__.py:17: error: Module 'importlib.metadata' has no attribute 'PackageNotFoundError'  [attr-defined]
sygnal/__init__.py:17: error: Module 'importlib.metadata' has no attribute 'version'  [attr-defined]

Python 3.8, importlib_metadata installed:

sygnal/__init__.py:22: error: Incompatible import of "PackageNotFoundError" (imported name has type "Type[importlib_metadata.PackageNotFoundError]", local name has type "Type[importlib.metadata.PackageNotFoundError]")  [misc]

Python 3.8, importlib_metadata not installed:

sygnal/__init__.py:22: error: Name 'PackageNotFoundError' already defined (possibly by an import)  [no-redef]
sygnal/__init__.py:22: error: Name 'version' already defined (possibly by an import)  [no-redef]

@DMRobertson
Copy link
Contributor

On another note, mypy really does not like conditional imports. Getting the right combination of type: ignores is far from simple.

Ouch, thanks for working through that. Is there any way that we could use TYPE_CHECKING to help? I guess not, since it's sensitive to the version of the stdlib that's running mypy(?)

@squahtx
Copy link
Contributor Author

squahtx commented Dec 14, 2021

Ouch, thanks for working through that. Is there any way that we could use TYPE_CHECKING to help? I guess not, since it's sensitive to the version of the stdlib that's running mypy(?)

I can't see how, unless we unconditionally use importlib_metadata when type checking.

and you've made me realise that the dependencies are wrong. typing_extensions is only installed on Python <3.8, but we use it in type checking mode regardless.

@squahtx
Copy link
Contributor Author

squahtx commented Dec 14, 2021

mypy brings in typing-extensions for us, but we should be explicit.

@DMRobertson
Copy link
Contributor

DMRobertson commented Dec 14, 2021

I'm happy if CI is happy. Sanity check: would this have fixed the earlier deployment to matrix.org?

It ought to, assuming we do a pip install as part of the deployment. I have no idea how we'd test this apart from doing another deployment.

Ahhh, I was more getting at "why did the deployment fail?" so we could check this fixes it. The cause was an inability to import typing_extensions, but that's now been made a hard requirement.

Edit: a hard requirement on sufficiently old Pythons.

So I think this is hopefully good to go! 👍

@squahtx squahtx merged commit d85aa6c into main Dec 14, 2021
@squahtx squahtx deleted the squah/declare_dependencies branch December 14, 2021 17:51
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

Successfully merging this pull request may close these issues.

Undeclared dependencies
4 participants