Skip to content
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

python bazel #101

Merged
merged 3 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,27 @@ nixpkgs_git_repository(

nixpkgs_cc_configure(repository = "@nixpkgs//:default.nix")

nixpkgs_package(
name = "z3",
repositories = { "nixpkgs": "@nixpkgs//:default.nix" }
)

# Python
nixpkgs_python_configure(
python3_attribute_path = "python3",
repository = "@nixpkgs//:default.nix",
)

http_archive(
name = "rules_python",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
)

load("@rules_python//python:pip.bzl", "pip_install")

pip_install(requirements = "//src/ldfi:requirements.txt")

# Golang
http_archive(
name = "io_bazel_rules_go",
Expand Down
17 changes: 17 additions & 0 deletions src/ldfi/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@pip//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_test")

py_test(
name = "ldfi_test",
main = "tests/test_ldfi.py",
srcs = ["tests/test_ldfi.py"],
imports = [".."],
deps = [
requirement("z3-solver"),
"//src/ldfi/src:ldfi_lib",
],
data = ["@z3//:bin"],
env = {
"Z3_LIBRARY_PATH": "/nix/store/zdaninww6cyh3h9aj7w0kymz8c13b1q4-z3-4.8.9-lib/lib"
}
)
5 changes: 0 additions & 5 deletions src/ldfi/bin/detsys-ldfi

This file was deleted.

2 changes: 1 addition & 1 deletion src/ldfi/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pythonPackages.buildPythonApplication rec {
export SETUPTOOLS_SCM_PRETEND_VERSION="${lib.commitIdFromGitRepo ./../../.git}"
'';

checkInputs = with pythonPackages; [ pytest pytestrunner ];
checkInputs = with pythonPackages; [ z3 pytest pytestrunner ];
propagatedBuildInputs = with pythonPackages; [ z3-solver setuptools setuptools_scm ];

checkPhase = "pytest --capture=tee-sys";
Expand Down
2 changes: 2 additions & 0 deletions src/ldfi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
z3-solver>=4.8.9.0
setuptools
8 changes: 6 additions & 2 deletions src/ldfi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
author='Stevan Andjelkovic',
author_email='[email protected]',
license='BSD 2-clause',
packages=setuptools.find_packages(),
packages=setuptools.find_packages(where='src'),
python_requires='>=3.6',
install_requires=['z3-solver>=4.8.9.0'],
setup_requires=['pytest-runner'],
tests_require=['pytest'],
scripts=['bin/detsys-ldfi'],
entry_points={
'console_scripts': [
'detsys-ldfi=ldfi:main',
],
},
classifiers=[],
)
2 changes: 1 addition & 1 deletion src/ldfi/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ let
in

mkShell {
buildInputs = [ pythonEnv mypy black ];
buildInputs = [ pythonEnv z3 mypy black ];
}
22 changes: 22 additions & 0 deletions src/ldfi/src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@pip//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_library", "py_binary")

py_library(
name = "ldfi_lib",
srcs = ["ldfi.py"],
srcs_version = "PY3",
visibility = ["//src/ldfi:__subpackages__"],
deps = [
requirement("z3-solver"),
requirement("setuptools"),
],
)

py_binary(
name = "ldfi",
srcs = ["__init__.py"],
main = "__init__.py",
deps = [
":ldfi_lib"
],
)
4 changes: 4 additions & 0 deletions src/ldfi/src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import ldfi

def main():
ldfi.main()
3 changes: 0 additions & 3 deletions src/ldfi/ldfi/__init__.py → src/ldfi/src/ldfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,3 @@ def main():
storage.store(event)
logging.debug(event.faults)
print(event.faults)

if __name__ == '__main__':
main()
Empty file added src/ldfi/tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion src/ldfi/tests/test_ldfi.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
import ldfi
import tempfile
import logging
import os
import sqlite3
import z3
from z3 import (And, Or, Not, Bool)
import ldfi

def test_sorted_faults():
l = sorted([{"kind": "omission", "from": "frontend", "to": "register2", "at": 2},
Expand Down