Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

PIP dependency support #1

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 14 commits into from
Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions 10 .ci/rules_python.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"variation": "",
"configurations": [
{"node": "linux-x86_64"},
{"node": "ubuntu_16.04-x86_64"},
{"node": "darwin-x86_64"}
]
}
]
39 changes: 39 additions & 0 deletions 39 .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Compiled Object files
Copy link

Choose a reason for hiding this comment

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

Why have all those parts? emacs exclude belongs to the ~/.gitignore, all the bin files should not be generated by bazel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just my standard .gitignore file I copy from repo to repo. I never touch it again.

Copy link

Choose a reason for hiding this comment

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

Repo .gitignore are supposed to be repo specific, so not includes things like *~...

Copy link

@duggelz duggelz Sep 8, 2017

Choose a reason for hiding this comment

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

I advice I got, didn't like, but eventually learned to appreciate the wisdom of, is to create a ~/.gitignore_global with all the editor autosave filenames, etc (things that are particular to me, not to the repo I'm working on), and do git config --global core.excludesfile ~/.gitignore_global

Otherwise, you're like "What part of this Python program creates Fortran executables?!"

*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# Emacs garbage
*~

# Bazel directories
bazel-*
bazel-bin
bazel-genfiles
bazel-out
bazel-testlogs
27 changes: 27 additions & 0 deletions 27 .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
sudo: required
Copy link

Choose a reason for hiding this comment

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

Add .ci/rules_python.json for CI. see https://github.com/bazelbuild/continuous-integration/blob/master/docs/owner.md#customizing-a-project

Seeing the build, you probably just want:

[
    {
          "variation": "",
           "configurations": [
                {"node": "linux-x86_64"},
                {"node": "ubuntu_16.04-x86_64"},
                {"node": "darwin-x86_64"}
           ]
    }
]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

dist: trusty
language:
- java
jdk:
- oraclejdk8 # Building Bazel requires JDK8.
addons:
apt:
sources:
- sourceline: 'deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8'
key_url: 'https://storage.googleapis.com/bazel-apt/doc/apt-key.pub.gpg'
packages:
- bazel

install:
- go get -u github.com/bazelbuild/buildifier/buildifier

script:
# Check that all of our tools and samples build
- bazel clean && bazel build //...
# Check that all of our tests pass
- bazel clean && bazel test //...

# Check for issues with the format of our bazel config files.
- buildifier -mode=check $(find . -name BUILD -type f)
- buildifier -mode=check $(find . -name WORKSPACE -type f)
- buildifier -mode=check $(find . -name '*.bzl' -type f)
66 changes: 54 additions & 12 deletions 66 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

## Rules

* [py_library](#py_library)
* [py_binary](#py_binary)
* [pip_import](docs/python/pip.md#pip_import)
* [py_library](docs/python/python.md#py_library)
* [py_binary](docs/python/python.md#py_binary)
* [py_test](docs/python/python.md#py_test)

## Overview

This is a placeholder repository that provides aliases for the native Bazel
python rules. In the future, this will also become the home for rules that
download `pip` packages, and other non-Core Python functionality.
This repository provides Python rules for Bazel. Currently, support for
rules that are available from Bazel core are simple aliases to that bundled
functionality. On top of that, this repository provides support for installing
dependencies typically managed via `pip`.

## Setup

Expand All @@ -23,14 +26,19 @@ git_repository(
remote = "https://github.com/bazelbuild/rules_python.git",
commit = "{HEAD}",
)

# Only needed for PIP support:
load("//python:pip.bzl", "pip_repositories")

pip_repositories()
```

Then in your `BUILD` files load the python rules with:

``` python
load(
"@io_bazel_rules_python//python:python.bzl",
"py_binary", "py_library"
"py_binary", "py_library", "py_test",
)

py_binary(
Expand All @@ -39,12 +47,46 @@ py_binary(
)
```

<a name="py_library"></a>
## py_library
## Importing `pip` dependencies

See Bazel core [documentation](https://docs.bazel.build/versions/master/be/python.html#py_library).
These rules are designed to have developers continue using `requirements.txt`
to express their dependencies in a Python idiomatic manner. These dependencies
are imported into the Bazel dependency graph via a two-phased process in
`WORKSPACE`:

```python
load("@io_bazel_rules_python//python:pip.bzl", "pip_import")

<a name="py_binary"></a>
## py_binary
# This rule translates the specified requirements.txt into
# @my_deps//:requirements.bzl, which itself exposes a pip_install method.
pip_import(
name = "my_deps",
requirements = "//path/to:requirements.txt",
)

# Load the pip_install symbol for my_deps, and create the dependencies'
# repositories.
load("@my_deps//:requirements.bzl", "pip_install")
pip_install()
```

See Bazel core [documentation](https://docs.bazel.build/versions/master/be/python.html#py_binary).
## Consuming `pip` dependencies

Once a set of dependencies has been imported via `pip_import` and `pip_install`
we can start consuming them in our `py_{binary,library,test}` rules. In support
of this, the generated `requirements.bzl` also contains a `package` method,
which can be used directly in `deps=[]` to reference an imported `py_library`.

```python
load("@my_deps//:requirements.bzl", "package")

py_library(
name = "mylib",
srcs = ["mylib.py"],
deps = [
":myotherlib",
# This takes the name as specified in requirements.txt
package("importeddep"),
]
)
```
109 changes: 109 additions & 0 deletions 109 WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
workspace(name = "io_bazel_rules_python")

# Skydoc stuff
git_repository(
name = "io_bazel_rules_sass",
remote = "https://github.com/bazelbuild/rules_sass.git",
tag = "0.0.2",
)

load("@io_bazel_rules_sass//sass:sass.bzl", "sass_repositories")

sass_repositories()

git_repository(
name = "io_bazel_skydoc",
remote = "https://github.com/bazelbuild/skydoc.git",
tag = "0.1.3",
)

load("@io_bazel_skydoc//skylark:skylark.bzl", "skydoc_repositories")

skydoc_repositories()

# Requirements for building our piptool.
load("//python:pip.bzl", "pip_import")

pip_import(
name = "piptool_deps",
requirements = "//python:requirements.txt",
)

load(
"@piptool_deps//:requirements.bzl",
_piptool_install = "pip_install",
)

_piptool_install()

git_repository(
name = "subpar",
remote = "https://github.com/google/subpar",
tag = "1.0.0",
)

# Test data for WHL tool testing.
http_file(
name = "grpc_whl",
sha256 = "c232d6d168cb582e5eba8e1c0da8d64b54b041dd5ea194895a2fe76050916561",
# From https://pypi.python.org/pypi/grpcio/1.6.0
url = ("https://pypi.python.org/packages/c6/28/" +
"67651b4eabe616b27472c5518f9b2aa3f63beab8f62100b26f05ac428639/" +
"grpcio-1.6.0-cp27-cp27m-manylinux1_i686.whl"),
)

http_file(
name = "futures_whl",
sha256 = "c4884a65654a7c45435063e14ae85280eb1f111d94e542396717ba9828c4337f",
# From https://pypi.python.org/pypi/futures
url = ("https://pypi.python.org/packages/a6/1c/" +
"72a18c8c7502ee1b38a604a5c5243aa8c2a64f4bba4e6631b1b8972235dd/" +
"futures-3.1.1-py2-none-any.whl"),
)

http_file(
name = "mock_whl",
sha256 = "5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1",
# From https://pypi.python.org/pypi/mock
url = ("https://pypi.python.org/packages/e6/35/" +
"f187bdf23be87092bd0f1200d43d23076cee4d0dec109f195173fd3ebc79/" +
"mock-2.0.0-py2.py3-none-any.whl"),
)

# Imports for examples
pip_import(
name = "examples_helloworld",
requirements = "//examples/helloworld:requirements.txt",
)

load(
"@examples_helloworld//:requirements.bzl",
_helloworld_install = "pip_install",
)

_helloworld_install()

pip_import(
name = "examples_version",
requirements = "//examples/version:requirements.txt",
)

load(
"@examples_version//:requirements.bzl",
_version_install = "pip_install",
)

_version_install()
60 changes: 60 additions & 0 deletions 60 docs/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # Apache 2.0

# To regenerate html docs, run:
# ./update_docs.sh

load("@io_bazel_skydoc//skylark:skylark.bzl", "skylark_doc", "skylark_library")

skylark_library(
name = "whl",
srcs = ["//python:whl.bzl"],
)

skylark_library(
name = "pip",
srcs = ["//python:pip.bzl"],
)

skylark_library(
name = "python",
srcs = ["//python:python.bzl"],
)

skylark_doc(
name = "docs-md",
format = "markdown",
overview = True,
site_root = ".",
deps = [
":pip",
":python",
":whl",
],
)

skylark_doc(
name = "docs-html",
format = "html",
overview = True,
site_root = ".",
deps = [
":pip",
":python",
":whl",
],
)
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.