From 3c7e56f93455b04b120c5d12358d10ca41f8c604 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Wed, 2 Oct 2024 16:02:41 +0200 Subject: [PATCH] Test rules_python with local package Signed-off-by: Amaury Pouly --- WORKSPACE | 2 +- pyproject.toml | 6 ++++++ python-requirements.txt | 1 + rules/repo.bzl | 34 ++++++++++++---------------------- third_party/python/repos.bzl | 9 +++++---- util/hello/BUILD | 1 + util/hello/WORKSPACE | 1 + util/hello/hello.py | 10 ++++++++++ util/hello/pyproject.toml | 10 ++++++++++ 9 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 util/hello/BUILD create mode 100644 util/hello/WORKSPACE create mode 100644 util/hello/hello.py create mode 100644 util/hello/pyproject.toml diff --git a/WORKSPACE b/WORKSPACE index 14ec5fde8542c7..93bd879efcdb06 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -15,7 +15,7 @@ bazel_skylib_workspace() # Python Toolchain + PIP Dependencies load("//third_party/python:repos.bzl", "python_repos") -python_repos() +python_repos("/home/pamaury/project/rules_python") load("//third_party/python:deps.bzl", "python_deps") python_deps() load("//third_party/python:pip.bzl", "pip_deps") diff --git a/pyproject.toml b/pyproject.toml index 1fe63a0627f4a3..772cb990e0640d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,8 +84,14 @@ dependencies = [ # and bug fixes. We fix the version for improved stability and manually update # if necessary. "chipwhisperer@https://github.com/newaetech/chipwhisperer-minimal/archive/2643131b71e528791446ee1bab7359120288f4ab.zip", + + # Test + "hello @ file:///home/pamaury/project/opentitan/util/hello" ] [tool.setuptools] # This is actually not a python project, we just use pyproject.toml to manage dependencies. py-modules = [] + +[tool.uv.workspace] +members = ["util/hello/hello"] diff --git a/python-requirements.txt b/python-requirements.txt index 3f5431ba77088f..07be7d452725e6 100644 --- a/python-requirements.txt +++ b/python-requirements.txt @@ -199,6 +199,7 @@ gitdb==4.0.10 \ gitpython==3.1.32 \ --hash=sha256:8d9b8cb1e80b9735e8717c9362079d3ce4c6e5ddeebedd0361b228c3a67a62f6 \ --hash=sha256:e3d59b1c2c6ebb9dfa7a184daf3b6dd4914237e7488a1730a6d8f6f5d0b4187f +hello @ file:///home/pamaury/project/opentitan/util/hello hjson==3.1.0 \ --hash=sha256:55af475a27cf83a7969c808399d7bccdec8fb836a07ddbd574587593b9cdcf75 \ --hash=sha256:65713cdcf13214fb554eb8b4ef803419733f4f5e551047c9b711098ab7186b89 diff --git a/rules/repo.bzl b/rules/repo.bzl index 47f59dc139631b..4f795923b3dfbe 100644 --- a/rules/repo.bzl +++ b/rules/repo.bzl @@ -2,7 +2,6 @@ # Licensed under the Apache License, Version 2.0, see LICENSE for details. # SPDX-License-Identifier: Apache-2.0 -load("@python3//:defs.bzl", "interpreter") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_skylib//lib:paths.bzl", "paths") @@ -30,17 +29,18 @@ def http_archive_or_local(local = None, **kwargs): def _bare_repository_impl(rctx): if rctx.attr.local: workspace_root = str(rctx.path(rctx.attr.workspace).dirname.realpath) - result = rctx.execute( - [ - rctx.path(rctx.attr.python_interpreter), - rctx.attr._symlink_tree, - paths.join(workspace_root, rctx.attr.local), - ".", - ], - quiet = False, - ) - if result.return_code != 0: - fail("Error initializing repo for {}".format(rctx.attr.local)) + # FIXME use standard bazel symlink + # result = rctx.execute( + # [ + # rctx.path(rctx.attr.python_interpreter), + # rctx.attr._symlink_tree, + # paths.join(workspace_root, rctx.attr.local), + # ".", + # ], + # quiet = False, + # ) + # if result.return_code != 0: + # fail("Error initializing repo for {}".format(rctx.attr.local)) elif rctx.attr.url: rctx.download_and_extract( url = rctx.attr.url, @@ -68,16 +68,6 @@ bare_repository = repository_rule( "additional_files_content": attr.string_dict( doc = "Additional files to place in the repository (mapping repo filename to strings).", ), - "python_interpreter": attr.label( - default = interpreter, - allow_single_file = True, - doc = "Python interpreter to use.", - ), - "_symlink_tree": attr.label( - default = Label("//rules/scripts:symlink_tree.py"), - allow_files = True, - doc = "Script to create symlink trees for the `local` case.", - ), "workspace": attr.label( default = Label("//:WORKSPACE"), allow_single_file = True, diff --git a/third_party/python/repos.bzl b/third_party/python/repos.bzl index db02a5865538c9..683d14a399ffc4 100644 --- a/third_party/python/repos.bzl +++ b/third_party/python/repos.bzl @@ -2,12 +2,13 @@ # Licensed under the Apache License, Version 2.0, see LICENSE for details. # SPDX-License-Identifier: Apache-2.0 -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@//rules:repo.bzl", "http_archive_or_local") -def python_repos(): - http_archive( +def python_repos(local = None): + http_archive_or_local( name = "rules_python", + local = local, sha256 = "778aaeab3e6cfd56d681c89f5c10d7ad6bf8d2f1a72de9de55b23081b2d31618", strip_prefix = "rules_python-0.34.0", url = "https://github.com/bazelbuild/rules_python/releases/download/0.34.0/rules_python-0.34.0.tar.gz", - ) + ) \ No newline at end of file diff --git a/util/hello/BUILD b/util/hello/BUILD new file mode 100644 index 00000000000000..269c3d1fa48d8c --- /dev/null +++ b/util/hello/BUILD @@ -0,0 +1 @@ +# This file is here just to prevent bazel from looking into this repository. \ No newline at end of file diff --git a/util/hello/WORKSPACE b/util/hello/WORKSPACE new file mode 100644 index 00000000000000..269c3d1fa48d8c --- /dev/null +++ b/util/hello/WORKSPACE @@ -0,0 +1 @@ +# This file is here just to prevent bazel from looking into this repository. \ No newline at end of file diff --git a/util/hello/hello.py b/util/hello/hello.py new file mode 100644 index 00000000000000..4c590fe790e0fc --- /dev/null +++ b/util/hello/hello.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 + +def main(): + print("hello") + +def bye(): + print("bye") + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/util/hello/pyproject.toml b/util/hello/pyproject.toml new file mode 100644 index 00000000000000..1dbf27770d119f --- /dev/null +++ b/util/hello/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "hello" +version = "0.1.0" +description = "Add your description here" +requires-python = ">=3.8" +dependencies = [] + +[project.scripts] +hello = "hello:main" +bye = "hello:bye" \ No newline at end of file