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

Replaced wild card imports #460

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 19 additions & 12 deletions sbol3/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@
import logging
import os
import posixpath
import warnings
from pathlib import Path
from typing import Dict, Callable, List, Optional, Any, Union, Iterable

# import typing for typing.Sequence, which we don't want to confuse
# with sbol3.Sequence
import typing as pytyping
import warnings
from pathlib import Path
from typing import Any, Callable, Dict, Iterable, List, Optional, Union

import pyshacl
import rdflib

from . import *
from .object import BUILDER_REGISTER
from .constants import (JSONLD, NTRIPLES, OM_NS, PROV_NS, RDF_TYPE, RDF_XML,
SBOL3_NS, SBOL_IDENTIFIED, SBOL_LOGGER_NAME,
SBOL_NAMESPACE, SBOL_TOP_LEVEL, SORTED_NTRIPLES,
TURTLE)
from .custom import CustomIdentified, CustomTopLevel
from .error import SBOLError
from .identified import Identified
from .object import BUILDER_REGISTER, SBOLObject
from .property_base import SingletonProperty
from .toplevel import TopLevel
from .validation import ValidationReport

_default_bindings = {
'sbol': SBOL3_NS,
Expand Down Expand Up @@ -161,9 +169,9 @@ def _build_object(self, identity: str, types: List[str]) -> Optional[Identified]
else:
try:
builder = self._uri_type_map[sbol_type]
except KeyError:
except KeyError as exc:
logging.warning(f'No builder found for {sbol_type}')
raise SBOLError(f'Unknown type {sbol_type}')
raise SBOLError(f'Unknown type {sbol_type}') from exc
result = builder(identity=identity, type_uri=sbol_type)
# Fix https://github.com/SynBioDex/pySBOL3/issues/264
if isinstance(result, TopLevel):
Expand Down Expand Up @@ -198,7 +206,7 @@ def _parse_objects(self, graph: rdflib.Graph) -> Dict[str, SBOLObject]:
def _parse_attributes(objects, graph) -> dict[str, Identified]:
# Track the child objects that get assigned to optimize the
# search for orphans later in the loading process.
child_objects = dict()
child_objects = {}
for s, p, o in graph.triples((None, None, None)):
str_s = str(s)
str_p = str(p)
Expand Down Expand Up @@ -314,10 +322,9 @@ def file_extension(file_format: str) -> str:
RDF_XML: '.xml',
TURTLE: '.ttl'
}
if file_format in types_with_standard_extension:
return types_with_standard_extension[file_format]
else:
if file_format not in types_with_standard_extension:
raise ValueError('Provided file format is not a valid one.')
return types_with_standard_extension[file_format]

# Formats: 'n3', 'nt', 'turtle', 'xml'
def read(self, location: Union[Path, str], file_format: str = None) -> None:
Expand Down
15 changes: 12 additions & 3 deletions sbol3/location.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import abc
from typing import Union, Any, Optional

from . import *
from typing import Any, Optional, Union

from .constants import (PYSBOL3_MISSING, SBOL_CUT, SBOL_END,
SBOL_ENTIRE_SEQUENCE, SBOL_ORDER, SBOL_ORIENTATION,
SBOL_RANGE, SBOL_SEQUENCES, SBOL_START)
from .document import Document
from .identified import Identified
from .int_property import IntProperty
from .refobj_property import ReferencedObject
from .sequence import Sequence
from .typing import uri_singleton
from .uri_property import URIProperty
from .validation import ValidationReport

int_property = Union[IntProperty, int]

Expand Down
14 changes: 10 additions & 4 deletions sbol3/om_compound.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import abc
from typing import Union, List, Any

from . import *

from typing import Any, List, Union

from .constants import (OM_HAS_BASE, OM_HAS_DENOMINATOR, OM_HAS_EXPONENT,
OM_HAS_NUMERATOR, OM_HAS_TERM1, OM_HAS_TERM2, OM_LABEL,
OM_SYMBOL, OM_UNIT_DIVISION, OM_UNIT_EXPONENTIATION,
OM_UNIT_MULTIPLICATION, PYSBOL3_MISSING)
from .document import Document
from .int_property import IntProperty
from .object import SBOLObject
from .om_unit import Unit
from .refobj_property import ReferencedObject


class CompoundUnit(Unit, abc.ABC):
Expand Down
17 changes: 12 additions & 5 deletions sbol3/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
import copy
import math
import posixpath
import typing
import urllib.parse
import uuid
import warnings
from typing import Dict, Callable, Optional, Any
import typing

from . import *
from .typing import *
from typing import Any, Callable, Dict, Optional

from .config import get_namespace
from .constants import (PYSBOL3_DEFAULT_NAMESPACE, SBOL_HAS_ATTACHMENT,
SBOL_NAMESPACE)
from .identified import Identified
from .property_base import ListProperty
from .refobj_property import ReferencedObject
from .typing import Property, Union, ownedobj_list_arg, refobj_list_arg
from .uri_property import URIProperty
from .validation import ValidationReport


class TopLevel(Identified):
Expand Down