diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..b96a58d --- /dev/null +++ b/.env.dist @@ -0,0 +1 @@ +ENV= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8848145..d24dbd2 100644 --- a/.gitignore +++ b/.gitignore @@ -251,4 +251,6 @@ dmypy.json # Pyre type checker .pyre/ -# End of https://www.gitignore.io/api/python,pycharm,jetbrains \ No newline at end of file +# End of https://www.gitignore.io/api/python,pycharm,jetbrains + +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..da28046 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM condaforge/mambaforge:24.3.0-0 as conda + +COPY bandit-agents-dev-env-linux-64.lock lib/bandit-agents-dev-env-linux-64.lock + +COPY build_env.sh /lib/build_env.sh + +RUN chmod +x /lib/build_env.sh + +ENV ENV="BUILD" + +RUN ./lib/build_env.sh + +FROM debian:stable-slim as unit-test-image + +COPY --from=conda /env /env + +ENV ENV="TEST" + +COPY BanditAgents /lib/BanditAgents +COPY Tests /lib/Tests +COPY tox.ini /lib/tox.ini + +WORKDIR /lib + +CMD ["/env/bin/python3", "-m", "tox", "--current-env"] + +FROM debian:stable-slim as publish-lib-image + +RUN apt-get -y update; apt-get -y install curl + +COPY --from=conda /env /env + +ARG ENV +ENV ENV=$ENV + +WORKDIR /lib + +ENTRYPOINT ["/app/launch_server.sh"] \ No newline at end of file diff --git a/Tests/BanditAgents/src/solvers/test_weight_solver.py b/Tests/BanditAgents/src/solvers/test_weight_solver.py index 8b1456c..6a6a0c2 100644 --- a/Tests/BanditAgents/src/solvers/test_weight_solver.py +++ b/Tests/BanditAgents/src/solvers/test_weight_solver.py @@ -1,4 +1,4 @@ -from typing import Generator, Iterable, List +from typing import Iterable, List import unittest from unittest.mock import patch @@ -38,7 +38,7 @@ def make_mock_base_solver(action_keys: Iterable[actionKey]) -> BaseSolver: return BaseSolverBuilder().with_action_keys(action_keys).build() -def mock__steps(x: ndarray[int], y: ndarray[float]) -> Generator[bool]: +def mock__steps(x: ndarray[int], y: ndarray[float]) -> Iterable[bool]: return (True for _ in x) diff --git a/bandit-agents-dev-env-linux-64.lock b/bandit-agents-dev-env-linux-64.lock index d21b60e..314be96 100644 --- a/bandit-agents-dev-env-linux-64.lock +++ b/bandit-agents-dev-env-linux-64.lock @@ -1,6 +1,6 @@ # Generated by conda-lock. # platform: linux-64 -# input_hash: 2e1d5b848aca3965630c49dd7f3377094a30ca3b18aaedee74ba7ed4147c1afd +# input_hash: 34b6a0f01ee56af448af8ff240e9dc28dc0f036c439c9129d764a9705b81498b @EXPLICIT https://repo.anaconda.com/pkgs/main/linux-64/_libgcc_mutex-0.1-main.conda#c3473ff8bdb3d124ed5ff11ec380d6f9 https://repo.anaconda.com/pkgs/main/linux-64/blas-1.0-mkl.conda#9a7a051e9bd41da46523acb017d8a517 @@ -31,6 +31,7 @@ https://repo.anaconda.com/pkgs/main/linux-64/sqlite-3.45.3-h5eee18b_0.conda#acf9 https://repo.anaconda.com/pkgs/main/linux-64/python-3.12.0-h996f2a0_0.conda#9bfdaa3ac3249dc0b8f9f22227f0ba07 https://repo.anaconda.com/pkgs/main/linux-64/cfgv-3.4.0-py312h06a4308_0.conda#765ea9eb7e1f5cd3791fcbae54fc6a8f https://repo.anaconda.com/pkgs/main/linux-64/click-8.1.7-py312h06a4308_0.conda#a0d97fc547780b4ddefc91139e633e02 +https://repo.anaconda.com/pkgs/main/linux-64/colorama-0.4.6-py312h06a4308_0.conda#6175699c700cc4e4bf18ffc86778e488 https://repo.anaconda.com/pkgs/main/linux-64/distlib-0.3.8-py312h06a4308_0.conda#3763a64961ca016ccf828044029cc5c0 https://repo.anaconda.com/pkgs/main/linux-64/filelock-3.13.1-py312h06a4308_0.conda#6a0b440821945eda176c2bd78fd64a56 https://repo.anaconda.com/pkgs/main/linux-64/mkl-service-2.4.0-py312h5eee18b_2.conda#4c74c6d49097f7bba2cd219e0c759048 @@ -38,22 +39,29 @@ https://repo.anaconda.com/pkgs/main/linux-64/mypy_extensions-1.0.0-py312h06a4308 https://repo.anaconda.com/pkgs/main/linux-64/packaging-24.2-py312h06a4308_0.conda#cece1340aae4560340b6f061cd3bae2f https://repo.anaconda.com/pkgs/main/linux-64/pathspec-0.10.3-py312h06a4308_0.conda#adca67c357ada01d137d476d8c2d7f41 https://repo.anaconda.com/pkgs/main/linux-64/platformdirs-3.10.0-py312h06a4308_0.conda#39dc9eb538e73250dadcdec7a8ed6595 +https://repo.anaconda.com/pkgs/main/linux-64/pluggy-1.5.0-py312h06a4308_0.conda#1287a7b660a041fbbb8931defb9111d6 +https://repo.anaconda.com/pkgs/main/noarch/py-1.11.0-pyhd3eb1b0_0.conda#7205a898ed2abbf6e9b903dff6abe08e https://repo.anaconda.com/pkgs/main/noarch/pycparser-2.21-pyhd3eb1b0_0.conda#135a72ff2a31150a3a3ff0b1edd41ca9 https://repo.anaconda.com/pkgs/main/noarch/python-tzdata-2023.3-pyhd3eb1b0_0.conda#479c037de0186d114b9911158427624e https://repo.anaconda.com/pkgs/main/linux-64/pytz-2024.1-py312h06a4308_0.conda#f8a72213ea02624e802216fedff222e1 https://repo.anaconda.com/pkgs/main/linux-64/pyyaml-6.0.2-py312h5eee18b_0.conda#757daf8bab7a35c165f3dc6c9355ea9b https://repo.anaconda.com/pkgs/main/linux-64/setuptools-72.1.0-py312h06a4308_0.conda#bab64ac5186aa07014788baf1fbe3ca9 https://repo.anaconda.com/pkgs/main/noarch/six-1.16.0-pyhd3eb1b0_1.conda#34586824d411d36af2fa40e799c172d0 +https://repo.anaconda.com/pkgs/main/linux-64/tomli-2.0.1-py312h06a4308_1.conda#8770c279821e6ba382d5fa7562a8391b https://repo.anaconda.com/pkgs/main/linux-64/wheel-0.44.0-py312h06a4308_0.conda#6d495438dd44e8f16b1a05d0a8648644 +https://repo.anaconda.com/pkgs/main/linux-64/zipp-3.21.0-py312h06a4308_0.conda#b3ad8cca3dcd963260b5f84401cfc6ae https://repo.anaconda.com/pkgs/main/linux-64/black-24.8.0-py312h06a4308_0.conda#45db94c5c4cc7ec895f3620198365987 https://repo.anaconda.com/pkgs/main/linux-64/cffi-1.17.1-py312h1fdaa30_1.conda#e3c5735b1a5c0ec929f62407410890bb +https://repo.anaconda.com/pkgs/main/linux-64/importlib-metadata-8.5.0-py312h06a4308_0.conda#c7395d8d9fc78756d72104f0e9d468f5 https://repo.anaconda.com/pkgs/main/linux-64/nodeenv-1.7.0-py312h06a4308_0.conda#23c0441e6b4e88642027f364e62f8566 https://repo.anaconda.com/pkgs/main/linux-64/numpy-base-2.2.1-py312h0da6c21_0.conda#6ec469e931f2d1f7f08494b1d5668cc5 https://repo.anaconda.com/pkgs/main/linux-64/pip-24.2-py312h06a4308_0.conda#798cbea8112672434d0cd7551f8fc4b9 https://repo.anaconda.com/pkgs/main/linux-64/python-dateutil-2.9.0post0-py312h06a4308_2.conda#06c8706a892aaaae74325c0b46c86d01 https://repo.anaconda.com/pkgs/main/linux-64/virtualenv-20.28.0-py312h06a4308_0.conda#f3843ea4e7a86a4fc2429cb0a25277a2 +https://conda.anaconda.org/conda-forge/noarch/tox-3.27.1-pyhd8ed1ab_0.tar.bz2#62b743e1030b17163c70654601afb60d https://repo.anaconda.com/pkgs/main/linux-64/ukkonen-1.0.1-py312hdb19cb5_1.conda#bbeaa2aff1b32149b4380d5cd80b4b25 https://repo.anaconda.com/pkgs/main/linux-64/identify-2.5.5-py312h06a4308_0.conda#f41d506d423ed77f2fd4ae67020ae659 +https://conda.anaconda.org/conda-forge/noarch/tox-current-env-0.0.11-pyhd8ed1ab_0.conda#ca5420198ae4fe23bc4fe924be99635c https://repo.anaconda.com/pkgs/main/linux-64/pre-commit-3.4.0-py312h06a4308_1.conda#8570303eeae34305d21b118782de1834 https://repo.anaconda.com/pkgs/main/linux-64/bottleneck-1.4.2-py312ha883a20_0.conda#ff0a95c8810f5c091da3d93e565c7763 https://repo.anaconda.com/pkgs/main/linux-64/mkl_fft-1.3.11-py312h5eee18b_0.conda#8e39abc21446208f8efa84140549e137 diff --git a/bandit_agents_dev_env.yml b/bandit_agents_dev_env.yml index 771f277..f5c1273 100644 --- a/bandit_agents_dev_env.yml +++ b/bandit_agents_dev_env.yml @@ -9,6 +9,8 @@ dependencies: - scipy - pandas - black + - tox + - tox-current-env platforms: - linux-64 \ No newline at end of file diff --git a/build_env.sh b/build_env.sh index 51a7c65..ccd5d26 100755 --- a/build_env.sh +++ b/build_env.sh @@ -1,10 +1,46 @@ #!/bin/sh +x -if [ -e $CONDA_PREFIX_1/envs/bandit_agents_dev_env ]; then + +if [ $ENV = "BUILD" ]; then + mamba create \ + --copy -p ./env \ + --file /lib/bandit-agents-dev-env-linux-64.lock \ + && conda clean -afy + + find -name '*.a' -delete && + rm -rf /env/conda-meta && + rm -rf /env/include && + rm /env/lib/libpython3.12.so.1.0 && + find -name '__pycache__' -type d -exec rm -rf '{}' '+' && + rm -rf /env/lib/python3.12/site-packages/pip /env/lib/python3.12/idlelib /env/lib/python3.12/ensurepip \ + /env/lib/libasan.so.5.0.0 \ + /env/lib/libtsan.so.0.0.0 \ + /env/lib/liblsan.so.0.0.0 \ + /env/lib/libubsan.so.1.0.0 \ + /env/bin/x86_64-conda-linux-gnu-ld \ + /env/bin/sqlite3 \ + /env/bin/openssl \ + /env/share/terminfo && + find /env/lib/python3.12/site-packages/scipy -name 'tests' -type d -exec rm -rf '{}' '+' && + find /env/lib/python3.12/site-packages/numpy -name 'tests' -type d -exec rm -rf '{}' '+' && + find /env/lib/python3.12/site-packages/pandas -name 'tests' -type d -exec rm -rf '{}' '+' && + find /env/lib/python3.12/site-packages -name '*.pyx' -delete && + rm -rf /env/lib/python3.12/site-packages/uvloop/loop.c + +else + if [ -e $CONDA_PREFIX_1/envs/bandit_agents_dev_env ]; then echo erase bandit_agents_dev_env rm -r $CONDA_PREFIX_1/envs/bandit_agents_dev_env -fi + fi -echo creating environment -conda create \ + echo creating environment + conda create \ --name bandit_agents_dev_env \ --file bandit-agents-dev-env-linux-64.lock -y + + echo adding dev dependencies + conda update \ + --name bandit_agents_dev_env \ + --freeze-installed \ + --no-update-deps \ + --file bandit-agents-dev-env-linux-64.lock +fi diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..094c65e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +services: + mb-assistant-v2: + build: + context: . + dockerfile: Dockerfile + target: publish-lib-image + args: + ENV: $ENV + + unit-tests: + build: + context: . + dockerfile: Dockerfile + target: unit-test-image \ No newline at end of file diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..3d12cf2 --- /dev/null +++ b/tox.ini @@ -0,0 +1,19 @@ +[flake8] +max-line-length = 300 +inline-quotes = single +literal-inline-quotes = single +exclude = + .git, + __pycache__, + old, + build, + dist, + env, + env_files, + deployment + +extend-ignore = E203, E704, F541 + + +[testenv] +commands = /env/bin/python3 -m unittest \ No newline at end of file