Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General refactoring of bfabricPy #95

Merged
merged 157 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
2ea11ef
added suds and pandas conversion libraries
Apr 4, 2024
48d47fb
minor
Apr 4, 2024
78a1bc3
updated to main
Apr 4, 2024
e5ee420
made example usage for read
Apr 8, 2024
a5b22b0
paginator impl as lib+example
Apr 8, 2024
bee0b53
skeleton BFabricPy_V2.0000001, engines for suds and zeep, resultsCont…
Apr 8, 2024
b9ecfdf
Merge branch 'dev-bfabric-2' into feat_response_formats
Apr 8, 2024
778e37b
applied SUDS->Dict to ResultContainer
Apr 8, 2024
b3968c8
Update bfabric/src/pandas_helper.py
aleksejs-fomins Apr 9, 2024
f5b05de
Update bfabric/src/pandas_helper.py
aleksejs-fomins Apr 9, 2024
7fd17f3
Update bfabric/src/pandas_helper.py
aleksejs-fomins Apr 9, 2024
0af5a95
Update bfabric/examples/suds_to_listdict.py
aleksejs-fomins Apr 9, 2024
967b44e
Update bfabric/examples/suds_to_listdict.py
aleksejs-fomins Apr 9, 2024
823b1c2
Update bfabric/src/suds_format.py
aleksejs-fomins Apr 9, 2024
2677402
Update bfabric/src/result_container.py
aleksejs-fomins Apr 9, 2024
fd6a210
Merge pull request #66 from fgcz/feat_response_formats
aleksejs-fomins Apr 9, 2024
5f52f4b
converted some names to to PEP8
Apr 9, 2024
5998523
Merge branch 'feat_response_formats' into dev-bfabric-2
Apr 9, 2024
0933542
minor
Apr 9, 2024
0e16526
Merge branch 'dev-bfabric-2' into feature-pagination
Apr 9, 2024
7b4656c
implementation of pagination and multi-query functionality for BFabric2
Apr 10, 2024
640f31b
Merge branch 'main' into dev-bfabric-2
Apr 10, 2024
5d7002f
Merge branch 'main' into feature-pagination
Apr 10, 2024
8b7d61e
using auth class, minor bug in engines, added __repr__ etc to Resourc…
Apr 11, 2024
cd743e0
Merge branch 'main' into dev-bfabric-2
Apr 11, 2024
05c24a4
Merge branch 'main' into feature-pagination
Apr 11, 2024
f3fec55
minor naming, progress on testing of consistency between Zeep and SUDS
Apr 12, 2024
d6c8ccc
rewrote test script in a more readable way
Apr 16, 2024
6d38069
reformulated comparison examples closer to test-like, added comments,…
Apr 17, 2024
ece5b9b
minor naming improvement
Apr 17, 2024
de7992b
added bfabric.exists() to check if objects with requested ids exist. …
Apr 17, 2024
250aaf0
extended exists interface to arbitrary key. Makes sense to also query…
Apr 17, 2024
491c30a
experimenting with exists-save-delete pipeline
Apr 17, 2024
9910300
unit and integration tests. Not full coverage, but hopefully will do …
Apr 19, 2024
8849dc0
Update bfabric/tests/unit/test_results_container.py
aleksejs-fomins Apr 22, 2024
7fad60b
test naming, moved dict_helper into same file
Apr 22, 2024
eabd876
Merge branch 'feature-pagination' of github.com:fgcz/bfabricPy into f…
Apr 22, 2024
6d0e283
Update bfabric/bfabric2.py
aleksejs-fomins Apr 22, 2024
f4d2840
removed save_multi
Apr 22, 2024
65c839f
Merge branch 'feature-pagination' of github.com:fgcz/bfabricPy into f…
Apr 22, 2024
64bb5f4
Update bfabric/tests/integration/test_bfabric2_read_pagination.py
aleksejs-fomins Apr 22, 2024
9be4615
naming and subtest for read test
Apr 22, 2024
f6d415f
Update bfabric/tests/integration/test_bfabric2_read_pagination.py
aleksejs-fomins Apr 22, 2024
b4eb030
Merge branch 'feature-pagination' of github.com:fgcz/bfabricPy into f…
Apr 22, 2024
e81c70d
Update bfabric/tests/integration/test_bfabric2_save_delete.py
aleksejs-fomins Apr 22, 2024
6a68919
Update bfabric/tests/unit/test_results_container.py
aleksejs-fomins Apr 22, 2024
8f6f5a5
minor naming
Apr 22, 2024
88452d3
minor naming
Apr 22, 2024
98337b6
hack to enable Zeep to read from samples
Apr 22, 2024
0e11c5f
added deepcopy to Zeep Hack for potential hierarchical queries
Apr 22, 2024
b32f2c1
migrated bfabricpy to .yml config files
Apr 23, 2024
90a5619
Merge pull request #70 from fgcz/feature-pagination
aleksejs-fomins Apr 23, 2024
d0d7779
docstring for bfabric class
Apr 23, 2024
e4e0642
Merge branch 'feat_ini_config' into dev-bfabric-2
Apr 23, 2024
c407a88
added authentication to the actual bfabric2 class, fixed a few minor …
Apr 23, 2024
f4506ff
renamed webbase to base_url everywhere
Apr 23, 2024
98b1bd6
Merge branch 'feat_ini_config' into dev-bfabric-2
Apr 23, 2024
1a4a10a
merged renaming from main
Apr 23, 2024
06bef1d
Update bfabric/bfabric_config.py
aleksejs-fomins Apr 23, 2024
d20cc47
Update bfabric/bfabric_config.py
aleksejs-fomins Apr 23, 2024
0edef12
Update bfabric/bfabric_config.py
aleksejs-fomins Apr 23, 2024
9292abd
Update bfabric/bfabric_config.py
aleksejs-fomins Apr 23, 2024
f8b55d9
Update bfabric/bfabric_config.py
aleksejs-fomins Apr 23, 2024
fd6d47c
renamed bfabric2 from webbase to base_url
Apr 23, 2024
78b1e09
Update bfabric/bfabric_config.py
aleksejs-fomins Apr 23, 2024
9fc88bd
Update bfabric/bfabric_config.py
aleksejs-fomins Apr 23, 2024
7c18828
Update bfabric/bfabric_config.py
aleksejs-fomins Apr 23, 2024
135c09f
Update bfabric/bfabric_config.py
aleksejs-fomins Apr 23, 2024
3b3bc14
Update bfabric/bfabric_config.py
aleksejs-fomins Apr 23, 2024
21d9cd0
revision changes
Apr 23, 2024
f9d5934
Merge branch 'feat_ini_config' of github.com:fgcz/bfabricPy into feat…
Apr 23, 2024
c12d289
warning for old config file
Apr 23, 2024
3ba6159
fixed a few bugs in _parse_dict
Apr 23, 2024
0ce7640
Merge branch 'feat_ini_config' into dev-bfabric-2
Apr 23, 2024
e3d6ab9
minor fix bad refactor
Apr 23, 2024
da7d46b
Merge branch 'dev-bfabric-2' into bugfix_bfabric2_login
aleksejs-fomins Apr 23, 2024
e4fbeb6
Merge pull request #72 from fgcz/bugfix_bfabric2_login
aleksejs-fomins Apr 23, 2024
1a7dd24
minor test if config file has .yml extension
Apr 23, 2024
1d6e7b6
throw exception if explicitly-provided path to the config file is wrong
Apr 24, 2024
c32cbc3
Handle default `None` parameters in BfabricConfig
leoschwarz Apr 24, 2024
7596a6d
Merge pull request #73 from fgcz/config-class-default-params
aleksejs-fomins Apr 25, 2024
33127e9
Detect error responses in ResultContainer
leoschwarz Apr 24, 2024
25e39c8
added integration tests for bad queries. added common handling of bad…
Apr 25, 2024
56e2482
Minor changes
leoschwarz Apr 25, 2024
1922635
added zeep as a requirement
Apr 26, 2024
501a4b7
fixed minor bug, added exists test
Apr 29, 2024
e0c2b68
minor
Apr 29, 2024
e2679d1
Python 3.9 compatibility
leoschwarz Apr 30, 2024
a56f53f
Merge branch 'main' into dev-bfabric-2
leoschwarz Apr 30, 2024
301bc54
fix some test failures
leoschwarz Apr 30, 2024
5457adb
Migrate to pyproject.toml (#76)
leoschwarz May 2, 2024
dca1cc0
Extract wrapper creator code (#78)
leoschwarz May 2, 2024
74c60a0
Update script bfabric_list_not_available_proteomics_workunits.py
leoschwarz May 3, 2024
008bd30
Merge pull request #80 from fgcz/leo-refactor-list-not-available-prot-wu
cpanse May 3, 2024
1b13f10
adapt 'make install' to toml
cpanse May 3, 2024
e0f7959
correct url, better version message
leoschwarz May 3, 2024
e90d736
Merge pull request #82 from fgcz/use-configured-url
cpanse May 3, 2024
04b9252
cosmetics Makefile
cpanse May 7, 2024
76daee1
Extend PR Checks (#83)
leoschwarz May 7, 2024
2afcd0c
Move auth logic to Bfabric class (#79)
leoschwarz May 7, 2024
8f5635b
add config field server_timezone (#84)
leoschwarz May 7, 2024
1472332
new pagination interface, more stable reads, Bfabric.from_config (#85)
leoschwarz May 7, 2024
45e2c4a
Deprecate some scripts
leoschwarz May 7, 2024
707bc7b
Merge pull request #88 from fgcz/protinf-flask
leoschwarz May 7, 2024
1810b64
added another hack for Zeep save, fixed minor read_pagination test bu…
May 8, 2024
3bc2fd9
timestamp safeguard temporarily disabled until bug fixed. Adjusted co…
May 8, 2024
981a17b
added explicit idonly to read() and read_multi()
May 8, 2024
d6f00d8
Update csv2dataset and dataset2csv (#87)
leoschwarz May 8, 2024
1f68300
Refactor read scripts (#86)
leoschwarz May 8, 2024
59c1724
Refactor upload scripts (#92)
leoschwarz May 8, 2024
a2c5f64
Remove add_query_timestamp logic
leoschwarz May 10, 2024
c79cf1f
Refactor status scripts (#89)
leoschwarz May 10, 2024
0b67246
Refactor save scripts (#91)
leoschwarz May 10, 2024
ebbefd4
Replace bfabric.py by bfabric2.py
leoschwarz May 10, 2024
077c306
Move some remaining wrapper creator related code into the relevant fo…
leoschwarz May 10, 2024
83dfaf5
Move result conversion into engines (#93)
leoschwarz May 13, 2024
4190f5e
Move some files to bfabric.results module
leoschwarz May 13, 2024
8ed4838
Rename remaining src module contents
leoschwarz May 13, 2024
8461e0c
Reformat files
leoschwarz May 13, 2024
f5aab81
Integration test for time range queries
May 13, 2024
cd6b179
update project files
leoschwarz May 16, 2024
8e6a6e1
add polars conversion convenience method
leoschwarz May 16, 2024
35fbfcf
update some more proteomics scripts
leoschwarz May 16, 2024
a020bd7
compatibility change
leoschwarz May 16, 2024
db32df1
add docstrings, typehints, __init__
leoschwarz May 16, 2024
eddf274
small changes in tests
leoschwarz May 16, 2024
e6530ea
documentation, clarify return_id_only parameter
leoschwarz May 16, 2024
a45675d
Extract multiquery (#94)
leoschwarz May 16, 2024
4fa8deb
Fix pyproject.toml for installation
leoschwarz May 16, 2024
9eb7ea6
make the github actions more strict
leoschwarz May 16, 2024
76faf79
clean up pyproject.toml
leoschwarz May 16, 2024
7bf2caa
move some type-checking only imports
leoschwarz May 16, 2024
697899a
test for multi-methods
May 16, 2024
bb71a4b
Merge branch 'dev-bfabric-4' of github.com:fgcz/bfabricPy into dev-bf…
May 16, 2024
9ae1ac9
set total_pages_api to `None` and avoid warnings in multiquery use case
leoschwarz May 17, 2024
cb1e01f
move the old integration tests
leoschwarz May 17, 2024
62c72f2
move demo_config.yaml
leoschwarz May 17, 2024
2a0d859
clean up shebang line and encoding declaration
leoschwarz May 17, 2024
494c6e7
convenience re-export
leoschwarz May 17, 2024
af87c59
reformat code
leoschwarz May 17, 2024
27b459d
code quality fixes
leoschwarz May 17, 2024
e5deb2b
add unit tests
leoschwarz May 17, 2024
e8d2e60
update README.md
leoschwarz May 17, 2024
7ef5729
update README.md
leoschwarz May 17, 2024
88ab710
config_path param
May 17, 2024
b9e47f0
Merge branch 'dev-bfabric-2' of github.com:fgcz/bfabricPy into dev-bf…
May 17, 2024
eac4cff
minor Path bug
May 17, 2024
f321a24
flask: simplify error handling
leoschwarz May 17, 2024
69599ed
adapt unit tests
leoschwarz May 17, 2024
6f47ec0
ensure compatibility with recent changes
leoschwarz May 21, 2024
3c328e5
deactivate automatic functional test (to be migrated)
leoschwarz May 21, 2024
fd30cfc
Add script to list the parameters of workunit runs
leoschwarz May 21, 2024
c52b182
polars-lts for m1 compbatibility
wolski May 22, 2024
92c3859
change version numbering
leoschwarz May 23, 2024
2a9695e
make filename of downloaded csv configurable
leoschwarz May 23, 2024
708b178
make ResultContainer iterable
leoschwarz May 23, 2024
8490b16
add a changelog
leoschwarz May 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/actions/setup-bfabricpy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Setup bfabricPy"
description: "Set up bfabricPy for use in GitHub Actions"
inputs:
python-version:
description: "Python version to use"
required: true
runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- name: Install bfabricPy
shell: bash
run: |
pip install uv
uv pip install --system ".[dev]"
12 changes: 6 additions & 6 deletions .github/workflows/run_functional_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ name: functionalTest
concurrency: functional-test-group

on:
push:
branches: [ main ]
schedule:
- cron: "00 08 * * *"
pull_request:
branches: [ main ]
#push:
# branches: [ main ]
#schedule:
# - cron: "00 08 * * *"
#pull_request:
# branches: [ main ]
workflow_dispatch:

jobs:
Expand Down
46 changes: 38 additions & 8 deletions .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: unit tests
name: PR Checks

on:
push:
Expand All @@ -8,15 +8,45 @@ on:
workflow_dispatch:

jobs:
build:
unit_tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-bfabricpy
with:
python-version: 3.9
- name: Install bfabricPy
run: python -m pip install .
- name: Run unit tests
run: python -m unittest discover -s bfabric/tests/unit -p 'test_*.py'
# Note: we use cd to double-check that the installation actually worked
run: cd bfabric/tests && python -m unittest discover -s ./unit -p 'test_*.py'
code_style:
name: Code Style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-bfabricpy
with:
python-version: 3.9
- name: Check code with ruff
run:
ruff bfabric || true
list_todos:
name: List TODOs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: sudo apt-get install -y ripgrep
name: Install ripgrep
- run:
rg -n TODO bfabric
name: List TODOs
license_check:
name: License Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-bfabricpy
with:
python-version: 3.9
- name: Check licenses
run: licensecheck
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/
__pycache__
bfabric.egg-info/
bfabric/__pycache__/
bfabric/scripts/query_result.txt
build/
dist/
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
test: test_workunit test_read
.PHONY: install install_dev build clean

test: test_read

test_workunit:
python3 -m unittest -v bfabric/tests/test_bfabric_workunit.py

test_read:
cd bfabric/tests && python3 -m unittest -v test_bfabric_read.py

install: test build
sudo pip3 install dist/bfabric*.gz -e .

build: clean
python3 setup.py sdist
install:
pip install -e .

install_dev:
pip install -e ".[dev]"

clean:
rm -vf dist/*
Expand Down
144 changes: 93 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,86 @@
![functionTest](https://github.com/fgcz/bfabricPy/workflows/functionalTest/badge.svg)
![unitTests](https://github.com/fgcz/bfabricPy/workflows/unit%20tests/badge.svg)
[![EDBT'10](https://img.shields.io/badge/EDBT-10.1145%2F1739041.1739135-brightgreen)](https://doi.org/10.1145/1739041.1739135)
[![JIB](https://img.shields.io/badge/JIB-10.1515%2Fjib.2022.0031-brightgreen)](https://doi.org/10.1515/jib-2022-0031)
![Downloads](https://img.shields.io/github/downloads/fgcz/bfabricPy/total)



# bfabricPy

This package connects the [bfabric](https://fgcz-bfabric.uzh.ch/bfabric/) system to the [python](https://www.python.org/) and [R](https://cran.r-project.org/) world while providing a JSON and REST interface using [Flask](https://www.fullstackpython.com).
The [bfabricShiny](https://github.com/cpanse/bfabricShiny) R package is an extension and provides code snippets and sample implementation for a seamless R shiny bfabric integration.
For more advanced users the *bfabricPy* package also provides a powerful query interface on the command-line though using the provided scripts.

## Install
The package can be installed like any other Python package, so if you are familiar you might not need to read this section.
Currently, it's only available from GitHub.

![bfabricPy-read](https://user-images.githubusercontent.com/4901987/65025926-db77c900-d937-11e9-8c92-f2412d6793ee.gif)
[see also #14](https://github.com/fgcz/bfabricPy/issues/14)
The best way to install the package depends on your use case, i.e. whether you want to:

## Requirements
1. Use the command line scripts
2. Use the Python API
3. Develop on the package

- install current stable Debian Linux release (any current BSD like or Microsoft OS will do)
The command line scripts are currently included in all cases.

- install the python3 package as follows:
### Command line scripts
To use the command line scripts, it's recommended to install `bfabricPy` with [pipx](https://pipx.pypa.io/).
If you don't have `pipx` installed, refer to the [pipx documentation](https://pipx.pypa.io/stable/installation/) for instructions.

```{bash}
git clone [email protected]:fgcz/bfabricPy.git \
&& cd bfabricPy
You can execute a command using a specific version of `bfabricPy` with the `pipx run` command.
This command handles the dependencies of multiple concurrent installations:

```bash
pipx run --spec "git+https://github.com/fgcz/[email protected]" bfabric_read.py --help
```

## Install
To install a specific version of bfabricPy on your system and make the command available without `pipx run` prefix, use the following command:
```bash
pipx install "git+https://github.com/fgcz/[email protected]"
bfabric_read.py --help
```

### Python API
If you're interested in using the Python API of `bfabricPy`, you have two options:

#### 1. Configure it in your `pyproject.toml` file.
```toml
[project]
dependencies = [
"bfabricPy @ git+https://github.com/fgcz/bfabricPy.git@main"
]
```

#### 2. Install the `bfabricPy` package directly using pip.
```bash
pip install git+https://github.com/fgcz/bfabricPy.git
````

### Development
As a bfabricPy developer: (i.e. an editable install)

```{bash}
python3 setup.py install --user
pip install -e ".[dev]"
```

## Configuration
Create a file as follows: (note: the password is not your login password, but the web service password)

```{yaml}
# ~/.bfabricpy.yml

GENERAL:
default_config: PRODUCTION

PRODUCTION:
login: yourBfabricLogin
password: yourBfabricWebPassword
base_url: https://fgcz-bfabric.uzh.ch/bfabric
```

```{bash}
cat ~/.bfabricrc.py
_WEBBASE="https://fgcz-bfabric-test.uzh.ch/bfabric"
_LOGIN="yourBfabricLogin"
_PASSWD='yourBfabricWebPassword'
You can also include an additional config for the TEST instance

```{yaml}
TEST:
login: yourBfabricLogin
password: yourBfabricWebPassword
base_url: https://fgcz-bfabric-test.uzh.ch/bfabric
```

## CheatSheet
Expand All @@ -65,41 +107,50 @@ bfabric_read.py workunit status failed
bfabric_read.py resource filechecksum d41d8cd98f00b204e9800998ecf8427e
```

call the `python3` interpreter and enter
Using the Python API:

```{py}
import bfabric
from bfabric import Bfabric

B = bfabric.Bfabric()
client = Bfabric.from.config()

user = B.read_object(endpoint = 'user', obj={'login': 'cpanse'})
resource = B.read_object(endpoint = 'resource', obj={'id': 550327 })
user = B.read(endpoint = 'user', obj={'login': 'cpanse'})
resource = B.read(endpoint = 'resource', obj={'id': 550327 })
```

### save
```
rv = B.save_object('workunit', {'id': 254063, 'status': 'available'})
B.print_json(rv)
# print(rv)
```{bash}
bfabric_save_workunit_attribute.py 199387 status available
```

### Command line code snippets

remove pending workunits from the past
```{bash}
bfabric_read.py workunit status pending \
| awk '$2~/cpanse/ && $3~/2015/{print $1}'
| fgcz_bfabric_delete_workunits.py
```{python}
import json
rv = client.save('workunit', {'id': 254063, 'status': 'available'})
print(json.dumps(rv.to_list_dict(), indent=2))
```

find empty resource files in bfabric
### Command line code snippet
Find empty resource files in bfabric
```{bash}
bfabric_read.py resource filechecksum `md5sum < /dev/null | cut -c-32` \
| cat -n \
| tail
```

## Examples
## Testing
Please be advised that integration tests will write to the `TEST` instance configured in your `~/.bfabricpy.yml` config file.

Run unit tests:
```{bash}
python3 -m unittest discover -s "bfabric/tests/unit"
```

Run integration tests (see note above):
```{bash}
python3 -m unittest discover -s "bfabric/tests/integration"
```

## Examples [outdated]

### bash script generated by the yaml wrapper creator / submitter

Expand Down Expand Up @@ -258,7 +309,7 @@ bfabric_read.py importresource \
done
```

## Send an E-mail
## Send an E-mail [outdated]

```
# by CT,CP
Expand All @@ -272,11 +323,7 @@ rv = B.save_object(endpoint = 'mail',
# shown as mail for user id 482
```

## Testing

```{sh}
cd bfabric/tests/ && python3 -m unittest discover; echo $?; cd -
```

## See also

Expand All @@ -287,25 +334,20 @@ cd bfabric/tests/ && python3 -m unittest discover; echo $?; cd -

## FAQ


### How to resolve `<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed`?

on macOSX
```
cd /Applications/Python 3.12 && ./Install\ Certificates.command
```

### How is the version numbering working?

X.Y.Z

X is not used

Y should be the bfabric release
X is used for major changes, that contain breaking changes

Z increment for significant changes
Y should be the current bfabric release

Also, please note that the branch ID should correspond with the bfabric stable release number.
Z is increased for feature releases, that should not break the API

### Howto cite?

Expand Down
Loading