Skip to content

Commit bd1307b

Browse files
Merge pull request #27 from pepkit/dev
Release 0.2.1
2 parents 2fdf976 + 7a89e24 commit bd1307b

9 files changed

+84
-7
lines changed

.github/workflows/black.yml .github/workflows/black_linter.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ on:
44
pull_request:
55
branches: [main]
66

7-
87
jobs:
98
lint:
109
runs-on: ubuntu-latest
1110
steps:
1211
- uses: actions/checkout@v2
1312
- uses: actions/setup-python@v2
14-
- uses: psf/black@stable
13+
- uses: psf/black@stable

.pre-commit-config.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
# Run the Ruff linter.
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
# Ruff version.
5+
rev: v0.1.3
6+
hooks:
7+
# Run the Ruff linter.
8+
- id: ruff
9+
# Run the Ruff formatter.
10+
- id: ruff-format

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
lint:
2-
# black should be last in the list, as it lint the code. Tests can fail if order will be different
3-
flake8 && isort . && black .
2+
ruff format .
43

54
run-coverage:
65
coverage run -m pytest

docs/changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
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.
44

5+
## [0.2.1] - 2023-11-01
6+
### Added
7+
- is_registry_path checker function
8+
59
## [0.2.0] - 2023-10-02
610
### Added
711
- Project search functionality

pephubclient/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pephubclient.pephubclient import PEPHubClient
22

33
__app_name__ = "pephubclient"
4-
__version__ = "0.2.0"
4+
__version__ = "0.2.1"
55
__author__ = "Oleksandr Khoroshevskyi, Rafal Stepien"
66

77

pephubclient/helpers.py

+19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
import requests
55
from requests.exceptions import ConnectionError
66

7+
from ubiquerg import parse_registry_path
8+
from pydantic.error_wrappers import ValidationError
9+
710
from pephubclient.exceptions import PEPExistsError, ResponseError
11+
from pephubclient.constants import RegistryPath
812

913

1014
class RequestManager:
@@ -84,3 +88,18 @@ def call_client_func(func: Callable[..., Any], **kwargs) -> Any:
8488
MessageHandler.print_warning(f"PEP already exists. {err}")
8589
except OSError as err:
8690
MessageHandler.print_error(f"{err}")
91+
92+
93+
def is_registry_path(input_string: str) -> bool:
94+
"""
95+
Check if input is a registry path to pephub
96+
:param str input_string: path to the PEP (or registry path)
97+
:return bool: True if input is a registry path
98+
"""
99+
if input_string.endswith(".yaml"):
100+
return False
101+
try:
102+
RegistryPath(**parse_registry_path(input_string))
103+
except (ValidationError, TypeError):
104+
return False
105+
return True

requirements/requirements-all.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ peppy>=0.35.7
33
requests>=2.28.2
44
pydantic<2.0
55
pandas>=2.0.0
6+
ubiquerg>=0.6.3

requirements/requirements-test.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
black
2+
ruff
23
pytest
34
python-dotenv
45
pytest-mock
56
flake8
67
coveralls
7-
pytest-cov
8+
pytest-cov
9+
pre-commit

tests/test_pephubclient.py

+44-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pephubclient.exceptions import ResponseError
77
from pephubclient.pephubclient import PEPHubClient
8+
from pephubclient.helpers import is_registry_path
89

910
SAMPLE_PEP = os.path.join(
1011
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
@@ -150,11 +151,53 @@ def test_push_with_pephub_error_response(
150151

151152
def test_search_prj(self, mocker):
152153
return_value = b'{"count":1,"limit":100,"offset":0,"items":[{"namespace":"namespace1","name":"basic","tag":"default","is_private":false,"number_of_samples":2,"description":"None","last_update_date":"2023-08-27 19:07:31.552861+00:00","submission_date":"2023-08-27 19:07:31.552858+00:00","digest":"08cbcdbf4974fc84bee824c562b324b5","pep_schema":"random_schema_name"}],"session_info":null,"can_edit":false}'
153-
requests_mock = mocker.patch(
154+
mocker.patch(
154155
"requests.request",
155156
return_value=Mock(content=return_value, status_code=200),
156157
)
157158

158159
return_value = PEPHubClient().find_project(namespace="namespace1")
159160
assert return_value.count == 1
160161
assert len(return_value.items) == 1
162+
163+
164+
class TestHelpers:
165+
@pytest.mark.parametrize(
166+
"input_str, expected_output",
167+
[
168+
(
169+
"databio/pep:default",
170+
True,
171+
),
172+
(
173+
"pephub.databio.org::databio/pep:default",
174+
True,
175+
),
176+
(
177+
"pephub.databio.org://databio/pep:default",
178+
True,
179+
),
180+
(
181+
"databio/pep",
182+
True,
183+
),
184+
(
185+
"databio/pep/default",
186+
False,
187+
),
188+
(
189+
"some/random/path/to.yaml",
190+
False,
191+
),
192+
(
193+
"path_to.csv",
194+
False,
195+
),
196+
(
197+
"this/is/path/to.csv",
198+
False,
199+
),
200+
],
201+
)
202+
def test_is_registry_path(self, input_str, expected_output):
203+
assert is_registry_path(input_str) is expected_output

0 commit comments

Comments
 (0)