From 0e466d3450bb29849424133986281ce6294cbc54 Mon Sep 17 00:00:00 2001 From: nsheff Date: Wed, 21 Feb 2024 20:10:02 -0500 Subject: [PATCH 1/6] cast maybe_urls to string --- ubiquerg/web.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubiquerg/web.py b/ubiquerg/web.py index e16037d..6eb80e3 100644 --- a/ubiquerg/web.py +++ b/ubiquerg/web.py @@ -23,4 +23,4 @@ def is_url(maybe_url): r"(?:/?|[/?]\S+)$", re.IGNORECASE, ) - return re.match(regex, maybe_url) is not None + return re.match(regex, str(maybe_url)) is not None From 89553386db69b764db50c8d2b4bcd4f36384ea06 Mon Sep 17 00:00:00 2001 From: nsheff Date: Wed, 21 Feb 2024 20:14:40 -0500 Subject: [PATCH 2/6] handle edge cases for mkabs --- ubiquerg/paths.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ubiquerg/paths.py b/ubiquerg/paths.py index 63ce656..6726b79 100644 --- a/ubiquerg/paths.py +++ b/ubiquerg/paths.py @@ -94,6 +94,12 @@ def mkabs(path, reldir=None): def xpand(path): return os.path.expandvars(os.path.expanduser(path)) + if path is None: + return path + + if is_url(path): + return path + if os.path.isabs(xpand(path)): return xpand(path) From f65569fdbbbccda31c5e2d7539b5a01d56e75fd8 Mon Sep 17 00:00:00 2001 From: nsheff Date: Wed, 21 Feb 2024 20:20:32 -0500 Subject: [PATCH 3/6] mkabs tests --- tests/test_paths.py | 11 ++++++++++- ubiquerg/paths.py | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_paths.py b/tests/test_paths.py index 5139c34..1005750 100644 --- a/tests/test_paths.py +++ b/tests/test_paths.py @@ -2,7 +2,7 @@ import os import pytest -from ubiquerg import expandpath, parse_registry_path +from ubiquerg import expandpath, parse_registry_path, mkabs __author__ = "Vince Reuter" __email__ = "vreuter@virginia.edu" @@ -106,3 +106,12 @@ def test_parse_reg(): def test_registry_path(registry_path, output): pvars = parse_registry_path(registry_path) assert pvars == output + + +def test_mkabs(): + relpath = "abc.txt" + abspath = mkabs(relpath) + print(f"Abspath: {abspath}") + assert abspath == os.path.join(os.getcwd(), relpath) + url = "http://example.com" + assert mkabs(url) == url diff --git a/ubiquerg/paths.py b/ubiquerg/paths.py index 6726b79..3ff12f2 100644 --- a/ubiquerg/paths.py +++ b/ubiquerg/paths.py @@ -2,8 +2,11 @@ import os import re + from typing import List, Tuple, Any, Union +from .web import is_url + __author__ = "Vince Reuter" __email__ = "vreuter@virginia.edu" From 50c99b93cf3f421a737a5607766ca616e97f1e0c Mon Sep 17 00:00:00 2001 From: nsheff Date: Wed, 21 Feb 2024 20:26:17 -0500 Subject: [PATCH 4/6] update mkabs function, version bump --- docs/changelog.md | 6 ++++++ ubiquerg/_version.py | 2 +- ubiquerg/paths.py | 9 ++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 0c022c7..f0d25f2 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,11 +2,17 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format. +## [0.8.0] - Unreleased +### Changed +- Expanded `mkabs` function to handle more cases +- Allow `is_url` to work on Path objects + ## [0.7.0] - 2024-01-02 ### Added - Experimental support for three-locking. + ## [0.6.3] - 2023-08-08 ### Fixed - Incorrect read of registry path. [Issue 35](https://github.com/pepkit/ubiquerg/issues/35) diff --git a/ubiquerg/_version.py b/ubiquerg/_version.py index 49e0fc1..777f190 100644 --- a/ubiquerg/_version.py +++ b/ubiquerg/_version.py @@ -1 +1 @@ -__version__ = "0.7.0" +__version__ = "0.8.0" diff --git a/ubiquerg/paths.py b/ubiquerg/paths.py index 3ff12f2..d195993 100644 --- a/ubiquerg/paths.py +++ b/ubiquerg/paths.py @@ -81,10 +81,10 @@ def parse_registry_path( return parsed_identifier -def mkabs(path, reldir=None): +def mkabs(path:str, reldir:str =None) -> str: """ Makes sure a path is absolute; if not already absolute, it's made absolute - relative to a given directory. Also expands ~ and environment variables for + relative to a given directory (or file). Also expands ~ and environment variables for kicks. :param str path: Path to make absolute @@ -109,4 +109,7 @@ def xpand(path): if not reldir: return os.path.abspath(xpand(path)) - return os.path.join(xpand(reldir), xpand(path)) + if os.path.isdir(reldir): + return os.path.join(xpand(reldir), xpand(path)) + else: + return os.path.join(xpand(os.path.dirname(reldir)), xpand(path)) From b999841133f6aa4d549c643c33a722a747c5b4b8 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Wed, 13 Mar 2024 09:38:11 +0800 Subject: [PATCH 5/6] Remove mock dependency --- requirements/requirements-test.txt | 1 - tests/test_query_yes_no.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements/requirements-test.txt b/requirements/requirements-test.txt index 922cca3..4637bac 100644 --- a/requirements/requirements-test.txt +++ b/requirements/requirements-test.txt @@ -1,4 +1,3 @@ coveralls>=1.1 pytest-cov==2.6.1 veracitools -mock diff --git a/tests/test_query_yes_no.py b/tests/test_query_yes_no.py index 3242035..97fb20e 100644 --- a/tests/test_query_yes_no.py +++ b/tests/test_query_yes_no.py @@ -1,7 +1,7 @@ """ Tests for binary user terminal interaction """ import itertools -import mock +import unittest.mock as mock import pytest from ubiquerg import query_yes_no From 506bab4a7538f553da03b22269813fadf4f7b012 Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:36:02 -0400 Subject: [PATCH 6/6] prepare changelog for v0.8.0 --- docs/changelog.md | 3 ++- ubiquerg/paths.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index f0d25f2..3d39305 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,10 +2,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format. -## [0.8.0] - Unreleased +## [0.8.0] - 2024-04-02 ### Changed - Expanded `mkabs` function to handle more cases - Allow `is_url` to work on Path objects +- Remove `mock` test requirement in favor of importing `unittest.mock as mock` ## [0.7.0] - 2024-01-02 diff --git a/ubiquerg/paths.py b/ubiquerg/paths.py index d195993..dc80763 100644 --- a/ubiquerg/paths.py +++ b/ubiquerg/paths.py @@ -81,7 +81,7 @@ def parse_registry_path( return parsed_identifier -def mkabs(path:str, reldir:str =None) -> str: +def mkabs(path: str, reldir: str = None) -> str: """ Makes sure a path is absolute; if not already absolute, it's made absolute relative to a given directory (or file). Also expands ~ and environment variables for