python_library()

This is liable to change in the future.

A python_library() rule is used to group together Python sources and resources to be packaged into a top-level python_binary rule.

Arguments

  • name (required) #

    The name of the rule.

  • srcs (defaults to []) #

    The set of .py files included in this library.

  • platform_srcs (defaults to []) #

    Python-platform-specific source files. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched (as defined in the `python#name` section of `.buckconfig`), and the second element is a list of source files.

  • resources (defaults to []) #

    Static files to be packaged along with the python sources. These resources can be accessed at runtime using the pkg_resources API.

  • platform_resources (defaults to []) #

    Python-platform-specific resource files. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched (as defined in the `python#name` section of `.buckconfig`), and the second element is a list of resource files.

  • base_module (defaults to None) #

    The package for which the given specified sources and resources should reside in their final location in the top-level binary. If unset, the project relative directory that houses the BUCK file is used.

  • deps (defaults to []) #

    Other python_library() rules which lists srcs from which this rule imports modules.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule in its deps.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

  • labels (defaults to []) #

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query attrfilter.

Examples

# A rule that includes a single .py file.
python_library(
  name = 'fileutil',
  srcs = ['fileutil.py'],
  deps = [
    '//third_party/python-magic:python-magic',
  ],
)

# A rule that uses glob() to include all sources in the directory which the
# rule is defined.  It also lists a resource file that gets packaged with
# the sources in this rule.
python_library(
  name = 'testutil',
  srcs = glob(['testutil/**/*.py'],
  resources = [
    'testdata.dat',
  ],
)

Here is an example of using the `platform_srcs` and `platform_resources` parameters to pull in sources/resources only when building for a specific Python platform:

; .buckconfig
[python#py2]
  interpreter = /usr/bin/python2.7
[python#py3]
  interpreter = /usr/bin/python3.4
# BUCK
python_library(
  name = 'utils',
  platform_srcs = [
    ('py2', ['foo.py']),
    ('py3', ['bar.py']),
  ],
  platform_resources = [
    ('py2', ['foo.dat']),
    ('py3', ['bar.dat']),
  ],
)
::...
免责声明:
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
内容版权归原作者所有;
本人对内容的有效性/合法性不承担任何强制性责任.
若有不妥, 欢迎评注提醒:

或是邮件反馈可也:
askdama[AT]googlegroups.com


订阅 substack 体验古早写作:


点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:
zoomquiet


自怼圈/年度番新

DU22.4
关于 ~ DebugUself with DAMA ;-)
粤ICP备18025058号-1
公安备案号: 44049002000656 ...::