Skip to content

Commit b7185dd

Browse files
Merge pull request #21 from pepkit/dev
Release v0.1.1
2 parents 75f2303 + 59249fb commit b7185dd

14 files changed

+91
-32
lines changed

.github/workflows/pytest.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ jobs:
3232
run: python -m pip install .
3333

3434
- name: Run pytest tests
35-
run: pytest tests -v
35+
run: pytest tests -v

.github/workflows/run-codecov.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Run codecov
2+
3+
on:
4+
push:
5+
branches: [dev]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
pytest:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
python-version: [3.11]
15+
os: [ubuntu-latest]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install test dependencies
26+
run: if [ -f requirements/requirements-test.txt ]; then pip install -r requirements/requirements-test.txt; fi
27+
28+
- name: Install package
29+
run: python -m pip install .
30+
31+
- name: Run pytest tests
32+
run: pytest tests --cov=./ --cov-report=xml
33+
34+
- name: Upload coverage to Codecov
35+
uses: codecov/codecov-action@v3
36+
with:
37+
file: ./coverage.xml
38+
name: py-${{ matrix.python-version }}-${{ matrix.os }}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![PEP compatible](https://pepkit.github.io/img/PEP-compatible-green.svg)](https://pepkit.github.io)
44
![Run pytests](https://github.com/pepkit/pephubclient/workflows/Run%20pytests/badge.svg)
5+
[![codecov](https://codecov.io/gh/pepkit/pephubclient/branch/dev/graph/badge.svg)](https://codecov.io/gh/pepkit/pephubclient)
56
[![pypi-badge](https://img.shields.io/pypi/v/pephubclient)](https://pypi.org/project/pephubclient)
67
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
78

codecov.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ignore:
2+
- "*/cli.py"
3+
- "*/__main__.py"
4+
- "*/__init__.py"
5+
- "setup.py"

docs/changelog.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
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-
5+
## [0.1.1] - 2023-07-29
6+
### Fixed
7+
- New raw PEP structure was broken. ([#20](https://github.com/pepkit/pephubclient/issues/20))
68

79
## [0.1.0] - 2023-04-16
810
### Added

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.1.0"
4+
__version__ = "0.1.1"
55
__author__ = "Oleksandr Khoroshevskyi, Rafal Stepien"
66

77

pephubclient/constants.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import pydantic
55
from pydantic import BaseModel
66

7-
PEPHUB_BASE_URL = "https://pephub.databio.org/"
8-
# PEPHUB_BASE_URL = "http://0.0.0.0:8000/"
7+
# PEPHUB_BASE_URL = "https://pephub.databio.org/"
8+
PEPHUB_BASE_URL = "http://0.0.0.0:8000/"
99
PEPHUB_PEP_API_BASE_URL = f"{PEPHUB_BASE_URL}api/v1/projects/"
1010
PEPHUB_PUSH_URL = f"{PEPHUB_BASE_URL}api/v1/namespaces/{{namespace}}/projects/json"
1111

pephubclient/helpers.py

+2
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,5 @@ def call_client_func(func: Callable[..., Any], **kwargs) -> Any:
8282
MessageHandler.print_error(f"{err}")
8383
except PEPExistsError as err:
8484
MessageHandler.print_warning(f"PEP already exists. {err}")
85+
except OSError as err:
86+
MessageHandler.print_error(f"{err}")

pephubclient/models.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
import pydantic
44
from pydantic import BaseModel, Extra, Field
5+
from peppy.const import CONFIG_KEY, SUBSAMPLE_RAW_LIST_KEY, SAMPLE_RAW_DICT_KEY
56

67

78
class ProjectDict(BaseModel):
89
"""
910
Project dict (raw) model
1011
"""
1112

12-
description: Optional[str] = ""
13-
config: dict = Field(alias="_config")
14-
subsample_dict: Optional[list] = Field(alias="_subsample_dict")
15-
name: str
16-
sample_dict: dict = Field(alias="_sample_dict")
13+
config: dict = Field(alias=CONFIG_KEY)
14+
subsample_list: Optional[list] = Field(alias=SUBSAMPLE_RAW_LIST_KEY)
15+
sample_list: list = Field(alias=SAMPLE_RAW_DICT_KEY)
1716

1817
class Config:
1918
allow_population_by_field_name = True

pephubclient/pephubclient.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pandas as pd
66
import peppy
7+
from peppy.const import NAME_KEY, DESC_KEY, CONFIG_KEY
78
import requests
89
import urllib3
910
from pydantic.error_wrappers import ValidationError
@@ -145,7 +146,10 @@ def upload(
145146
project["name"] = name
146147

147148
upload_data = ProjectUploadData(
148-
pep_dict=project.to_dict(extended=True),
149+
pep_dict=project.to_dict(
150+
extended=True,
151+
orient="records",
152+
),
149153
tag=tag,
150154
is_private=is_private,
151155
overwrite=force,
@@ -167,6 +171,10 @@ def upload(
167171
)
168172
elif pephub_response.status_code == ResponseStatusCodes.UNAUTHORIZED:
169173
raise ResponseError("Unauthorized! Failure in uploading project.")
174+
elif pephub_response.status_code == ResponseStatusCodes.FORBIDDEN:
175+
raise ResponseError(
176+
"User does not have permission to write to this namespace!"
177+
)
170178
else:
171179
raise ResponseError("Unexpected Response Error.")
172180
return None
@@ -190,7 +198,7 @@ def _save_raw_pep(
190198
def full_path(fn: str) -> str:
191199
return os.path.join(folder_path, fn)
192200

193-
project_name = project_dict["name"]
201+
project_name = project_dict[CONFIG_KEY][NAME_KEY]
194202
sample_table_filename = "sample_table.csv"
195203
yaml_full_path = full_path(f"{project_name}_config.yaml")
196204
sample_full_path = full_path(sample_table_filename)
@@ -203,9 +211,9 @@ def full_path(fn: str) -> str:
203211
f"{len(extant)} file(s) exist(s): {', '.join(extant)}"
204212
)
205213

206-
config_dict = project_dict.get("_config")
207-
config_dict["name"] = project_name
208-
config_dict["description"] = project_dict["description"]
214+
config_dict = project_dict.get(CONFIG_KEY)
215+
config_dict[NAME_KEY] = project_name
216+
config_dict[DESC_KEY] = project_dict[CONFIG_KEY][DESC_KEY]
209217
config_dict["sample_table"] = sample_table_filename
210218

211219
sample_pandas = pd.DataFrame(project_dict.get("_sample_dict", {}))
@@ -251,6 +259,8 @@ def _load_raw_pep(
251259
:param jwt_data: JWT token.
252260
:return: Raw project in dict.
253261
"""
262+
if not jwt_data:
263+
jwt_data = FilesManager.load_jwt_data_from_file(self.PATH_TO_FILE_WITH_JWT)
254264
query_param = query_param or {}
255265
query_param["raw"] = "true"
256266

@@ -271,7 +281,9 @@ def _load_raw_pep(
271281
if pephub_response.status_code == ResponseStatusCodes.NOT_EXIST:
272282
raise ResponseError("File does not exist, or you are unauthorized.")
273283
if pephub_response.status_code == ResponseStatusCodes.INTERNAL_ERROR:
274-
raise ResponseError("Internal server error.")
284+
raise ResponseError(
285+
f"Internal server error. Unexpected return value. Error: {pephub_response.status_code}"
286+
)
275287

276288
def _set_registry_data(self, query_string: str) -> None:
277289
"""

requirements/requirements-all.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
typer>=0.7.0
2-
peppy>=0.35.4
2+
peppy>=0.35.7
33
requests>=2.28.2
4-
pydantic>=1.10.6
4+
pydantic<2.0
55
pandas>=2.0.0

requirements/requirements-test.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ black
22
pytest
33
python-dotenv
44
pytest-mock
5-
flake8
5+
flake8
6+
coveralls
7+
pytest-cov

tests/conftest.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@ def device_code_return():
1717
@pytest.fixture()
1818
def test_raw_pep_return():
1919
sample_prj = {
20-
"description": None,
21-
"config": {"This": "is config"},
22-
"subsample_dict": [],
23-
"name": "sample name",
24-
"sample_dict": {
25-
"organism": {"0": "pig", "1": "pig", "2": "frog", "3": "frog"},
26-
"sample_name": {
27-
"0": "pig_0h",
28-
"1": "pig_1h",
29-
"2": "frog_0h",
30-
"3": "frog_1h",
31-
},
20+
"config": {
21+
"This": "is config",
22+
"description": "desc",
23+
"name": "sample name",
3224
},
25+
"subsample_list": [],
26+
"sample_list": [
27+
{"time": "0", "file_path": "source1", "sample_name": "pig_0h"},
28+
{"time": "1", "file_path": "source1", "sample_name": "pig_1h"},
29+
{"time": "0", "file_path": "source1", "sample_name": "frog_0h"},
30+
],
3331
}
3432
return json.dumps(sample_prj)
3533

tests/test_pephubclient.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_pull(self, mocker, test_jwt, test_raw_pep_return):
8787
),
8888
(
8989
500,
90-
"Internal server error.",
90+
"Internal server error. Unexpected return value. Error: 500",
9191
),
9292
],
9393
)

0 commit comments

Comments
 (0)