Skip to content

Commit

Permalink
Merge pull request #41 from pepkit/dev
Browse files Browse the repository at this point in the history
Release v0.8.0
  • Loading branch information
donaldcampbelljr authored Apr 2, 2024
2 parents 11818a9 + 506bab4 commit cba25a3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion requirements/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
coveralls>=1.1
pytest-cov==2.6.1
veracitools
mock
11 changes: 10 additions & 1 deletion tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = "[email protected]"
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/test_query_yes_no.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ubiquerg/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.0"
__version__ = "0.8.0"
18 changes: 15 additions & 3 deletions ubiquerg/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import os
import re

from typing import List, Tuple, Any, Union

from .web import is_url

__author__ = "Vince Reuter"
__email__ = "[email protected]"

Expand Down Expand Up @@ -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
Expand All @@ -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))
2 changes: 1 addition & 1 deletion ubiquerg/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cba25a3

Please sign in to comment.