-
-
Notifications
You must be signed in to change notification settings - Fork 650
feat!: Following generation mode when generating test targets #2044
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
Conversation
|
In order for this to be mergeable we should be the policy outlined here: https://rules-python.readthedocs.io/en/latest/contributing.html#breaking-changes So we should go with the approach of an extra directive, which we may later set to default to some other value than today. Maybe it could default to |
|
Added the directive and updated readme to include the macro. Please take another look |
aignas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, added a CHANGELOG entry for a future release announcement.
…les (#2998) Remove entry point file requirements when generating rules. Enable python rule generation as long as there are .py source files under the directory so all new packages will have python rules generated in the package. The extension used to require entrypoints for generation but: - entry point for tests (i.e., `__test__.py` ) is no longer required after #999 and #2044 - entry point for binaries (i.e., `__main__.py` ) is no longer required after #1584 The entry point for libraries (`__init__.py` ) shouldn't be required either, especially for Python 3.3 and after when namespace packages are supported. --------- Co-authored-by: yushan <yushan@uber.com> Co-authored-by: Douglas Thor <dougthor42@users.noreply.github.com>
…les (bazel-contrib#2998) Remove entry point file requirements when generating rules. Enable python rule generation as long as there are .py source files under the directory so all new packages will have python rules generated in the package. The extension used to require entrypoints for generation but: - entry point for tests (i.e., `__test__.py` ) is no longer required after bazel-contrib#999 and bazel-contrib#2044 - entry point for binaries (i.e., `__main__.py` ) is no longer required after bazel-contrib#1584 The entry point for libraries (`__init__.py` ) shouldn't be required either, especially for Python 3.3 and after when namespace packages are supported. --------- Co-authored-by: yushan <yushan@uber.com> Co-authored-by: Douglas Thor <dougthor42@users.noreply.github.com>
When
python_generation_modeisprojectorfile, the generatedpy_testtargets are consistent withpy_library. However, whenpython_generation_modeispackage, it becomes inconsistent: it requires either__test__target or__test__.pyfile to generatepy_testin package mode, otherwise it will fall back to file mode.This PR relaxes this requirement with a new directive
gazelle:python_generation_mode_per_package_require_test_entry_point. Whent it's set to false, Gazelle and generates onepy_testtarget per package in package mode even without entry points.This allows people to use
gazelle:map_kindto mappy_testto a macro that sets a default test runner, such as rules_python_pytest or pytest-bazel, and generate one test target per package. The behavior whengazelle:python_generation_modeis "file" or "project" remains the same.This fixes #1972 for supporting pytest from Gazelle. With this approach, people can define a thin macro like this to use py_pytest_main:
BREAKING CHANGES:
Without
gazelle:map_kindor__test__target or__test__.py, the package mode will now generatepy_testwithoutmainattribute, which may not be runnable. However, this is already an issue with "python_generation_mode:project" before this PR.The default value of
gazelle:python_generation_mode_per_package_require_test_entry_pointis true to preserve the current behavior. We will flip that default value in the future.