Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 16 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
exclude: '^docs/conf.py'

minimum_pre_commit_version: 3.2.0
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand All @@ -17,24 +18,25 @@ repos:
- id: mixed-line-ending
args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows

## If you want to avoid flake8 errors due to unused vars or imports:
# - repo: https://github.com/myint/autoflake
# rev: v1.4
# hooks:
# - id: autoflake
# args: [
# --in-place,
# --remove-all-unused-imports,
# --remove-unused-variables,
# ]
# If you want to avoid flake8 errors due to unused vars or imports:
- repo: https://github.com/myint/autoflake
rev: v2.3.1
hooks:
- id: autoflake
args: [
# --in-place, # Use this to modify the files in place, without printing diffs, as opposed to --stdout
--stdout,
--remove-all-unused-imports,
--remove-unused-variables,
]

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.10.0
hooks:
- id: black
language_version: python3
Expand All @@ -47,8 +49,8 @@ repos:
# additional_dependencies: [black]

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
## You can add flake8 plugins via `additional_dependencies`:
# additional_dependencies: [flake8-bugbear]
additional_dependencies: [flake8-bugbear]
4 changes: 3 additions & 1 deletion examples/device_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
OSW.StoreEntityParam(
entities=[new_category],
namespace="Category",
# meta_category_title="Category:OSWd845b96813a344458f140e48c4d063fd" # usage of MetaDeviceCategory not yet supported
# meta_category_title= (
# "Category:OSWd845b96813a344458f140e48c4d063fd")
# usage of MetaDeviceCategory not yet supported
)
)

Expand Down
2 changes: 1 addition & 1 deletion examples/gui_local_slot_editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def save_as_page_package(
with open(settings["settings_file_path"], "r") as f:
settings = json.load(f)
# update GUI
window["-CREDENTIALS-"].update(settings["credentials_file_path"]),
window["-CREDENTIALS-"].update(settings["credentials_file_path"])
window["-LWD-"].update(settings["local_working_directory"])
window["-DOMAIN-"].update(settings["domain"])
window["-ADDRESS-"].update(settings["target_page"])
Expand Down
35 changes: 21 additions & 14 deletions examples/ontology_import emmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,61 @@
ontology_name = "BVCO"

# Define ontology metadata
emmo = model.Ontology(
emmo = model.OwlOntology(
name="EMMO",
label=[model.Label(text="EMMO", lang="en")],
iri="http://emmo.info/emmo",
prefix="http://emmo.info/emmo#",
prefix_name="emmo",
link="https://github.com/emmo-repo/EMMO",
see_also=["https://github.com/emmo-repo/EMMO"],
)
dc = model.Ontology(
dc = model.OwlOntology(
name="DC",
label=[model.Label(text="Dublin Core", lang="en")],
iri="http://purl.org/dc/elements/1.1",
prefix="http://purl.org/dc/elements/1.1/",
prefix_name="dc",
link="http://purl.org/dc",
see_also=["http://purl.org/dc"],
)
battinfo = model.Ontology(
battinfo = model.OwlOntology(
name="EMMO BattINFO",
label=[model.Label(text="EMMO BattINFO", lang="en")],
iri="http://emmo.info/battery",
prefix="http://emmo.info/battery#",
prefix_name="battinfo",
link="https://github.com/BIG-MAP/BattINFO",
see_also=["https://github.com/BIG-MAP/BattINFO"],
)
electrochemistry = model.Ontology(
electrochemistry = model.OwlOntology(
name="EMMO Electrochemistry",
label=[model.Label(text="EMMO Electrochemistry", lang="en")],
iri="http://emmo.info/electrochemistry",
prefix="http://emmo.info/electrochemistry#",
prefix_name="electrochemistry",
link="https://github.com/emmo-repo/EMMO",
see_also=["https://github.com/emmo-repo/EMMO"],
)
periodictable = model.Ontology(
periodictable = model.OwlOntology(
name="EMMO Periodic Table",
label=[model.Label(text="EMMO Periodic Table", lang="en")],
iri="http://emmo.info/emmo/domain/periodic-table",
prefix="http://emmo.info/emmo/domain/periodic-table#",
prefix_name="periodictable",
link="https://github.com/emmo-repo/EMMO",
see_also=["https://github.com/emmo-repo/EMMO"],
)
gpo = model.Ontology(
gpo = model.OwlOntology(
name="GPO",
label=[model.Label(text="General Process Ontology", lang="en")],
iri="https://gpo.ontology.link",
prefix="https://gpo.ontology.link/",
prefix_name="gpo",
link="https://github.com/General-Process-Ontology/ontology",
see_also=["https://github.com/General-Process-Ontology/ontology"],
)
bvco = model.Ontology(
bvco = model.OwlOntology(
name="BVCO",
label=[model.Label(text="Battery Value Chain Ontology", lang="en")],
iri="https://bvco.ontology.link",
prefix="https://bvco.ontology.link/",
prefix_name="bvco",
link="https://github.com/Battery-Value-Chain-Ontology/ontology",
see_also=["https://github.com/Battery-Value-Chain-Ontology/ontology"],
)

import_config = ImportConfig(
Expand Down
5 changes: 3 additions & 2 deletions examples/ontology_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@

ontology_name = "example_ontology"

ex = model.Ontology(
ex = model.OwlOntology(
name="Example",
label=[model.Label(text="Example", lang="en")],
iri="http://example.com",
prefix="http://example.com/",
prefix_name="example",
link="http://example.com",
see_also=["http://example.com"],
)

import_config = ImportConfig(
Expand Down
3 changes: 2 additions & 1 deletion examples/page_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def slot_default_values():
def modify(wtpage: WtPage):
edit = True
# print(wtpage.get_last_changed_time())
# if wtpage.get_last_changed_time() > datetime.fromisoformat('2023-01-15T12:00:00+00:00'):
# if (wtpage.get_last_changed_time() >
# datetime.fromisoformat('2023-01-15T12:00:00+00:00')):
# print("new")
# else:
# print("old")
Expand Down
4 changes: 3 additions & 1 deletion examples/prefect/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ class ConnectionSettings(model.OswBaseModel):


@task
def connect(settings: Optional[ConnectionSettings] = ConnectionSettings()):
def connect(settings: Optional[ConnectionSettings] = None):
"""Initiates the connection to the OSW instance

Parameters
----------
settings
see ConnectionSetttings dataclass
"""
if settings is None:
settings = ConnectionSettings()
global wtsite
# define username
if environ.get("OSW_USER") is not None and environ.get("OSW_USER") != "":
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ S3 = boto3

# Add here dev requirements (semicolon/line-separated)
dev =
pre-commit>=3.2.0
tox

# Add here test requirements (semicolon/line-separated)
Expand Down
2 changes: 1 addition & 1 deletion src/osw/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def save_credentials_to_file(
with open(write_to_fp, "r") as stream:
content = stream.read()
comment_set = False
for ii, fp in enumerate(filepath_):
for _ii, fp in enumerate(filepath_):
if fp.name not in content:
print(f"Adding '{fp.name}' to gitignore file '{write_to_fp}'.")
with open(write_to_fp, "a") as stream:
Expand Down
12 changes: 7 additions & 5 deletions src/osw/controller/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# This file is required to make Python treat directories containing the file as packages.
# Additionally, classes from multiple files are imported to allow easy access via 'osw.controller.<ClassName>
# This file is required to make Python treat directories containing the file as
# packages.
# Additionally, classes from multiple files are imported to allow easy access via
# 'osw.controller.<ClassName>

import inspect
from pprint import pprint

import osw.model.entity as model

# imports of controllers for always present models
from osw.controller.entity import Entity
# note: to keep this import auto-removal per pre-commit hook is disabled
from osw.controller.entity import Entity # noqa: F401

# conditional imports
models = [m[0] for m in inspect.getmembers(model)]

if "Database" in models:
from osw.controller.database import DatabaseController
from osw.controller.database import DatabaseController # noqa: F401
2 changes: 0 additions & 2 deletions src/osw/controller/file/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def get(self) -> IO:
-------
the IO object of the opened file
"""
pass

@abstractmethod
def put(self, file: IO, **kwargs: Dict[str, Any]):
Expand All @@ -27,7 +26,6 @@ def put(self, file: IO, **kwargs: Dict[str, Any]):
file
the IO object to read from
"""
pass

def put_from(self, other: "FileController", **kwargs: Dict[str, Any]):
"""Writes or uploads a file from another file controller
Expand Down
5 changes: 3 additions & 2 deletions src/osw/controller/file/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
# TODO: add addional remove file with https://docs.prefect.io/2.11.4/concepts/filesystems/


# note: the order of the base classes is important
# the data class must be the first base class, otherwise subclass controllers fall back to the data model of the controller superclass
# Note: the order of the base classes is important
# The data class must be the first base class, otherwise subclass controllers fall back
# to the data model of the controller superclass
class RemoteFileController(model.RemoteFile, FileController):
@abstractmethod
def get(self) -> IO:
Expand Down
20 changes: 14 additions & 6 deletions src/osw/controller/file/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ def get(self) -> IO:
web_api_failed = False
response = None
try:
url = f"{self.osw.site._site.scheme}://{self.osw.site._site.host}{self.osw.site._site.path}api.php?action=download&format=json&title={full_title}"
url = (
f"{self.osw.site._site.scheme}://"
f"{self.osw.site._site.host}"
f"{self.osw.site._site.path}"
f"api.php?action=download&format=json&title={full_title}"
)
# print("Use web api: ", url)
response = self.osw.site._site.connection.get(url, stream=True)
api_error = response.headers.get("Mediawiki-Api-Error")
Expand All @@ -63,20 +68,22 @@ def get(self) -> IO:
# fallback: use direct download
url = file.imageinfo["url"]
print(
"Extension FileApi not installed on the server. Fallback: use direct download from ",
"Extension FileApi not installed on the server. Fallback: use direct "
"download from ",
url,
)
response = self.osw.site._site.connection.get(url, stream=True)

if response.status_code != 200:
raise Exception(
"Download failed. Please note that bot or OAuth logins have in general no permission for direct downloads. Error: "
+ response.text
"Download failed. Please note that bot or OAuth logins have in general "
"no permission for direct downloads. Error: " + response.text
)

# for chunk in response.iter_content(1024):
# destination.write(chunk)
# see https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests
# See https://stackoverflow.com/questions/16694907/
# download-large-file-in-python-with-requests
response.raw.read = functools.partial(response.raw.read, decode_content=True)
return response.raw

Expand All @@ -90,7 +97,8 @@ def get_to(self, other: "FileController"):
) as response:
# for chunk in response.iter_content(1024):
# destination.write(chunk)
# see https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests
# See https://stackoverflow.com/questions/16694907/
# download-large-file-in-python-with-requests
response.raw.read = functools.partial(
response.raw.read, decode_content=True
)
Expand Down
6 changes: 2 additions & 4 deletions src/osw/controller/page_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,13 @@ def read_package_script_file(script_fp: Path, package_name: str = None) -> dict:
def get_listed_pages_from_package_script(package_script: dict) -> List[str]:
"""Takes in the output of read_package_script_file and returns a list of
pages listed in the package"""
return getattr(package_script["package_meta_data"], "page_titles")
return getattr(package_script["package_meta_data"], "page_titles", [])


def get_required_packages_from_package_script(package_script: dict) -> List[str]:
"""Takes in the output of read_package_script_file and returns a list of
packages listed in the package"""
if getattr(package_script["package_meta_data"], "requiredPackages"):
return getattr(package_script["package_meta_data"], "requiredPackages")
return []
return getattr(package_script["package_meta_data"], "requiredPackages", [])


def read_package_info_file(
Expand Down
Loading
Loading