From 9e2bdf7ecc587778b3268b9fbf792533a913a392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Eide?= Date: Fri, 13 Sep 2024 10:41:16 +0200 Subject: [PATCH] Temp --- .github/workflows/mac-run-tests-build-docs.yml | 12 ++++++------ docs/everest/source/conf.py | 16 +++++++--------- pyproject.toml | 3 ++- src/everest/detached/jobs/everserver.py | 10 ++-------- .../detached/jobs/{everserver => fm_everserver} | 2 +- src/everest/strings.py | 2 +- tests/everest/test_everserver.py | 15 ++++++++++----- 7 files changed, 29 insertions(+), 31 deletions(-) rename src/everest/detached/jobs/{everserver => fm_everserver} (75%) diff --git a/.github/workflows/mac-run-tests-build-docs.yml b/.github/workflows/mac-run-tests-build-docs.yml index a45171ac304..c2f0ac5c461 100644 --- a/.github/workflows/mac-run-tests-build-docs.yml +++ b/.github/workflows/mac-run-tests-build-docs.yml @@ -65,12 +65,12 @@ jobs: run: | python -m pytest tests/everest -n 4 -m "integration_test and not fails_on_macos_github_workflow" --dist loadgroup -# - name: Build Documentation -# if: matrix.test_type == 'doc' -# run: | -# pip install git+https://github.com/equinor/everest-models.git -# mkdir tmp -# sphinx-build -W -b html -d tmp/doctrees docs/source {envtmpdir}/html + - name: Build Documentation + if: matrix.test_type == 'doc' + run: | + pip install git+https://github.com/equinor/everest-models.git + mkdir tmp + sphinx-build -W -b html -d tmp/doctrees docs/everest/source {envtmpdir}/html - name: Run tests requiring everest-models if: matrix.test_type == 'everest-models-test' diff --git a/docs/everest/source/conf.py b/docs/everest/source/conf.py index e585cddd89b..703f0c4e6fc 100644 --- a/docs/everest/source/conf.py +++ b/docs/everest/source/conf.py @@ -12,7 +12,7 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # -import pkg_resources +from importlib import metadata # -- Project information ----------------------------------------------------- @@ -21,17 +21,15 @@ author = "Equinor & TNO" -def get_version(): - # Retrieve the everest installed version. - everest_version = pkg_resources.get_distribution(project).version - print("everest version: {}".format(everest_version)) - return everest_version - +try: + dist_version = metadata.version("everest") +except metadata.PackageNotFoundError: + dist_version = "0.0.0" # The short X.Y version -version = get_version() +version = ".".join(dist_version.split(".")[:2]) # The full version, including alpha/beta/rc tags -release = version +release = dist_version # -- General configuration --------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 5dcd156f44a..e36f4782fe9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -166,10 +166,11 @@ everest = [ ] [tool.setuptools] +package-dir = {"" = "src"} platforms = ["all"] [tool.setuptools.package-data] -everest = ["detached/jobs/everserver"] +everest = ["data/**/*", "*.tmpl", "detached/jobs/everserver"] ieverest = ["*.ui"] diff --git a/src/everest/detached/jobs/everserver.py b/src/everest/detached/jobs/everserver.py index 2c7583abeb3..8c5dd4c65ae 100755 --- a/src/everest/detached/jobs/everserver.py +++ b/src/everest/detached/jobs/everserver.py @@ -1,11 +1,9 @@ -#!/usr/bin/env python import argparse import json import logging import os import socket import ssl -import sys import threading import traceback from base64 import b64encode @@ -218,11 +216,11 @@ def _configure_loggers(config: EverestConfig): ) -def main(args): +def main(): arg_parser = argparse.ArgumentParser() arg_parser.add_argument("--config-file", type=str) arg_parser.add_argument("--debug", action="store_true") - options, _ = arg_parser.parse_known_args(args=args) + options = arg_parser.parse_args() config = EverestConfig.load_file(options.config_file) if options.debug: config.logging_level = "debug" @@ -411,7 +409,3 @@ def _generate_authentication(): n_bytes = 128 random_bytes = bytes(os.urandom(n_bytes)) return b64encode(random_bytes).decode("utf-8") - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/src/everest/detached/jobs/everserver b/src/everest/detached/jobs/fm_everserver similarity index 75% rename from src/everest/detached/jobs/everserver rename to src/everest/detached/jobs/fm_everserver index cdf6d88d4a5..aee9d30592f 100755 --- a/src/everest/detached/jobs/everserver +++ b/src/everest/detached/jobs/fm_everserver @@ -1,4 +1,4 @@ -EXECUTABLE everserver.py +EXECUTABLE everserver STDOUT ../../logs/everest_server.stdout STDERR ../../logs/everest_server.stderr diff --git a/src/everest/strings.py b/src/everest/strings.py index da5dc3d80e5..590dbea9eb5 100644 --- a/src/everest/strings.py +++ b/src/everest/strings.py @@ -5,7 +5,7 @@ DEFAULT_OUTPUT_DIR = "everest_output" DEFAULT_LOGGING_FORMAT = "%(asctime)s %(name)s %(levelname)s: %(message)s" -EVEREST_SERVER = "everserver" +EVEREST_SERVER = "fm_everserver" EVEREST = "everest" HOSTFILE_NAME = "hostfile" diff --git a/tests/everest/test_everserver.py b/tests/everest/test_everserver.py index 24ed0331b13..2103da56421 100644 --- a/tests/everest/test_everserver.py +++ b/tests/everest/test_everserver.py @@ -80,6 +80,7 @@ def test_hostfile_storage(): assert result == expected_result +@patch("sys.argv", ["name", "--config-file", "config_minimal.yml"]) @patch( "everest.detached.jobs.everserver.configure_logger", side_effect=configure_everserver_logger, @@ -88,13 +89,14 @@ def test_hostfile_storage(): def test_everserver_status_failure(mf_1): config_file = "config_minimal.yml" config = EverestConfig.load_file(config_file) - everserver.main(["--config-file", config_file]) + everserver.main() status = everserver_status(config) assert status["status"] == ServerStatus.failed assert "Exception: Configuring logger failed" in status["message"] +@patch("sys.argv", ["name", "--config-file", "config_minimal.yml"]) @patch("everest.detached.jobs.everserver.configure_logger") @patch("everest.detached.jobs.everserver._generate_authentication") @patch( @@ -123,13 +125,14 @@ def test_everserver_status_failure(mf_1): def test_everserver_status_running_complete(*args): config_file = "config_minimal.yml" config = EverestConfig.load_file(config_file) - everserver.main(["--config-file", config_file]) + everserver.main() status = everserver_status(config) assert status["status"] == ServerStatus.completed assert status["message"] == "Optimization completed." +@patch("sys.argv", ["name", "--config-file", "config_minimal.yml"]) @patch("everest.detached.jobs.everserver.configure_logger") @patch("everest.detached.jobs.everserver._generate_authentication") @patch( @@ -166,7 +169,7 @@ def test_everserver_status_running_complete(*args): def test_everserver_status_failed_job(*args): config_file = "config_minimal.yml" config = EverestConfig.load_file(config_file) - everserver.main(["--config-file", config_file]) + everserver.main() status = everserver_status(config) # The server should fail and store a user-friendly message. @@ -175,6 +178,7 @@ def test_everserver_status_failed_job(*args): assert "3 job failures caused by: job1, job2" in status["message"] +@patch("sys.argv", ["name", "--config-file", "config_minimal.yml"]) @patch("everest.detached.jobs.everserver.configure_logger") @patch("everest.detached.jobs.everserver._generate_authentication") @patch( @@ -199,7 +203,7 @@ def test_everserver_status_failed_job(*args): def test_everserver_status_exception(*args): config_file = "config_minimal.yml" config = EverestConfig.load_file(config_file) - everserver.main(["--config-file", config_file]) + everserver.main() status = everserver_status(config) # The server should fail, and store the exception that @@ -208,6 +212,7 @@ def test_everserver_status_exception(*args): assert "Exception: Failed optimization" in status["message"] +@patch("sys.argv", ["name", "--config-file", "config_one_batch.yml"]) @patch("everest.detached.jobs.everserver.configure_logger") @patch("everest.detached.jobs.everserver._generate_authentication") @patch( @@ -228,7 +233,7 @@ def test_everserver_status_exception(*args): def test_everserver_status_max_batch_num(*args): config_file = "config_one_batch.yml" config = EverestConfig.load_file(config_file) - everserver.main(["--config-file", config_file]) + everserver.main() status = everserver_status(config) # The server should complete without error.