From 5ac46784021735bf266696cb56c350692d68f31d Mon Sep 17 00:00:00 2001 From: Robert Timms <43040151+rtimms@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:53:37 +0000 Subject: [PATCH] add append_path (#5) --- iwutil/__init__.py | 13 ++++++++++++- tests/test_init.py | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/iwutil/__init__.py b/iwutil/__init__.py index 9f71c4b..a82484d 100644 --- a/iwutil/__init__.py +++ b/iwutil/__init__.py @@ -5,7 +5,7 @@ import pandas as pd from pathlib import Path import shutil - +import sys def subplots_autolayout( n, *args, n_rows=None, figsize=None, layout="constrained", **kwargs @@ -164,3 +164,14 @@ def this_dir(file): Get the directory of the file """ return Path(file).parent + +def append_path(path): + """ + Append a path to the current path + + Parameters + ---------- + path : str or Path + Path to append + """ + sys.path.append(str(path)) diff --git a/tests/test_init.py b/tests/test_init.py index 67ed7c7..ea9f56d 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -1,6 +1,7 @@ import iwutil import tempfile from pathlib import Path +import sys def test_check_and_combine_options(): @@ -117,3 +118,8 @@ def test_this_dir(): file_path = "" expected_dir = Path(".") assert iwutil.this_dir(file_path) == expected_dir + + +def test_append_path(): + iwutil.append_path(".") + assert "." in sys.path