From aed3d639fb11f2d88110d873764a02f251a2c8d1 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Jul 2023 10:57:05 -0400 Subject: [PATCH 01/15] Enumerate the OCI_ENV_PATH automatically. [noissue] Signed-off-by: James Tanner --- client/oci_env/utils.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/client/oci_env/utils.py b/client/oci_env/utils.py index ce82bbf..1a41ff6 100644 --- a/client/oci_env/utils.py +++ b/client/oci_env/utils.py @@ -8,7 +8,40 @@ def get_oci_env_path(): - return os.environ.get("OCI_ENV_PATH", os.getcwd()) + """This returns the root directory of the oci-env checkout.""" + + if os.environ.get("OCI_ENV_PATH"): + return os.environ.get("OCI_ENV_PATH") + + # use cwd -if- it is an oci-env checkout + cwd = os.getcwd() + if os.path.basename(cwd) == "oci_env": + return cwd + + # let's try to find the pip path ... + try: + import oci_env + except ImportError: + # fallback to cwd if we can't import + return cwd + + # this is the $CHECKOUT/client/oci_env/__init__.py path ... + path = os.path.dirname(oci_env.__file__) + + # use git to find the root dir ... + pid = subprocess.run( + "git rev-parse --show-toplevel", + cwd=path, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + if pid.returncode != 0: + return cwd + + gitroot = pid.stdout.decode('utf-8').strip() + return gitroot + def exit_with_error(msg): print(msg) From 25209126a7a499786f51891b0b96484d526bf635 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Jul 2023 12:32:34 -0400 Subject: [PATCH 02/15] Docker compose install is broken in github. [noissue] Signed-off-by: James Tanner --- .github/workflows/ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 411e394..2a6ddb7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -62,9 +62,9 @@ jobs: sudo dpkg -i containernetworking-plugins_1.1.1+ds1-1_amd64.deb fi - - name: (Ubuntu) Install docker compose - if: matrix.TEST == 'docker' && matrix.os == 'ubuntu-latest' - uses: docker-practice/actions-setup-docker@1.0.11 + #- name: (Ubuntu) Install docker compose + # if: matrix.TEST == 'docker' && matrix.os == 'ubuntu-latest' + # uses: docker-practice/actions-setup-docker@1.0.11 - name: (Mac) Install docker compose if: matrix.TEST == 'docker' && matrix.os == 'macos-12' From 32b60a81be501e75eff28411a0c56c1cf7e2270d Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Jul 2023 12:41:11 -0400 Subject: [PATCH 03/15] Try CI without setting OCI_ENV_PATH ... [noissue] Signed-off-by: James Tanner --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2a6ddb7..74bd0f2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,7 +33,7 @@ jobs: - name: Set environment variables run: | echo "TEST=${{ matrix.TEST }}" >> $GITHUB_ENV - echo "OCI_ENV_PATH=${GITHUB_WORKSPACE}/oci_env/" >> $GITHUB_ENV + #echo "OCI_ENV_PATH=${GITHUB_WORKSPACE}/oci_env/" >> $GITHUB_ENV echo "COMPOSE_INTERACTIVE_NO_CLI=1" >> $GITHUB_ENV - name: clone pulpcore, pulp_file, pulp-openapi-generator From 8a6dbc92df6996b32c5db840011ec40e23ec6352 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Jul 2023 12:47:36 -0400 Subject: [PATCH 04/15] Debug prints. [noissue] Signed-off-by: James Tanner --- client/oci_env/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/oci_env/utils.py b/client/oci_env/utils.py index 1a41ff6..99148db 100644 --- a/client/oci_env/utils.py +++ b/client/oci_env/utils.py @@ -11,11 +11,13 @@ def get_oci_env_path(): """This returns the root directory of the oci-env checkout.""" if os.environ.get("OCI_ENV_PATH"): + print('USING OCI_ENV_PATH FROM ENVIRONMENT: {os.environ.get("OCI_ENV_PATH")}') return os.environ.get("OCI_ENV_PATH") # use cwd -if- it is an oci-env checkout cwd = os.getcwd() if os.path.basename(cwd) == "oci_env": + print(f'USING CWD ({cwd} FOR OCI_ENV_PATH') return cwd # let's try to find the pip path ... @@ -23,6 +25,7 @@ def get_oci_env_path(): import oci_env except ImportError: # fallback to cwd if we can't import + print(f'USING CWD ({cwd} FOR OCI_ENV_PATH BECAUSE OF OCI IMPORT FAILURE') return cwd # this is the $CHECKOUT/client/oci_env/__init__.py path ... @@ -37,9 +40,11 @@ def get_oci_env_path(): stderr=subprocess.PIPE ) if pid.returncode != 0: + print(f'USING CWD {cwd} FOR OCI_ENV_PATH BECAUSE OF GIT CMD FAILURE {pid.stdout}') return cwd gitroot = pid.stdout.decode('utf-8').strip() + print(f'USING {gitroot} FOR OCI_ENV_PATH BASED ON GIT CMD OUTPUT') return gitroot From 1aec2592202c3bbc0f3d1a955eb5e9028dbaf286 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Jul 2023 13:00:28 -0400 Subject: [PATCH 05/15] More debug. [noissue] Signed-off-by: James Tanner --- client/oci_env/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/oci_env/utils.py b/client/oci_env/utils.py index 99148db..b971fb7 100644 --- a/client/oci_env/utils.py +++ b/client/oci_env/utils.py @@ -10,6 +10,8 @@ def get_oci_env_path(): """This returns the root directory of the oci-env checkout.""" + print(f'FOUND GITHUB_WORKSPACE={os.environ.get("GITHUB_WORKSPACE")}') + if os.environ.get("OCI_ENV_PATH"): print('USING OCI_ENV_PATH FROM ENVIRONMENT: {os.environ.get("OCI_ENV_PATH")}') return os.environ.get("OCI_ENV_PATH") From 08a53b1d21101e0fcb395697d86d4916d702732a Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Jul 2023 13:12:54 -0400 Subject: [PATCH 06/15] More debug. [noissue] Signed-off-by: James Tanner --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 74bd0f2..560195f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,6 +30,9 @@ jobs: with: python-version: "3.8" + - name: DEBUG VAR + run: echo "${GITHUB_WORKSPACE}" + - name: Set environment variables run: | echo "TEST=${{ matrix.TEST }}" >> $GITHUB_ENV From 9ac4f81e73ced7b5d46f33c9f8cdc36995fab7ad Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Jul 2023 13:18:36 -0400 Subject: [PATCH 07/15] More debug ... [noissue] Signed-off-by: James Tanner --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 560195f..c23d98b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -36,8 +36,8 @@ jobs: - name: Set environment variables run: | echo "TEST=${{ matrix.TEST }}" >> $GITHUB_ENV - #echo "OCI_ENV_PATH=${GITHUB_WORKSPACE}/oci_env/" >> $GITHUB_ENV echo "COMPOSE_INTERACTIVE_NO_CLI=1" >> $GITHUB_ENV + #echo "OCI_ENV_PATH=${GITHUB_WORKSPACE}/oci_env/" >> $GITHUB_ENV - name: clone pulpcore, pulp_file, pulp-openapi-generator run: | From fad68f4022cf9152fff0aff7d27a4119ad14f21b Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Jul 2023 13:23:17 -0400 Subject: [PATCH 08/15] Traling slash? [noissue] Signed-off-by: James Tanner --- client/oci_env/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/oci_env/utils.py b/client/oci_env/utils.py index b971fb7..c284252 100644 --- a/client/oci_env/utils.py +++ b/client/oci_env/utils.py @@ -47,7 +47,7 @@ def get_oci_env_path(): gitroot = pid.stdout.decode('utf-8').strip() print(f'USING {gitroot} FOR OCI_ENV_PATH BASED ON GIT CMD OUTPUT') - return gitroot + return gitroot.rstrip('/') + '/' def exit_with_error(msg): From d5a8cd411d5ba9e14e5a2ae4a20abb2ae3be7253 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Jul 2023 13:33:42 -0400 Subject: [PATCH 09/15] Try this? [noissue] Signed-off-by: James Tanner --- client/oci_env/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/oci_env/utils.py b/client/oci_env/utils.py index c284252..b638448 100644 --- a/client/oci_env/utils.py +++ b/client/oci_env/utils.py @@ -18,16 +18,16 @@ def get_oci_env_path(): # use cwd -if- it is an oci-env checkout cwd = os.getcwd() - if os.path.basename(cwd) == "oci_env": - print(f'USING CWD ({cwd} FOR OCI_ENV_PATH') - return cwd + #if os.path.basename(cwd) == "oci_env": + # print(f'USING CWD ({cwd} FOR OCI_ENV_PATH') + # return cwd # let's try to find the pip path ... try: import oci_env except ImportError: # fallback to cwd if we can't import - print(f'USING CWD ({cwd} FOR OCI_ENV_PATH BECAUSE OF OCI IMPORT FAILURE') + print(f'USING CWD ({cwd}) FOR OCI_ENV_PATH BECAUSE OF OCI IMPORT FAILURE') return cwd # this is the $CHECKOUT/client/oci_env/__init__.py path ... From 85033e6b485b1af60e2bc37190edca3bfe7ceab2 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Jul 2023 14:53:01 -0400 Subject: [PATCH 10/15] Use logzero. [noissue] Signed-off-by: James Tanner --- client/oci_env/utils.py | 54 +++++++++++++++-------------------------- client/setup.py | 4 +-- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/client/oci_env/utils.py b/client/oci_env/utils.py index b638448..5ddf4cd 100644 --- a/client/oci_env/utils.py +++ b/client/oci_env/utils.py @@ -1,37 +1,21 @@ -from genericpath import isfile import os -import subprocess import pathlib +import subprocess import time +from genericpath import isfile from urllib import request +from logzero import logger def get_oci_env_path(): """This returns the root directory of the oci-env checkout.""" - - print(f'FOUND GITHUB_WORKSPACE={os.environ.get("GITHUB_WORKSPACE")}') - if os.environ.get("OCI_ENV_PATH"): - print('USING OCI_ENV_PATH FROM ENVIRONMENT: {os.environ.get("OCI_ENV_PATH")}') + logger.info('USING OCI_ENV_PATH FROM ENVIRONMENT: {os.environ.get("OCI_ENV_PATH")}') return os.environ.get("OCI_ENV_PATH") - # use cwd -if- it is an oci-env checkout - cwd = os.getcwd() - #if os.path.basename(cwd) == "oci_env": - # print(f'USING CWD ({cwd} FOR OCI_ENV_PATH') - # return cwd - - # let's try to find the pip path ... - try: - import oci_env - except ImportError: - # fallback to cwd if we can't import - print(f'USING CWD ({cwd}) FOR OCI_ENV_PATH BECAUSE OF OCI IMPORT FAILURE') - return cwd - - # this is the $CHECKOUT/client/oci_env/__init__.py path ... - path = os.path.dirname(oci_env.__file__) + # this is the $CHECKOUT/client/oci_env/utils.py path ... + path = os.path.dirname(__file__) # use git to find the root dir ... pid = subprocess.run( @@ -42,18 +26,20 @@ def get_oci_env_path(): stderr=subprocess.PIPE ) if pid.returncode != 0: - print(f'USING CWD {cwd} FOR OCI_ENV_PATH BECAUSE OF GIT CMD FAILURE {pid.stdout}') + cwd = os.getcwd() + logger.warning(f'USING CWD {cwd} FOR OCI_ENV_PATH BECAUSE OF GIT CMD FAILURE {pid.stdout}') return cwd gitroot = pid.stdout.decode('utf-8').strip() - print(f'USING {gitroot} FOR OCI_ENV_PATH BASED ON GIT CMD OUTPUT') + logger.info(f'USING {gitroot} FOR OCI_ENV_PATH BASED ON GIT CMD OUTPUT') return gitroot.rstrip('/') + '/' def exit_with_error(msg): - print(msg) + logger.error(msg) exit(1) + def read_env_file(path, exit_on_error=True): """ Read the contents of a .env file into a dictionary. @@ -115,7 +101,7 @@ def get_config(env_file): # A port dedicated for exposing generated docs "DOCS_PORT": "12345", "NGINX_DOCS_PORT": user_preferences.get("DOCS_PORT", "12345"), - + # nginx port to run in the container. This defaults to 5001 if nothing is set or # the value of API_HOST if that is set. "NGINX_PORT": user_preferences.get("API_PORT", "5001"), @@ -308,8 +294,8 @@ def get_env_file(path, env_file): for f in files: if os.path.isfile(f): return f - print(f"No compose.env or .compose.env file found in {path}.") - + logger.error(f"No compose.env or .compose.env file found in {path}.") + else: files = [ os.path.abspath(env_file), @@ -319,8 +305,8 @@ def get_env_file(path, env_file): for f in files: if os.path.isfile(f): return f - print(f"Could not find file {env_file}") - + logger.error(f"Could not find file {env_file}") + exit(1) @@ -358,7 +344,7 @@ def compose_command(self, cmd, interactive=False, pipe_output=False): cmd = binary + compose_files + cmd if self.is_verbose: - print(f"Running command in container: {' '.join(cmd)}") + logger.info(f"Running command in container: {' '.join(cmd)}") if interactive: return subprocess.call(cmd) @@ -379,7 +365,7 @@ def container_name(self, service=None): def _exit_no_container_found(): service_name = service if service[-1].isdigit() else f"{service}_1" name = f"{project_name}_{service_name}" - print( + logger.error( f"Could not find a running container named: {name} \n" f"instead of {service!r} did you mean 'pulp' or 'ui'?\n" "Run `oci-env compose ps` to see all running containers." @@ -436,7 +422,7 @@ def exec(self, args, service=None, interactive=False, pipe_output=False, privile cmd = cmd[:2] + ["--privileged"] + cmd[2:] if self.is_verbose: - print(f"Running command in container: {' '.join(cmd)}") + logger.info(f"Running command in container: {' '.join(cmd)}") if interactive: proc = subprocess.call(cmd) @@ -494,7 +480,7 @@ def poll(self, attempts, wait_time): ) try: if request.urlopen(status_api).code == 200: - print(f"[{container_name}] {status_api} online after {(i * wait_time)} seconds") + logger.info(f"[{container_name}] {status_api} online after {(i * wait_time)} seconds") return except: time.sleep(wait_time) diff --git a/client/setup.py b/client/setup.py index af05a46..1f74dd4 100644 --- a/client/setup.py +++ b/client/setup.py @@ -9,10 +9,10 @@ entry_points={ 'console_scripts': ['oci-env=oci_env.main:main'], }, - install_requires=[], + install_requires=['logzero'], packages=find_packages(exclude=["tests", "tests.*"]), long_description=long_description, long_description_content_type="text/markdown", url='https://github.com/newswangerd/oci-env', description='CLI for running OCI Env.' -) \ No newline at end of file +) From 908c6a50aca0442da9dc9f28588b18512e056c08 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Wed, 26 Jul 2023 12:01:15 -0400 Subject: [PATCH 11/15] Use stdlib logger. [noissue] Signed-off-by: James Tanner --- client/oci_env/logger.py | 46 ++++++++++++++++++++++++++++++++++++++++ client/oci_env/utils.py | 7 +++++- client/setup.py | 2 +- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 client/oci_env/logger.py diff --git a/client/oci_env/logger.py b/client/oci_env/logger.py new file mode 100644 index 0000000..b45ef05 --- /dev/null +++ b/client/oci_env/logger.py @@ -0,0 +1,46 @@ +# logger.py - reimplement some functionality of logzero + +import logging +import os + +# Define ANSI escape codes for different colors +ANSI_RESET = "\033[0m" +ANSI_RED = "\033[31m" +ANSI_GREEN = "\033[32m" +ANSI_YELLOW = "\033[33m" +ANSI_CYAN = "\033[36m" + + +# unique color per level +LOG_LEVEL_COLORS = { + 'DEBUG': ANSI_CYAN, + 'INFO': ANSI_GREEN, + 'WARNING': ANSI_YELLOW, + 'ERROR': ANSI_RED, + 'CRITICAL': ANSI_RED, +} + + +# need a custom class to have color per level +class LogColor(logging.LogRecord): + def __init__(self, *args, **kwargs): + super(LogColor, self).__init__(*args, **kwargs) + self.log_color = LOG_LEVEL_COLORS[self.levelname] + self.reset = ANSI_RESET + + +formatter = logging.Formatter('%(asctime)s - %(log_color)s%(levelname)s%(reset)s - %(filename)s:%(lineno)d - %(message)s') +logging.setLogRecordFactory(LogColor) +logger = logging.getLogger('oci_env') +logger.setLevel(logging.INFO) +console_handler = logging.StreamHandler() +console_handler.setFormatter(formatter) + + +if os.environ.get("OCI_ENV_DEBUG"): + logger.setLevel(logging.DEBUG) + console_handler.setLevel(logging.DEBUG) + + +# Add the console handler to the logger +logger.addHandler(console_handler) diff --git a/client/oci_env/utils.py b/client/oci_env/utils.py index 5ddf4cd..20da996 100644 --- a/client/oci_env/utils.py +++ b/client/oci_env/utils.py @@ -5,11 +5,16 @@ from genericpath import isfile from urllib import request -from logzero import logger + +#from logzero import logger +from oci_env.logger import logger def get_oci_env_path(): """This returns the root directory of the oci-env checkout.""" + + print(type(logger)) + if os.environ.get("OCI_ENV_PATH"): logger.info('USING OCI_ENV_PATH FROM ENVIRONMENT: {os.environ.get("OCI_ENV_PATH")}') return os.environ.get("OCI_ENV_PATH") diff --git a/client/setup.py b/client/setup.py index 1f74dd4..d78f03f 100644 --- a/client/setup.py +++ b/client/setup.py @@ -9,7 +9,7 @@ entry_points={ 'console_scripts': ['oci-env=oci_env.main:main'], }, - install_requires=['logzero'], + install_requires=[], packages=find_packages(exclude=["tests", "tests.*"]), long_description=long_description, long_description_content_type="text/markdown", From 95893d761154e3109e691fe51620f7004cd4cfeb Mon Sep 17 00:00:00 2001 From: James Tanner Date: Wed, 26 Jul 2023 12:35:39 -0400 Subject: [PATCH 12/15] Review changes. [noissue] Signed-off-by: James Tanner --- client/oci_env/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/oci_env/utils.py b/client/oci_env/utils.py index 20da996..5cdf86e 100644 --- a/client/oci_env/utils.py +++ b/client/oci_env/utils.py @@ -15,9 +15,9 @@ def get_oci_env_path(): print(type(logger)) - if os.environ.get("OCI_ENV_PATH"): - logger.info('USING OCI_ENV_PATH FROM ENVIRONMENT: {os.environ.get("OCI_ENV_PATH")}') - return os.environ.get("OCI_ENV_PATH") + if OCI_ENV_PATH := os.environ.get("OCI_ENV_PATH"): + logger.info('USING OCI_ENV_PATH FROM ENV: {OCI_ENV_PATH}') + return OCI_ENV_PATH # this is the $CHECKOUT/client/oci_env/utils.py path ... path = os.path.dirname(__file__) From 813932bc607fd4b84e0e043f4be361b637b5faae Mon Sep 17 00:00:00 2001 From: James Tanner Date: Wed, 26 Jul 2023 12:37:04 -0400 Subject: [PATCH 13/15] Remove unused workflow step. [noissue] Signed-off-by: James Tanner --- .github/workflows/ci.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c23d98b..c526fa0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -65,10 +65,6 @@ jobs: sudo dpkg -i containernetworking-plugins_1.1.1+ds1-1_amd64.deb fi - #- name: (Ubuntu) Install docker compose - # if: matrix.TEST == 'docker' && matrix.os == 'ubuntu-latest' - # uses: docker-practice/actions-setup-docker@1.0.11 - - name: (Mac) Install docker compose if: matrix.TEST == 'docker' && matrix.os == 'macos-12' uses: docker-practice/actions-setup-docker@1.0.11 From 2819e68936c3f4418c87d1763d1c7de7a6ffabaf Mon Sep 17 00:00:00 2001 From: James Tanner Date: Thu, 27 Jul 2023 15:31:07 -0400 Subject: [PATCH 14/15] Cleanup. [noissue] Signed-off-by: James Tanner --- .github/workflows/ci.yaml | 3 --- client/oci_env/logger.py | 4 ++-- client/oci_env/utils.py | 3 --- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c526fa0..ad7029a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,9 +30,6 @@ jobs: with: python-version: "3.8" - - name: DEBUG VAR - run: echo "${GITHUB_WORKSPACE}" - - name: Set environment variables run: | echo "TEST=${{ matrix.TEST }}" >> $GITHUB_ENV diff --git a/client/oci_env/logger.py b/client/oci_env/logger.py index b45ef05..3e68954 100644 --- a/client/oci_env/logger.py +++ b/client/oci_env/logger.py @@ -38,8 +38,8 @@ def __init__(self, *args, **kwargs): if os.environ.get("OCI_ENV_DEBUG"): - logger.setLevel(logging.DEBUG) - console_handler.setLevel(logging.DEBUG) + logger.setLevel(logging.DEBUG) + console_handler.setLevel(logging.DEBUG) # Add the console handler to the logger diff --git a/client/oci_env/utils.py b/client/oci_env/utils.py index 5cdf86e..5159e14 100644 --- a/client/oci_env/utils.py +++ b/client/oci_env/utils.py @@ -6,15 +6,12 @@ from genericpath import isfile from urllib import request -#from logzero import logger from oci_env.logger import logger def get_oci_env_path(): """This returns the root directory of the oci-env checkout.""" - print(type(logger)) - if OCI_ENV_PATH := os.environ.get("OCI_ENV_PATH"): logger.info('USING OCI_ENV_PATH FROM ENV: {OCI_ENV_PATH}') return OCI_ENV_PATH From 89adaa9d90783caf3908a497512c7d6c9170fd84 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Fri, 28 Jul 2023 09:19:40 -0400 Subject: [PATCH 15/15] No trailing slashes. [noissue] Signed-off-by: James Tanner --- client/oci_env/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/oci_env/utils.py b/client/oci_env/utils.py index 5159e14..60c469f 100644 --- a/client/oci_env/utils.py +++ b/client/oci_env/utils.py @@ -13,6 +13,7 @@ def get_oci_env_path(): """This returns the root directory of the oci-env checkout.""" if OCI_ENV_PATH := os.environ.get("OCI_ENV_PATH"): + OCI_ENV_PATH = OCI_ENV_PATH.rstrip('/') logger.info('USING OCI_ENV_PATH FROM ENV: {OCI_ENV_PATH}') return OCI_ENV_PATH @@ -28,13 +29,13 @@ def get_oci_env_path(): stderr=subprocess.PIPE ) if pid.returncode != 0: - cwd = os.getcwd() + cwd = os.getcwd().rstrip('/') logger.warning(f'USING CWD {cwd} FOR OCI_ENV_PATH BECAUSE OF GIT CMD FAILURE {pid.stdout}') return cwd - gitroot = pid.stdout.decode('utf-8').strip() + gitroot = pid.stdout.decode('utf-8').strip().rstrip('/') logger.info(f'USING {gitroot} FOR OCI_ENV_PATH BASED ON GIT CMD OUTPUT') - return gitroot.rstrip('/') + '/' + return gitroot def exit_with_error(msg):