From a948dbf544b663d3bed3b84636d8f4571ec08712 Mon Sep 17 00:00:00 2001 From: youngmokcho Date: Fri, 28 Jul 2023 16:10:48 -0400 Subject: [PATCH 1/3] bazelize python-magic --- BUILD | 0 WORKSPACE | 24 ++++++++++++++++++++++++ magic/BUILD | 19 +++++++++++++++++++ test/BUILD | 21 +++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 BUILD create mode 100644 WORKSPACE create mode 100644 magic/BUILD create mode 100644 test/BUILD diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..fd686ee --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,24 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "libmagic", + sha256 = "09c588dac9cff4baa054f51a36141793bcf64926edc909594111ceae60fce4ee", + strip_prefix = "file-5.31", + urls = [ + "https://astron.com/pub/file/file-5.31.tar.gz", + ], + patch_cmds = [ + "./configure", + "make", + "make install", + "cp src/.libs/libmagic.dylib /usr/local/lib/libmagic.dylib", + ], + build_file_content = """ +cc_library( + name = 'libmagic', + srcs = ["src/.libs/libmagic.dylib"], + includes = ['.'], + linkstatic = 1, + visibility = ['//visibility:public'], +)""", +) \ No newline at end of file diff --git a/magic/BUILD b/magic/BUILD new file mode 100644 index 0000000..5e956a7 --- /dev/null +++ b/magic/BUILD @@ -0,0 +1,19 @@ +py_library( + name = "loader", + srcs = ["loader.py", "__init__.py"], + imports = [".."], + data = [ + "@libmagic//:libmagic", + ], + visibility = ["//visibility:public"], +) + +py_library( + name = "compat", + srcs = ["compat.py"], + imports = [".."], + data = [ + ":loader", + ], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/test/BUILD b/test/BUILD new file mode 100644 index 0000000..fe19b5c --- /dev/null +++ b/test/BUILD @@ -0,0 +1,21 @@ +py_test( + name = "libmagic_test", + srcs = ["libmagic_test.py"], + deps = [ + "//magic:compat", + ], + data = [ + "testdata" + ] +) + +py_test( + name = "python_magic_test", + srcs = ["python_magic_test.py"], + deps = [ + "//magic:compat", + ], + data = [ + "testdata" + ] +) \ No newline at end of file From 9f1de6683f02e1d0fb81f5f7563b7f9eef885a9e Mon Sep 17 00:00:00 2001 From: youngmokcho Date: Fri, 28 Jul 2023 16:13:47 -0400 Subject: [PATCH 2/3] add prefix to build files --- BUILD => BUILD.bazel | 0 magic/{BUILD => BUILD.bazel} | 0 test/{BUILD => BUILD.bazel} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename BUILD => BUILD.bazel (100%) rename magic/{BUILD => BUILD.bazel} (100%) rename test/{BUILD => BUILD.bazel} (100%) diff --git a/BUILD b/BUILD.bazel similarity index 100% rename from BUILD rename to BUILD.bazel diff --git a/magic/BUILD b/magic/BUILD.bazel similarity index 100% rename from magic/BUILD rename to magic/BUILD.bazel diff --git a/test/BUILD b/test/BUILD.bazel similarity index 100% rename from test/BUILD rename to test/BUILD.bazel From 2796488bcc647cf64833786d62d079d9aef2030b Mon Sep 17 00:00:00 2001 From: youngcho22 <111297186+youngcho22@users.noreply.github.com> Date: Fri, 4 Aug 2023 17:37:13 -0400 Subject: [PATCH 3/3] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9eb70e8..41eb3c9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +# Descripton of the repository +This repository migrates python-magic and libmagic to Bazel in a single Bazel workspace, allowing any other Bazel workspace to consume python-magic as is without needing to install libmagic on the host machine. + # python-magic [![PyPI version](https://badge.fury.io/py/python-magic.svg)](https://badge.fury.io/py/python-magic) [![Build Status](https://travis-ci.org/ahupp/python-magic.svg?branch=master)](https://travis-ci.org/ahupp/python-magic) [![Join the chat at https://gitter.im/ahupp/python-magic](https://badges.gitter.im/ahupp/python-magic.svg)](https://gitter.im/ahupp/python-magic?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)