From 62c672eeae0e6809e86e080aafa70a39d242db1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Pokorn=C3=BD=20=28Rai=29?= Date: Mon, 20 Apr 2020 20:52:58 +0200 Subject: [PATCH] Work on PyPI - currently not working, see https://github.com/ankitects/anki/pull/535#issuecomment-616743033 --- WORKSPACE | 28 +++++++++++++++++++++------- src/deploy/BUILD | 6 +++++- src/deploy/list_models.py | 2 +- src/requirements.txt | 1 + 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 src/requirements.txt diff --git a/WORKSPACE b/WORKSPACE index c70979e..be3edc4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -28,20 +28,33 @@ load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories") sass_repositories() -# Python rules - -http_archive( +# NOTE: cannot use version 0.0.1 as it doesn't support Python 3 pip packages. +git_repository( name = "rules_python", - sha256 = "aa96a691d3a8177f3215b14b0edc9641787abaaa30363a080165d06ab65e1161", - url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.1/rules_python-0.0.1.tar.gz", + # NOT VALID: Replace with actual Git commit SHA. + commit = "a0fbf98d4e3a232144df4d0d80b577c7a693b570", + remote = "https://github.com/bazelbuild/rules_python.git", ) load("@rules_python//python:repositories.bzl", "py_repositories") py_repositories() + # Only needed if using the packaging rules. -# load("@rules_python//python:pip.bzl", "pip_repositories") -# pip_repositories() +#load("@rules_python//python:pip.bzl", "pip_import", "pip_repositories") +load("@rules_python//python:pip.bzl", "pip_import", "pip_repositories") + +pip_repositories() + +pip_import( + name = "my_deps", + python_interpreter = "python3", + requirements = "//src:requirements.txt", +) + +load("@my_deps//:requirements.bzl", "pip_install") + +pip_install() node_repositories(package_json = ["//:package.json"]) @@ -94,4 +107,5 @@ http_archive( load("@io_bazel_rules_closure//closure:repositories.bzl", "rules_closure_dependencies", "rules_closure_toolchains") rules_closure_dependencies() + rules_closure_toolchains() diff --git a/src/deploy/BUILD b/src/deploy/BUILD index 036b5f9..27bca11 100644 --- a/src/deploy/BUILD +++ b/src/deploy/BUILD @@ -1,4 +1,5 @@ load("@rules_python//python:defs.bzl", "py_binary") +load("@my_deps//:requirements.bzl", "requirement") py_binary( name = "build_slug", @@ -10,7 +11,10 @@ py_binary( name = "list_models", srcs = ["list_models.py"], data = ["//src/models:slug.json"], - deps = ["@rules_python//python/runfiles"], + deps = [ + "@rules_python//python/runfiles", + requirement("anki2"), + ], ) py_binary( diff --git a/src/deploy/list_models.py b/src/deploy/list_models.py index d9dc96e..0bf9b93 100644 --- a/src/deploy/list_models.py +++ b/src/deploy/list_models.py @@ -13,7 +13,7 @@ import json import sys -sys.path.append('/usr/share/anki') +# From anki2 package. import anki flags.DEFINE_string('collection_path', None, 'Path to .anki2 collection') diff --git a/src/requirements.txt b/src/requirements.txt new file mode 100644 index 0000000..034e154 --- /dev/null +++ b/src/requirements.txt @@ -0,0 +1 @@ +anki2