diff --git a/docs/BUILD b/docs/BUILD index 6c19d11b67..541f9c1943 100644 --- a/docs/BUILD +++ b/docs/BUILD @@ -88,3 +88,9 @@ stardoc( out = "whl.md", input = "//python:whl.bzl", ) + +stardoc( + name = "packaging-docs", + out = "packaging.md", + input = "//python:packaging.bzl", +) diff --git a/docs/packaging.md b/docs/packaging.md new file mode 100755 index 0000000000..bf3d08f9d5 --- /dev/null +++ b/docs/packaging.md @@ -0,0 +1,315 @@ + + + + +## py_package + +
+py_package(name, deps, packages) ++ +A rule to select all files in transitive dependencies of deps which +belong to given set of Python packages. + +This rule is intended to be used as data dependency to py_wheel rule + + +### Attributes + +
name |
+
+ Name; required
+ + A unique name for this target. + + |
+
deps |
+ + List of labels; optional + | +
packages |
+
+ List of strings; optional
+ + List of Python packages to include in the distribution. +Sub-packages are automatically included. + + |
+
+py_wheel(name, abi, author, author_email, classifiers, console_scripts, deps, description_file, distribution, entry_points, extra_requires, homepage, license, platform, python_requires, python_tag, requires, strip_path_prefixes, version) ++ + +A rule for building Python Wheels. + +Wheels are Python distribution format defined in https://www.python.org/dev/peps/pep-0427/. + +This rule packages a set of targets into a single wheel. + +Currently only pure-python wheels are supported. + +Examples: + +```python +# Package just a specific py_libraries, without their dependencies +py_wheel( + name = "minimal_with_py_library", + # Package data. We're building "example_minimal_library-0.0.1-py3-none-any.whl" + distribution = "example_minimal_library", + python_tag = "py3", + version = "0.0.1", + deps = [ + "//examples/wheel/lib:module_with_data", + "//examples/wheel/lib:simple_module", + ], +) + +# Use py_package to collect all transitive dependencies of a target, +# selecting just the files within a specific python package. +py_package( + name = "example_pkg", + # Only include these Python packages. + packages = ["examples.wheel"], + deps = [":main"], +) + +py_wheel( + name = "minimal_with_py_package", + # Package data. We're building "example_minimal_package-0.0.1-py3-none-any.whl" + distribution = "example_minimal_package", + python_tag = "py3", + version = "0.0.1", + deps = [":example_pkg"], +) +``` + + +### Attributes + +
name |
+
+ Name; required
+ + A unique name for this target. + + |
+
abi |
+
+ String; optional
+ + Python ABI tag. 'none' for pure-Python wheels. + + |
+
author |
+
+ String; optional
+ + A string specifying the author of the package. + + |
+
author_email |
+
+ String; optional
+ + A string specifying the email address of the package author. + + |
+
classifiers |
+
+ List of strings; optional
+ + A list of strings describing the categories for the package. + + |
+
console_scripts |
+
+ Dictionary: String -> String; optional
+ + Deprecated console_script entry points, e.g. `{'main': 'examples.wheel.main:main'}`. + +Deprecated: prefer the `entry_points` attribute, which supports `console_scripts` as well as other entry points. + + |
+
deps |
+
+ List of labels; optional
+ + Targets to be included in the distribution. + +The targets to package are usually `py_library` rules or filesets (for packaging data files). + +Note it's usually better to package `py_library` targets and use +`entry_points` attribute to specify `console_scripts` than to package +`py_binary` rules. `py_binary` targets would wrap a executable script that +tries to locate `.runfiles` directory which is not packaged in the wheel. + + |
+
description_file |
+
+ Label; optional
+ + A file containing text describing the package in a single line. + + |
+
distribution |
+
+ String; required
+ + Name of the distribution. + +This should match the project name onm PyPI. It's also the name that is used to +refer to the package in other packages' dependencies. + + |
+
entry_points |
+
+ Dictionary: String -> List of strings; optional
+ + entry_points, e.g. `{'console_scripts': ['main = examples.wheel.main:main']}`. + + |
+
extra_requires |
+
+ Dictionary: String -> List of strings; optional
+ + List of optional requirements for this package + + |
+
homepage |
+
+ String; optional
+ + A string specifying the URL for the package homepage. + + |
+
license |
+
+ String; optional
+ + A string specifying the license of the package. + + |
+
platform |
+
+ String; optional
+
+ Supported platform. Use 'any' for pure-Python wheel.
+
+If you have included platform-specific data, such as a .pyd or .so
+extension module, you will need to specify the platform in standard
+pip format. If you support multiple platforms, you can define
+platform constraints, then use a select() to specify the appropriate
+specifier, eg:
+
+ |
+
python_requires |
+
+ String; optional
+ + A string specifying what other distributions need to be installed when this one is. See the section on [Declaring required dependency](https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#declaring-dependencies) for details and examples of the format of this argument. + + |
+
python_tag |
+
+ String; optional
+ + Supported Python version(s), eg `py3`, `cp35.cp36`, etc + + |
+
requires |
+
+ List of strings; optional
+ + List of requirements for this package + + |
+
strip_path_prefixes |
+
+ List of strings; optional
+ + path prefixes to strip from files added to the generated package + + |
+
version |
+
+ String; required
+ + Version number of the package + + |
+
+platform = select({
+ "//platforms:windows_x86_64": "win_amd64",
+ "//platforms:macos_x86_64": "macosx_10_7_x86_64",
+ "//platforms:linux_x86_64": "manylinux2014_x86_64",
+})
+
""",
),
"python_tag": attr.string(
default = "py3",
- doc = "Supported Python version(s), eg 'py3', 'cp35.cp36', etc",
+ doc = "Supported Python version(s), eg `py3`, `cp35.cp36`, etc",
),
"version": attr.string(
mandatory = True,
@@ -243,26 +247,51 @@ _requirement_attrs = {
_entrypoint_attrs = {
"console_scripts": attr.string_dict(
doc = """\
-Deprecated console_script entry points, e.g. {'main': 'examples.wheel.main:main'}.
+Deprecated console_script entry points, e.g. `{'main': 'examples.wheel.main:main'}`.
Deprecated: prefer the `entry_points` attribute, which supports `console_scripts` as well as other entry points.
""",
),
"entry_points": attr.string_list_dict(
doc = """\
-entry_points, e.g. {'console_scripts': ['main = examples.wheel.main:main']}.
+entry_points, e.g. `{'console_scripts': ['main = examples.wheel.main:main']}`.
""",
),
}
_other_attrs = {
- "author": attr.string(default = ""),
- "author_email": attr.string(default = ""),
- "classifiers": attr.string_list(),
- "description_file": attr.label(allow_single_file = True),
- "homepage": attr.string(default = ""),
- "license": attr.string(default = ""),
- "python_requires": attr.string(default = ""),
+ "author": attr.string(
+ doc = "A string specifying the author of the package.",
+ default = "",
+ ),
+ "author_email": attr.string(
+ doc = "A string specifying the email address of the package author.",
+ default = "",
+ ),
+ "classifiers": attr.string_list(
+ doc = "A list of strings describing the categories for the package. For valid classifiers see https://pypi.org/classifiers",
+ ),
+ "description_file": attr.label(
+ doc = "A file containing text describing the package in a single line.",
+ allow_single_file = True,
+ ),
+ "homepage": attr.string(
+ doc = "A string specifying the URL for the package homepage.",
+ default = "",
+ ),
+ "license": attr.string(
+ doc = "A string specifying the license of the package.",
+ default = "",
+ ),
+ "python_requires": attr.string(
+ doc = (
+ "A string specifying what other distributions need to be installed " +
+ "when this one is. See the section on " +
+ "[Declaring required dependency](https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#declaring-dependencies) " +
+ "for details and examples of the format of this argument."
+ ),
+ default = "",
+ ),
"strip_path_prefixes": attr.string_list(
default = [],
doc = "path prefixes to strip from files added to the generated package",
@@ -282,8 +311,8 @@ Currently only pure-python wheels are supported.
Examples:
-
-# Package just a specific py_libraries, without their dependencies
+```python
+# Package some specific py_library targets, without their dependencies
py_wheel(
name = "minimal_with_py_library",
# Package data. We're building "example_minimal_library-0.0.1-py3-none-any.whl"
@@ -313,7 +342,7 @@ py_wheel(
version = "0.0.1",
deps = [":example_pkg"],
)
-
+```
""",
attrs = _concat_dicts(
{