@@ -17,7 +17,10 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file")
1717load ("//examples/wheel/private:wheel_utils.bzl" , "directory_writer" , "make_variable_tags" )
1818load ("//python:defs.bzl" , "py_library" , "py_test" )
1919load ("//python:packaging.bzl" , "py_package" , "py_wheel" )
20+ load ("//python:pip.bzl" , "compile_pip_requirements" )
2021load ("//python:versions.bzl" , "gen_python_config_settings" )
22+ load ("//python/entry_points:py_console_script_binary.bzl" , "py_console_script_binary" )
23+ load ("//python/private:bzlmod_enabled.bzl" , "BZLMOD_ENABLED" ) # buildifier: disable=bzl-visibility
2124
2225package (default_visibility = ["//visibility:public" ])
2326
@@ -56,6 +59,10 @@ py_wheel(
5659 # Package data. We're building "example_minimal_library-0.0.1-py3-none-any.whl"
5760 distribution = "example_minimal_library" ,
5861 python_tag = "py3" ,
62+ # NOTE: twine_binary = "//tools/publish:twine" does not work on non-bzlmod
63+ # setups because the `//tools/publish:twine` produces multiple files and is
64+ # unsuitable as the `src` to the underlying native_binary rule.
65+ twine = None if BZLMOD_ENABLED else "@rules_python_publish_deps_twine//:pkg" ,
5966 version = "0.0.1" ,
6067 deps = [
6168 "//examples/wheel/lib:module_with_data" ,
@@ -348,3 +355,39 @@ py_test(
348355 "//python/runfiles" ,
349356 ],
350357)
358+
359+ # Test wheel publishing
360+
361+ compile_pip_requirements (
362+ name = "requirements_server" ,
363+ src = "requirements_server.in" ,
364+ )
365+
366+ py_test (
367+ name = "test_publish" ,
368+ srcs = ["test_publish.py" ],
369+ data = [
370+ ":minimal_with_py_library" ,
371+ ":minimal_with_py_library.publish" ,
372+ ":pypiserver" ,
373+ ],
374+ env = {
375+ "PUBLISH_PATH" : "$(location :minimal_with_py_library.publish)" ,
376+ "SERVER_PATH" : "$(location :pypiserver)" ,
377+ "WHEEL_PATH" : "$(rootpath :minimal_with_py_library)" ,
378+ },
379+ target_compatible_with = select ({
380+ "@platforms//os:linux" : [],
381+ "@platforms//os:macos" : [],
382+ "//conditions:default" : ["@platforms//:incompatible" ],
383+ }),
384+ deps = [
385+ "@pypiserver//pypiserver" ,
386+ ],
387+ )
388+
389+ py_console_script_binary (
390+ name = "pypiserver" ,
391+ pkg = "@pypiserver//pypiserver" ,
392+ script = "pypi-server" ,
393+ )
0 commit comments