diff --git a/docs/changelog.md b/docs/changelog.md index 0c022c7..3d39305 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,11 +2,18 @@ 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] - 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 ### 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/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_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/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 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 63ce656..dc80763 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" @@ -78,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 @@ -94,10 +97,19 @@ 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) 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)) 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