Skip to content

feat: Support extras in stubtest_third_party.py #8467

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

Merged
merged 8 commits into from
Aug 18, 2022
Merged

feat: Support extras in stubtest_third_party.py #8467

merged 8 commits into from
Aug 18, 2022

Conversation

kkirsche
Copy link
Contributor

@kkirsche kkirsche commented Aug 2, 2022

X-Ref: #8457 (comment)

This pull request adds a new key to the METADATA.toml file, under the tool.stubtest key, named extras_dependencies. This key is to allow the use of extras when running stubtest in upstream tests.

For example, the current schema would change from:

version = ...
requires = ...
extra_description = ...
obsolete_since = ...
no_longer_updated = ...

[tool.stubtest]
skip = ...
apt_dependencies = ...
ignore_missing_stubs = ...

to:

version = ...
requires = ...
extra_description = ...
obsolete_since = ...
no_longer_updated = ...

[tool.stubtest]
skip = ...
apt_dependencies = ...
extras_dependencies = ["sock"]; # the list of names of extras to install.
ignore_missing_stubs = ...

The reason for this is that when a stub, such as urllib3, which provides contributor functionality based on other libraries, such as PySock, may have a complex version dependency. In those cases, rather than trying to ensure that the version specification is manually or automatically detected as updated, this bypasses the issue by ensuring that we're using the version specification defined by the upstream library, tracking it as it changes.

@AlexWaygood
Copy link
Member

AlexWaygood commented Aug 2, 2022

Thanks!

Do any of our stubs packages that currently have requirements-stubtest.txt files specify extra dependencies at runtime? If so, can you update the stubs for those packages so that they use this new key, instead of the requirements-stubtest.txt file, as part of this PR? That way we can see whether stubtest still works correctly on those packages with this change.

@github-actions

This comment has been minimized.

@kkirsche
Copy link
Contributor Author

kkirsche commented Aug 2, 2022

Thanks!

Do any of our stubs packages that currently have requirements-stubtest.txt files specify extra dependencies at runtime? If so, can you update the stubs for those packages so that they use this new key, instead of the requirements-stubtest.txt file, as part of this PR? That way we can see whether stubtest still works correctly on those packages with this change.

I've updated all the stubs that currently use extras. Depending on the merge order between this and #8457, I'll merge and update whichever merge request gets merged second with any required changes

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

extras_dependencies is a little confusing to me, since it's not clear whether it's a list of names of extras or a list of names of dependencies. Maybe extras or extras_to_install?

dist_req = f"{dist.name}=={dist_version}"
assert isinstance(extras_dependencies, list)
dist_extras = ", ".join(extras_dependencies)
dist_req = f"{dist.name}[{dist_extras}]=={dist_version}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh, didn't realise this, but pip install pkg[] does work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, as long as you conform to the structure, the behavior will work. It's only if you break the calling structure that it fails to execute :)

@kkirsche
Copy link
Contributor Author

kkirsche commented Aug 2, 2022

extras_dependencies is a little confusing to me, since it's not clear whether it's a list of names of extras or a list of names of dependencies. Maybe extras or extras_to_install?

I'm perfectly happy with those, but will through out a few others in case they help:

  • requires_extras
  • stubs_use_extras
  • tests_require_extras
  • stubs_require_extras

Just let me know the preference, and I can proceed with that

Kevin Kirsche added 3 commits August 4, 2022 10:23
* master:
  Add `urllib3.contrib.socks`; improve `urllib3.connectionpool` (#8457)
  Improve `multiprocessing.context` module (#8466)
  Always return `True` from `xml.dom.minidom.Node.__bool__` (#8480)
  Adds missing `__dir__` definitions (#8479)
  Various pyvmomi improvements (#8469)
  Bump pytype version. (#8478)
  Remove `Enum.__hash__`, improve `Enum.__reduce_ex__` (#8477)
  refactor: prefer f-strings to other format/concatentation styles (#8474)
  Remove redundant `__str__` methods (#8475)
  Add some missing stubs in datetimerange (#8470)
  tkinter: get rid of unnecessary Incomplete (#8471)
  Improve urllib3.util.url annotations (#8460)
  Fix `complex` constructor (#8473)
  [pre-commit.ci] pre-commit autoupdate (#8461)
  Use typeshed.Incomplete and object instead of Any in tkinter stubs (#8458)
  `io.IOBase`: correct metaclass (#8468)
@kkirsche
Copy link
Contributor Author

kkirsche commented Aug 4, 2022

Updated:

  1. Merged latest master to pick up the changes from Add urllib3.contrib.socks; improve urllib3.connectionpool #8457
  2. Updated Add urllib3.contrib.socks; improve urllib3.connectionpool #8457 to install extras via this feature.
  3. Updated extras_dependencies to extras
  4. Clarification is required (either from discussion or trial and error about test failures) from the team about feat: Support extras in stubtest_third_party.py #8467 (comment) as lxml (as I understand it) would not be installed with the extras.

@github-actions

This comment has been minimized.

@kkirsche
Copy link
Contributor Author

kkirsche commented Aug 4, 2022

#8439 will, if merged, also be a candidate for this via https://github.com/psf/requests/blob/main/setup.py#L125

EDIT: fix the links

Kevin Kirsche added 2 commits August 18, 2022 08:31
* master: (51 commits)
  Update pytype_test to be compatible with the latest pytype version. (#8551)
  Normalise use of `Never` vs `NoReturn` (#8549)
  Add stubs for tree-sitter-languages (#8548)
  Add SAFE_RESTARTABLE strategy to ldap3 Connection client_strategy parameter (#8547)
  Add stubs for tree_sitter (#8533)
  Additional return types for psycopg2 connections (#8528)
  fpdf2: fix for 2.5.6 changes (#8546)
  cryptography: Rename parameter of serialize_key_and_certificates (#8543)
  Add `_threading_local.local.__delattr__` back to the stub (#8526)
  Fix `UDPServer` to correctly inherit from `TCPServer` (#8542)
  Upgrade pyright (#8541)
  Add "Naming convention" to `test_cases/README.md` (#8521)
  Improve `.keys()`, `.values()`, `.items()` methods for `TypedDict`s (#8532)
  setuptools: fix stubtest (#8540)
  Annotate Model in SQLAlchemy (#8535)
  Unpin stubtest from 3.10.5 (#8523)
  [stubsabot] Bump setuptools to 64.0.* (#8534)
  Add `@type_check_only` to two fictional classes in `builtins.pyi` (#8531)
  Enable flake8-pyi's Y034 check in `stdlib/typing.pyi` (#8530)
  setuptools: delete _distutils.command.check.HAS_DOCUTILS (#8529)
  ...
@kkirsche
Copy link
Contributor Author

Merge request updated with the extras for requests since #8485 was merged.

This is using the socks extra seen here:
https://github.com/psf/requests/blob/main/setup.py#L125

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@hauntsaninja hauntsaninja 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 updating, sorry for the delay here! :-)

@hauntsaninja hauntsaninja merged commit 8c51fab into python:master Aug 18, 2022
@kkirsche
Copy link
Contributor Author

Thanks for updating, sorry for the delay here! :-)

No worries, life happens 🙂 thanks for your time

@kkirsche kkirsche deleted the feat/stubtest-extras branch September 2, 2022 13:48
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.

4 participants