Skip to content

Commit

Permalink
Merge pull request #136 from fgcz/main
Browse files Browse the repository at this point in the history
bfabricPy 1.13.19
  • Loading branch information
leoschwarz authored Feb 6, 2025
2 parents ae0514e + a9f5edd commit b0c65a0
Show file tree
Hide file tree
Showing 178 changed files with 990 additions and 1,142 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build-app-runner/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
source-path:
description: 'Path to app runner source code'
required: false
default: 'app_runner'
default: 'bfabric_app_runner'
outputs:
artifact-name:
description: 'Name of the uploaded artifact'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_app_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
id: build
with:
output-path: build-output
source-path: app_runner
source-path: bfabric_app_runner
- name: Comment PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
Expand Down
51 changes: 0 additions & 51 deletions .github/workflows/complete_release.yml

This file was deleted.

21 changes: 19 additions & 2 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- release_bfabric
- release_bfabric_scripts
- release_app_runner
- release_bfabric_app_runner
workflow_dispatch:
inputs:
package:
Expand All @@ -13,7 +13,7 @@ on:
options:
- bfabric
- bfabric_scripts
- app_runner
- bfabric_app_runner
default: bfabric
environment:
description: 'Target PyPI'
Expand All @@ -28,6 +28,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write # permission to create tags
steps:
- uses: actions/checkout@v4
# Step: Determine the package that is being built
Expand Down Expand Up @@ -62,6 +63,13 @@ jobs:
python-version: '3.11'
- name: Install hatch
run: pip install hatch
- name: Get package version
id: get-version
run: |
cd ${{ env.PACKAGE }}
VERSION=$(hatch version)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Package version: $VERSION"
- name: Build package
run: |
cd ${{ env.PACKAGE }}
Expand All @@ -71,11 +79,20 @@ jobs:
with:
repository-url: ${{ env.PYPI_REPOSITORY_URL }}
packages-dir: ${{ env.PACKAGE }}/dist
- name: Create and push tag
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
TAG_NAME="${{ env.PACKAGE }}/${{ env.VERSION }}"
git tag -a "$TAG_NAME" -m "Release ${{ env.PACKAGE }} version ${{ env.VERSION }}"
git push origin "$TAG_NAME"
- name: Debug package info
run: |
echo "Built and published package: ${{ env.PACKAGE }}"
echo "Created tag: ${{ env.PACKAGE }}/${{ env.VERSION }}"
if [ "${{ env.PYPI_REPOSITORY_URL }}" == "https://pypi.org/legacy/" ]; then
echo "Check it at: https://pypi.org/project/${{ env.PACKAGE }}/"
else
echo "Check it at: https://test.pypi.org/project/${{ env.PACKAGE }}/"
fi
if: always()
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:
autofix_commit_msg: "style: pre-commit fixes"
repos:
- repo: https://github.com/psf/black
rev: "24.8.0"
rev: "25.1.0"
hooks:
- id: black
- repo: https://github.com/adamchainz/blacken-docs
Expand Down
18 changes: 0 additions & 18 deletions app_runner/docs/index.md

This file was deleted.

4 changes: 2 additions & 2 deletions bfabric/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "hatchling.build"
[project]
name = "bfabric"
description = "Python client for the B-Fabric API"
version = "1.13.18"
version = "1.13.19"
license = { text = "GPL-3.0" }
authors = [
{ name = "Christian Panse", email = "cp@fgcz.ethz.ch" },
Expand Down Expand Up @@ -53,7 +53,7 @@ Repository = "https://github.com/fgcz/bfabricPy"


[tool.uv]
reinstall-package = ["bfabric", "bfabric_scripts", "app_runner"]
reinstall-package = ["bfabric", "bfabric_scripts", "bfabric_app_runner"]

[tool.black]
line-length = 120
Expand Down
30 changes: 7 additions & 23 deletions bfabric/src/bfabric/bfabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ def from_config(
If it is set to None, no authentication will be used.
:param engine: Engine to use for the API. Default is SUDS.
"""
config, auth_config = get_system_auth(
config_env=config_env, config_path=config_path
)
config, auth_config = get_system_auth(config_env=config_env, config_path=config_path)
auth_used: BfabricAuth | None = auth_config if auth == "config" else auth
return cls(config, auth_used, engine=engine)

Expand Down Expand Up @@ -195,9 +193,7 @@ def read(
response_items += results[page_offset:]
page_offset = 0

result = ResultContainer(
response_items, total_pages_api=n_available_pages, errors=errors
)
result = ResultContainer(response_items, total_pages_api=n_available_pages, errors=errors)
if check:
result.assert_success()
return result.get_first_n_results(max_results)
Expand All @@ -217,16 +213,12 @@ def save(
appropriate to be used instead.
:return a ResultContainer describing the saved object if successful
"""
results = self._engine.save(
endpoint=endpoint, obj=obj, auth=self.auth, method=method
)
results = self._engine.save(endpoint=endpoint, obj=obj, auth=self.auth, method=method)
if check:
results.assert_success()
return results

def delete(
self, endpoint: str, id: int | list[int], check: bool = True
) -> ResultContainer:
def delete(self, endpoint: str, id: int | list[int], check: bool = True) -> ResultContainer:
"""Deletes the object with the specified ID from the specified endpoint.
:param endpoint: the endpoint to delete from, e.g. "sample"
:param id: the ID of the object to delete
Expand Down Expand Up @@ -353,19 +345,11 @@ def get_system_auth(
if not resolved_path.is_file():
if config_path:
# NOTE: If user explicitly specifies a path to a wrong config file, this has to be an exception
raise OSError(
f"Explicitly specified config file does not exist: {resolved_path}"
)
raise OSError(f"Explicitly specified config file does not exist: {resolved_path}")
# TODO: Convert to log
print(
f"Warning: could not find the config file in the default location: {resolved_path}"
)
print(f"Warning: could not find the config file in the default location: {resolved_path}")
config = BfabricClientConfig(base_url=base_url)
auth = (
None
if login is None or password is None
else BfabricAuth(login=login, password=password)
)
auth = None if login is None or password is None else BfabricAuth(login=login, password=password)

# Load config from file, override some of the fields with the provided ones
else:
Expand Down
4 changes: 1 addition & 3 deletions bfabric/src/bfabric/bfabric2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3
import warnings

warnings.warn(
"bfabric.bfabric2 module is deprecated, use bfabric instead", DeprecationWarning
)
warnings.warn("bfabric.bfabric2 module is deprecated, use bfabric instead", DeprecationWarning)
# TODO deprecated - import from bfabric instead
4 changes: 1 addition & 3 deletions bfabric/src/bfabric/bfabric_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def read_config(
- If not, finally, the parser will select the default_config specified in [GENERAL] of the .bfabricpy.yml file
"""
logger.debug(f"Reading configuration from: {config_path}")
config_file = ConfigFile.model_validate(
yaml.safe_load(Path(config_path).read_text())
)
config_file = ConfigFile.model_validate(yaml.safe_load(Path(config_path).read_text()))
env_config = config_file.get_selected_config(explicit_config_env=config_env)
return env_config.config, env_config.auth
6 changes: 2 additions & 4 deletions bfabric/src/bfabric/cli_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ def setup_script_logging(debug: bool = False) -> None:
if os.environ.get(setup_flag_key, "0") == "1":
return
logger.remove()
packages = ["bfabric", "bfabric_scripts", "app_runner", "__main__"]
packages = ["bfabric", "bfabric_scripts", "bfabric_app_runner", "__main__"]
if not (debug or os.environ.get("BFABRICPY_DEBUG")):
for package in packages:
logger.add(
sys.stderr, filter=package, level="INFO", format="{level} {message}"
)
logger.add(sys.stderr, filter=package, level="INFO", format="{level} {message}")
else:
for package in packages:
logger.add(sys.stderr, filter=package, level="DEBUG")
Expand Down
8 changes: 2 additions & 6 deletions bfabric/src/bfabric/config/bfabric_client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class BfabricClientConfig(BaseModel):

def __init__(self, **kwargs: Any) -> None:
# TODO remove this custom constructor (note that this is currently used in some places when "None" is passed)
super().__init__(
**{key: value for key, value in kwargs.items() if value is not None}
)
super().__init__(**{key: value for key, value in kwargs.items() if value is not None})

def copy_with(
self,
Expand All @@ -39,9 +37,7 @@ def copy_with(
"""Returns a copy of the configuration with new values applied, if they are not None."""
return BfabricClientConfig(
base_url=base_url if base_url is not None else self.base_url,
application_ids=(
application_ids if application_ids is not None else self.application_ids
),
application_ids=(application_ids if application_ids is not None else self.application_ids),
job_notification_emails=self.job_notification_emails,
)

Expand Down
22 changes: 5 additions & 17 deletions bfabric/src/bfabric/config/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def gather_config(cls, values: dict[str, Any]) -> dict[str, Any]:
"""Gathers all configs into the config field."""
if not isinstance(values, dict):
return values
values["config"] = {
key: value
for key, value in values.items()
if key not in ["login", "password"]
}
values["config"] = {key: value for key, value in values.items() if key not in ["login", "password"]}
return values

@model_validator(mode="before")
Expand Down Expand Up @@ -78,21 +74,13 @@ def get_selected_config_env(self, explicit_config_env: str | None) -> str:
if explicit_config_env:
return explicit_config_env
elif "BFABRICPY_CONFIG_ENV" in os.environ:
logger.debug(
f"found BFABRICPY_CONFIG_ENV = {os.environ['BFABRICPY_CONFIG_ENV']}"
)
logger.debug(f"found BFABRICPY_CONFIG_ENV = {os.environ['BFABRICPY_CONFIG_ENV']}")
return os.environ["BFABRICPY_CONFIG_ENV"]
else:
logger.debug(
f"BFABRICPY_CONFIG_ENV not found, using default environment {self.general.default_config}"
)
logger.debug(f"BFABRICPY_CONFIG_ENV not found, using default environment {self.general.default_config}")
return self.general.default_config

def get_selected_config(
self, explicit_config_env: str | None = None
) -> EnvironmentConfig:
def get_selected_config(self, explicit_config_env: str | None = None) -> EnvironmentConfig:
"""Returns the selected configuration, by checking the hierarchy of config_env definitions.
See selected_config_env for details."""
return self.environments[
self.get_selected_config_env(explicit_config_env=explicit_config_env)
]
return self.environments[self.get_selected_config_env(explicit_config_env=explicit_config_env)]
20 changes: 5 additions & 15 deletions bfabric/src/bfabric/engine/engine_suds.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def read(
response = service.read(full_query)
return self._convert_results(response=response, endpoint=endpoint)

def save(
self, endpoint: str, obj: dict, auth: BfabricAuth, method: str = "save"
) -> ResultContainer:
def save(self, endpoint: str, obj: dict, auth: BfabricAuth, method: str = "save") -> ResultContainer:
"""Saves the provided object to the specified endpoint.
:param endpoint: the endpoint to save to, e.g. "sample"
:param obj: the object to save
Expand All @@ -72,14 +70,10 @@ def save(
try:
response = getattr(service, method)(query)
except MethodNotFound as e:
raise BfabricRequestError(
f"SUDS failed to find save method for the {endpoint} endpoint."
) from e
raise BfabricRequestError(f"SUDS failed to find save method for the {endpoint} endpoint.") from e
return self._convert_results(response=response, endpoint=endpoint)

def delete(
self, endpoint: str, id: int | list[int], auth: BfabricAuth
) -> ResultContainer:
def delete(self, endpoint: str, id: int | list[int], auth: BfabricAuth) -> ResultContainer:
"""Deletes the object with the specified ID from the specified endpoint.
:param endpoint: the endpoint to delete from, e.g. "sample"
:param id: the ID of the object to delete
Expand All @@ -99,9 +93,7 @@ def _get_suds_service(self, endpoint: str) -> ServiceProxy:
"""Returns a SUDS service for the given endpoint. Reuses existing instances when possible."""
if endpoint not in self._cl:
try:
self._cl[endpoint] = Client(
f"{self._base_url}/{endpoint}?wsdl", cache=None
)
self._cl[endpoint] = Client(f"{self._base_url}/{endpoint}?wsdl", cache=None)
except suds.transport.TransportError as error:
if error.httpcode == 404:
msg = f"Non-existent endpoint {repr(endpoint)} or the configured B-Fabric instance was not found."
Expand All @@ -127,6 +119,4 @@ def _convert_results(self, response: Any, endpoint: str) -> ResultContainer:
sort_keys=True,
)
results += [result_parsed]
return ResultContainer(
results=results, total_pages_api=n_available_pages, errors=errors
)
return ResultContainer(results=results, total_pages_api=n_available_pages, errors=errors)
Loading

0 comments on commit b0c65a0

Please sign in to comment.