biocypher 0.6.2__py3-none-any.whl → 0.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of biocypher might be problematic. Click here for more details.

Files changed (34) hide show
  1. biocypher/__init__.py +3 -13
  2. biocypher/_config/__init__.py +6 -23
  3. biocypher/_config/biocypher_config.yaml +14 -3
  4. biocypher/_core.py +360 -262
  5. biocypher/_create.py +13 -27
  6. biocypher/_deduplicate.py +4 -11
  7. biocypher/_get.py +21 -60
  8. biocypher/_logger.py +4 -16
  9. biocypher/_mapping.py +4 -17
  10. biocypher/_metadata.py +3 -15
  11. biocypher/_misc.py +14 -28
  12. biocypher/_ontology.py +127 -212
  13. biocypher/_translate.py +34 -58
  14. biocypher/output/connect/_get_connector.py +40 -0
  15. biocypher/output/connect/_neo4j_driver.py +9 -65
  16. biocypher/output/in_memory/_get_in_memory_kg.py +34 -0
  17. biocypher/output/in_memory/_in_memory_kg.py +40 -0
  18. biocypher/output/in_memory/_networkx.py +44 -0
  19. biocypher/output/in_memory/_pandas.py +20 -15
  20. biocypher/output/write/_batch_writer.py +166 -179
  21. biocypher/output/write/_get_writer.py +11 -24
  22. biocypher/output/write/_writer.py +43 -44
  23. biocypher/output/write/graph/_arangodb.py +7 -24
  24. biocypher/output/write/graph/_neo4j.py +51 -56
  25. biocypher/output/write/graph/_networkx.py +36 -43
  26. biocypher/output/write/graph/_rdf.py +107 -95
  27. biocypher/output/write/relational/_csv.py +6 -11
  28. biocypher/output/write/relational/_postgresql.py +5 -13
  29. biocypher/output/write/relational/_sqlite.py +3 -1
  30. {biocypher-0.6.2.dist-info → biocypher-0.8.0.dist-info}/LICENSE +1 -1
  31. {biocypher-0.6.2.dist-info → biocypher-0.8.0.dist-info}/METADATA +3 -3
  32. biocypher-0.8.0.dist-info/RECORD +43 -0
  33. {biocypher-0.6.2.dist-info → biocypher-0.8.0.dist-info}/WHEEL +1 -1
  34. biocypher-0.6.2.dist-info/RECORD +0 -39
@@ -1,38 +1,27 @@
1
- #!/usr/bin/env python
2
-
3
- #
4
- # Copyright 2021, Heidelberg University Clinic
5
- #
6
- # File author(s): Sebastian Lobentanzer
7
- # Michael Hartung
8
- #
9
- # Distributed under MIT licence, see the file `LICENSE`.
10
- #
11
1
  """
12
2
  BioCypher 'offline' module. Handles the writing of node and edge representations
13
3
  suitable for import into a DBMS.
14
4
  """
15
5
 
6
+ from typing import TYPE_CHECKING
7
+
8
+ from biocypher._config import config as _config
16
9
  from biocypher._logger import logger
17
- from biocypher.output.write.graph._rdf import _RDFWriter
18
- from biocypher.output.write.graph._neo4j import _Neo4jBatchWriter
19
10
  from biocypher.output.write.graph._arangodb import _ArangoDBBatchWriter
11
+ from biocypher.output.write.graph._neo4j import _Neo4jBatchWriter
20
12
  from biocypher.output.write.graph._networkx import _NetworkXWriter
13
+ from biocypher.output.write.graph._rdf import _RDFWriter
21
14
  from biocypher.output.write.relational._csv import _PandasCSVWriter
22
- from biocypher.output.write.relational._sqlite import _SQLiteBatchWriter
23
15
  from biocypher.output.write.relational._postgresql import _PostgreSQLBatchWriter
16
+ from biocypher.output.write.relational._sqlite import _SQLiteBatchWriter
24
17
 
25
18
  logger.debug(f"Loading module {__name__}.")
26
19
 
27
- from typing import TYPE_CHECKING
28
-
29
- from biocypher._config import config as _config
30
-
31
20
  __all__ = ["get_writer", "DBMS_TO_CLASS"]
32
21
 
33
22
  if TYPE_CHECKING:
34
- from biocypher._translate import Translator
35
23
  from biocypher._deduplicate import Deduplicator
24
+ from biocypher._translate import Translator
36
25
 
37
26
  DBMS_TO_CLASS = {
38
27
  "neo": _Neo4jBatchWriter,
@@ -52,6 +41,8 @@ DBMS_TO_CLASS = {
52
41
  "CSV": _PandasCSVWriter,
53
42
  "pandas": _PandasCSVWriter,
54
43
  "Pandas": _PandasCSVWriter,
44
+ "tabular": _PandasCSVWriter,
45
+ "Tabular": _PandasCSVWriter,
55
46
  "networkx": _NetworkXWriter,
56
47
  "NetworkX": _NetworkXWriter,
57
48
  }
@@ -99,12 +90,8 @@ def get_writer(
99
90
  import_call_file_prefix=dbms_config.get("import_call_file_prefix"),
100
91
  wipe=dbms_config.get("wipe"),
101
92
  strict_mode=strict_mode,
102
- skip_bad_relationships=dbms_config.get(
103
- "skip_bad_relationships"
104
- ), # neo4j
105
- skip_duplicate_nodes=dbms_config.get(
106
- "skip_duplicate_nodes"
107
- ), # neo4j
93
+ skip_bad_relationships=dbms_config.get("skip_bad_relationships"), # neo4j
94
+ skip_duplicate_nodes=dbms_config.get("skip_duplicate_nodes"), # neo4j
108
95
  db_user=dbms_config.get("user"), # psql
109
96
  db_password=dbms_config.get("password"), # psql
110
97
  db_port=dbms_config.get("port"), # psql
@@ -1,12 +1,12 @@
1
+ import os
2
+
1
3
  from abc import ABC, abstractmethod
2
- from typing import Union, Optional
3
4
  from collections.abc import Iterable
4
- import os
5
5
 
6
6
  from biocypher._create import BioCypherEdge, BioCypherNode, BioCypherRelAsNode
7
+ from biocypher._deduplicate import Deduplicator
7
8
  from biocypher._logger import logger
8
9
  from biocypher._translate import Translator
9
- from biocypher._deduplicate import Deduplicator
10
10
 
11
11
  __all__ = ["_Writer"]
12
12
 
@@ -22,26 +22,28 @@ class _Writer(ABC):
22
22
  - _get_import_script_name
23
23
 
24
24
  Args:
25
+ ----
25
26
  translator (Translator): Instance of :py:class:`Translator` to enable translation of
26
27
  nodes and manipulation of properties.
27
28
  deduplicator (Deduplicator): Instance of :py:class:`Deduplicator` to enable deduplication
28
29
  of nodes and edges.
29
30
  output_directory (str, optional): Path for exporting CSV files. Defaults to None.
30
31
  strict_mode (bool, optional): Whether to enforce source, version, and license properties. Defaults to False.
31
- strict_mode (bool, optional): Whether to enforce source, version, and license properties. Defaults to False.
32
32
 
33
33
  Raises:
34
+ ------
34
35
  NotImplementedError: Writer implementation must override '_write_node_data'
35
36
  NotImplementedError: Writer implementation must override '_write_edge_data'
36
37
  NotImplementedError: Writer implementation must override '_construct_import_call'
37
38
  NotImplementedError: Writer implementation must override '_get_import_script_name'
39
+
38
40
  """
39
41
 
40
42
  def __init__(
41
43
  self,
42
44
  translator: Translator,
43
45
  deduplicator: Deduplicator,
44
- output_directory: Optional[str] = None,
46
+ output_directory: str | None = None,
45
47
  strict_mode: bool = False,
46
48
  *args,
47
49
  **kwargs,
@@ -49,13 +51,14 @@ class _Writer(ABC):
49
51
  """Abstract class for writing node and edge representations to disk.
50
52
 
51
53
  Args:
54
+ ----
52
55
  translator (Translator): Instance of :py:class:`Translator` to enable translation of
53
56
  nodes and manipulation of properties.
54
57
  deduplicator (Deduplicator): Instance of :py:class:`Deduplicator` to enable deduplication
55
58
  of nodes and edges.
56
59
  output_directory (str, optional): Path for exporting CSV files. Defaults to None.
57
60
  strict_mode (bool, optional): Whether to enforce source, version, and license properties. Defaults to False.
58
- strict_mode (bool, optional): Whether to enforce source, version, and license properties. Defaults to False.
61
+
59
62
  """
60
63
  self.translator = translator
61
64
  self.deduplicator = deduplicator
@@ -66,7 +69,7 @@ class _Writer(ABC):
66
69
  if kwargs.get("write_to_file", True):
67
70
  logger.warning(
68
71
  f"Output directory `{self.output_directory}` already exists. "
69
- "If this is not planned, file consistency may be compromised."
72
+ "If this is not planned, file consistency may be compromised.",
70
73
  )
71
74
  else:
72
75
  logger.info(f"Creating output directory `{self.output_directory}`.")
@@ -75,73 +78,69 @@ class _Writer(ABC):
75
78
  @abstractmethod
76
79
  def _write_node_data(
77
80
  self,
78
- nodes: Iterable[
79
- Union[BioCypherNode, BioCypherEdge, BioCypherRelAsNode]
80
- ],
81
+ nodes: Iterable[BioCypherNode | BioCypherEdge | BioCypherRelAsNode],
81
82
  ) -> bool:
82
83
  """Implement how to output.write nodes to disk.
83
84
 
84
85
  Args:
86
+ ----
85
87
  nodes (Iterable): An iterable of BioCypherNode / BioCypherEdge / BioCypherRelAsNode objects.
86
88
 
87
89
  Returns:
90
+ -------
88
91
  bool: The return value. True for success, False otherwise.
92
+
89
93
  """
90
- raise NotImplementedError(
91
- "Writer implementation must override 'write_nodes'"
92
- )
94
+ raise NotImplementedError("Writer implementation must override 'write_nodes'")
93
95
 
94
96
  @abstractmethod
95
97
  def _write_edge_data(
96
98
  self,
97
- edges: Iterable[
98
- Union[BioCypherNode, BioCypherEdge, BioCypherRelAsNode]
99
- ],
99
+ edges: Iterable[BioCypherNode | BioCypherEdge | BioCypherRelAsNode],
100
100
  ) -> bool:
101
101
  """Implement how to output.write edges to disk.
102
102
 
103
103
  Args:
104
+ ----
104
105
  edges (Iterable): An iterable of BioCypherNode / BioCypherEdge / BioCypherRelAsNode objects.
105
106
 
106
107
  Returns:
108
+ -------
107
109
  bool: The return value. True for success, False otherwise.
110
+
108
111
  """
109
- raise NotImplementedError(
110
- "Writer implementation must override 'write_edges'"
111
- )
112
+ raise NotImplementedError("Writer implementation must override 'write_edges'")
112
113
 
113
114
  @abstractmethod
114
115
  def _construct_import_call(self) -> str:
115
- """
116
- Function to construct the import call detailing folder and
116
+ """Function to construct the import call detailing folder and
117
117
  individual node and edge headers and data files, as well as
118
118
  delimiters and database name. Built after all data has been
119
119
  processed to ensure that nodes are called before any edges.
120
120
 
121
- Returns:
121
+ Returns
122
+ -------
122
123
  str: command for importing the output files into a DBMS.
124
+
123
125
  """
124
- raise NotImplementedError(
125
- "Writer implementation must override '_construct_import_call'"
126
- )
126
+ raise NotImplementedError("Writer implementation must override '_construct_import_call'")
127
127
 
128
128
  @abstractmethod
129
129
  def _get_import_script_name(self) -> str:
130
130
  """Returns the name of the import script.
131
131
 
132
- Returns:
132
+ Returns
133
+ -------
133
134
  str: The name of the import script (ending in .sh)
135
+
134
136
  """
135
- raise NotImplementedError(
136
- "Writer implementation must override '_get_import_script_name'"
137
- )
137
+ raise NotImplementedError("Writer implementation must override '_get_import_script_name'")
138
138
 
139
- def write_nodes(
140
- self, nodes, batch_size: int = int(1e6), force: bool = False
141
- ):
139
+ def write_nodes(self, nodes, batch_size: int = int(1e6), force: bool = False):
142
140
  """Wrapper for writing nodes.
143
141
 
144
142
  Args:
143
+ ----
145
144
  nodes (BioCypherNode): a list or generator of nodes in
146
145
  :py:class:`BioCypherNode` format
147
146
  batch_size (int): The batch size for writing nodes.
@@ -149,7 +148,9 @@ class _Writer(ABC):
149
148
  not present in the schema.
150
149
 
151
150
  Returns:
151
+ -------
152
152
  bool: The return value. True for success, False otherwise.
153
+
153
154
  """
154
155
  passed = self._write_node_data(nodes)
155
156
  if not passed:
@@ -157,12 +158,11 @@ class _Writer(ABC):
157
158
  return False
158
159
  return True
159
160
 
160
- def write_edges(
161
- self, edges, batch_size: int = int(1e6), force: bool = False
162
- ):
161
+ def write_edges(self, edges, batch_size: int = int(1e6), force: bool = False):
163
162
  """Wrapper for writing edges.
164
163
 
165
164
  Args:
165
+ ----
166
166
  nodes (BioCypherNode): a list or generator of nodes in
167
167
  :py:class:`BioCypherNode` format
168
168
  batch_size (int): The batch size for writing nodes.
@@ -170,7 +170,9 @@ class _Writer(ABC):
170
170
  not present in the schema.
171
171
 
172
172
  Returns:
173
+ -------
173
174
  bool: The return value. True for success, False otherwise.
175
+
174
176
  """
175
177
  passed = self._write_edge_data(edges)
176
178
  if not passed:
@@ -179,20 +181,17 @@ class _Writer(ABC):
179
181
  return True
180
182
 
181
183
  def write_import_call(self):
182
- """
183
- Function to output.write the import call detailing folder and
184
+ """Function to output.write the import call detailing folder and
184
185
  individual node and edge headers and data files, as well as
185
186
  delimiters and database name, to the export folder as txt.
186
187
 
187
- Returns:
188
+ Returns
189
+ -------
188
190
  str: The path of the file holding the import call.
191
+
189
192
  """
190
- file_path = os.path.join(
191
- self.output_directory, self._get_import_script_name()
192
- )
193
- logger.info(
194
- f"Writing {self.__class__.__name__} import call to `{file_path}`."
195
- )
193
+ file_path = os.path.join(self.output_directory, self._get_import_script_name())
194
+ logger.info(f"Writing {self.__class__.__name__} import call to `{file_path}`.")
196
195
 
197
196
  with open(file_path, "w", encoding="utf-8") as f:
198
197
  f.write(self._construct_import_call())
@@ -61,9 +61,7 @@ class _ArangoDBBatchWriter(_Neo4jBatchWriter):
61
61
 
62
62
  # check if file already exists
63
63
  if os.path.exists(header_path):
64
- logger.warning(
65
- f"File {header_path} already exists. Overwriting."
66
- )
64
+ logger.warning(f"File {header_path} already exists. Overwriting.")
67
65
 
68
66
  # concatenate key:value in props
69
67
  props_list = []
@@ -81,9 +79,7 @@ class _ArangoDBBatchWriter(_Neo4jBatchWriter):
81
79
  f.write(row)
82
80
 
83
81
  # add collection from schema config
84
- collection = self.translator.ontology.mapping.extended_schema[
85
- label
86
- ].get("db_collection_name", None)
82
+ collection = self.translator.ontology.mapping.extended_schema[label].get("db_collection_name", None)
87
83
 
88
84
  # add file path to neo4 admin import statement
89
85
  # do once for each part file
@@ -91,8 +87,7 @@ class _ArangoDBBatchWriter(_Neo4jBatchWriter):
91
87
 
92
88
  if not parts:
93
89
  raise ValueError(
94
- f"No parts found for node label {label}. "
95
- f"Check that the data was parsed first.",
90
+ f"No parts found for node label {label}. " f"Check that the data was parsed first.",
96
91
  )
97
92
 
98
93
  for part in parts:
@@ -145,9 +140,7 @@ class _ArangoDBBatchWriter(_Neo4jBatchWriter):
145
140
 
146
141
  # check for file exists
147
142
  if os.path.exists(header_path):
148
- logger.warning(
149
- f"Header file {header_path} already exists. Overwriting."
150
- )
143
+ logger.warning(f"Header file {header_path} already exists. Overwriting.")
151
144
 
152
145
  # concatenate key:value in props
153
146
  props_list = []
@@ -172,9 +165,7 @@ class _ArangoDBBatchWriter(_Neo4jBatchWriter):
172
165
  break
173
166
 
174
167
  else:
175
- collection = self.translator.ontology.mapping.extended_schema[
176
- label
177
- ].get("db_collection_name", None)
168
+ collection = self.translator.ontology.mapping.extended_schema[label].get("db_collection_name", None)
178
169
 
179
170
  # add file path to neo4 admin import statement (import call path
180
171
  # may be different from actual output path)
@@ -206,11 +197,7 @@ class _ArangoDBBatchWriter(_Neo4jBatchWriter):
206
197
  Returns:
207
198
  str: a bash command for neo4j-admin import
208
199
  """
209
- import_call = (
210
- f"{self.import_call_bin_prefix}arangoimp "
211
- f"--type csv "
212
- f'--separator="{self.escaped_delim}" '
213
- )
200
+ import_call = f"{self.import_call_bin_prefix}arangoimp " f"--type csv " f'--separator="{self.escaped_delim}" '
214
201
 
215
202
  if self.quote == "'":
216
203
  import_call += f'--quote="{self.quote}" '
@@ -221,11 +208,7 @@ class _ArangoDBBatchWriter(_Neo4jBatchWriter):
221
208
 
222
209
  # node import calls: one line per node type
223
210
  for header_path, parts_path, collection in self.import_call_nodes:
224
- line = (
225
- f"{import_call} "
226
- f"--headers-file {header_path} "
227
- f"--file= {parts_path} "
228
- )
211
+ line = f"{import_call} --headers-file {header_path} --file= {parts_path} "
229
212
 
230
213
  if collection:
231
214
  line += f"--create-collection --collection {collection} "
@@ -1,12 +1,11 @@
1
1
  import os
2
2
 
3
3
  from biocypher._logger import logger
4
- from biocypher.output.write._batch_writer import parse_label, _BatchWriter
4
+ from biocypher.output.write._batch_writer import _BatchWriter, parse_label
5
5
 
6
6
 
7
7
  class _Neo4jBatchWriter(_BatchWriter):
8
- """
9
- Class for writing node and edge representations to disk using the
8
+ """Class for writing node and edge representations to disk using the
10
9
  format specified by Neo4j for the use of admin import. Each batch
11
10
  writer instance has a fixed representation that needs to be passed
12
11
  at instantiation via the :py:attr:`schema` argument. The instance
@@ -23,26 +22,26 @@ class _Neo4jBatchWriter(_BatchWriter):
23
22
  """
24
23
 
25
24
  def __init__(self, *args, **kwargs):
26
- """
27
- Constructor.
25
+ """Constructor.
28
26
 
29
27
  Check the version of Neo4j and adds a command scope if version >= 5.
30
28
 
31
- Returns:
29
+ Returns
30
+ -------
32
31
  _Neo4jBatchWriter: An instance of the writer.
33
- """
34
32
 
33
+ """
35
34
  # Should read the configuration and setup import_call_bin_prefix.
36
35
  super().__init__(*args, **kwargs)
37
36
 
38
37
  def _get_default_import_call_bin_prefix(self):
39
- """
40
- Method to provide the default string for the import call bin prefix.
38
+ """Method to provide the default string for the import call bin prefix.
41
39
 
42
- Returns:
40
+ Returns
41
+ -------
43
42
  str: The default location for the neo4j admin import location
44
- """
45
43
 
44
+ """
46
45
  return "bin/"
47
46
 
48
47
  def _quote_string(self, value: str) -> str:
@@ -53,27 +52,30 @@ class _Neo4jBatchWriter(_BatchWriter):
53
52
  return f"{self.quote}{value.replace(self.quote, self.quote * 2)}{self.quote}"
54
53
 
55
54
  def _write_array_string(self, string_list):
56
- """
57
- Abstract method to output.write the string representation of an array into a .csv file
55
+ """Abstract method to output.write the string representation of an array into a .csv file
58
56
  as required by the neo4j admin-import.
59
57
 
60
58
  Args:
59
+ ----
61
60
  string_list (list): list of ontology strings
62
61
 
63
62
  Returns:
63
+ -------
64
64
  str: The string representation of an array for the neo4j admin import
65
+
65
66
  """
66
67
  string = self.adelim.join(string_list)
67
68
  return self._quote_string(string)
68
69
 
69
70
  def _write_node_headers(self):
70
- """
71
- Writes single CSV file for a graph entity that is represented
71
+ """Writes single CSV file for a graph entity that is represented
72
72
  as a node as per the definition in the `schema_config.yaml`,
73
73
  containing only the header for this type of node.
74
74
 
75
- Returns:
75
+ Returns
76
+ -------
76
77
  bool: The return value. True for success, False otherwise.
78
+
77
79
  """
78
80
  # load headers from data parse
79
81
  if not self.node_property_dict:
@@ -86,9 +88,7 @@ class _Neo4jBatchWriter(_BatchWriter):
86
88
  _id = ":ID"
87
89
 
88
90
  # translate label to PascalCase
89
- pascal_label = self.translator.name_sentence_to_pascal(
90
- parse_label(label)
91
- )
91
+ pascal_label = self.translator.name_sentence_to_pascal(parse_label(label))
92
92
 
93
93
  header = f"{pascal_label}-header.csv"
94
94
  header_path = os.path.join(
@@ -143,20 +143,19 @@ class _Neo4jBatchWriter(_BatchWriter):
143
143
  self.import_call_file_prefix,
144
144
  parts,
145
145
  )
146
- self.import_call_nodes.add(
147
- (import_call_header_path, import_call_parts_path)
148
- )
146
+ self.import_call_nodes.add((import_call_header_path, import_call_parts_path))
149
147
 
150
148
  return True
151
149
 
152
150
  def _write_edge_headers(self):
153
- """
154
- Writes single CSV file for a graph entity that is represented
151
+ """Writes single CSV file for a graph entity that is represented
155
152
  as an edge as per the definition in the `schema_config.yaml`,
156
153
  containing only the header for this type of edge.
157
154
 
158
- Returns:
155
+ Returns
156
+ -------
159
157
  bool: The return value. True for success, False otherwise.
158
+
160
159
  """
161
160
  # load headers from data parse
162
161
  if not self.edge_property_dict:
@@ -167,9 +166,7 @@ class _Neo4jBatchWriter(_BatchWriter):
167
166
 
168
167
  for label, props in self.edge_property_dict.items():
169
168
  # translate label to PascalCase
170
- pascal_label = self.translator.name_sentence_to_pascal(
171
- parse_label(label)
172
- )
169
+ pascal_label = self.translator.name_sentence_to_pascal(parse_label(label))
173
170
 
174
171
  # paths
175
172
  header = f"{pascal_label}-header.csv"
@@ -181,9 +178,7 @@ class _Neo4jBatchWriter(_BatchWriter):
181
178
 
182
179
  # check for file exists
183
180
  if os.path.exists(header_path):
184
- logger.warning(
185
- f"File {header_path} already exists. Overwriting."
186
- )
181
+ logger.warning(f"File {header_path} already exists. Overwriting.")
187
182
 
188
183
  # concatenate key:value in props
189
184
  props_list = []
@@ -213,9 +208,7 @@ class _Neo4jBatchWriter(_BatchWriter):
213
208
 
214
209
  if label in ["IS_SOURCE_OF", "IS_TARGET_OF", "IS_PART_OF"]:
215
210
  skip_id = True
216
- elif not self.translator.ontology.mapping.extended_schema.get(
217
- label
218
- ):
211
+ elif not self.translator.ontology.mapping.extended_schema.get(label):
219
212
  # find label in schema by label_as_edge
220
213
  for (
221
214
  k,
@@ -231,10 +224,10 @@ class _Neo4jBatchWriter(_BatchWriter):
231
224
 
232
225
  if schema_label:
233
226
  if (
234
- self.translator.ontology.mapping.extended_schema.get(
235
- schema_label
227
+ self.translator.ontology.mapping.extended_schema.get( # (seems to not work with 'not')
228
+ schema_label,
236
229
  ).get("use_id")
237
- == False
230
+ == False # noqa: E712 (seems to not work with 'not')
238
231
  ):
239
232
  skip_id = True
240
233
 
@@ -259,54 +252,56 @@ class _Neo4jBatchWriter(_BatchWriter):
259
252
  self.import_call_file_prefix,
260
253
  parts,
261
254
  )
262
- self.import_call_edges.add(
263
- (import_call_header_path, import_call_parts_path)
264
- )
255
+ self.import_call_edges.add((import_call_header_path, import_call_parts_path))
265
256
 
266
257
  return True
267
258
 
268
259
  def _get_import_script_name(self) -> str:
269
- """
270
- Returns the name of the neo4j admin import script
260
+ """Returns the name of the neo4j admin import script
271
261
 
272
- Returns:
262
+ Returns
263
+ -------
273
264
  str: The name of the import script (ending in .sh)
265
+
274
266
  """
275
267
  return "neo4j-admin-import-call.sh"
276
268
 
277
269
  def _construct_import_call(self) -> str:
278
- """
279
- Function to construct the import call detailing folder and
270
+ """Function to construct the import call detailing folder and
280
271
  individual node and edge headers and data files, as well as
281
272
  delimiters and database name. Built after all data has been
282
273
  processed to ensure that nodes are called before any edges.
283
274
 
284
- Returns:
275
+ Returns
276
+ -------
285
277
  str: a bash command for neo4j-admin import
278
+
286
279
  """
287
- import_call_neo4j_v4 = self._get_import_call(
288
- "import", "--database=", "--force="
289
- )
290
- import_call_neo4j_v5 = self._get_import_call(
291
- "database import full", "", "--overwrite-destination="
280
+ import_call_neo4j_v4 = self._get_import_call("import", "--database=", "--force=")
281
+ import_call_neo4j_v5 = self._get_import_call("database import full", "", "--overwrite-destination=")
282
+ neo4j_version_check = (
283
+ f"version=$({self._get_default_import_call_bin_prefix()}neo4j-admin --version | cut -d '.' -f 1)"
292
284
  )
293
- neo4j_version_check = f"version=$({self._get_default_import_call_bin_prefix()}neo4j-admin --version | cut -d '.' -f 1)"
294
285
 
295
- import_script = f"#!/bin/bash\n{neo4j_version_check}\nif [[ $version -ge 5 ]]; then\n\t{import_call_neo4j_v5}\nelse\n\t{import_call_neo4j_v4}\nfi"
286
+ import_script = (
287
+ f"#!/bin/bash\n{neo4j_version_check}\nif [[ $version -ge 5 ]]; "
288
+ f"then\n\t{import_call_neo4j_v5}\nelse\n\t{import_call_neo4j_v4}\nfi"
289
+ )
296
290
  return import_script
297
291
 
298
- def _get_import_call(
299
- self, import_cmd: str, database_cmd: str, wipe_cmd: str
300
- ) -> str:
292
+ def _get_import_call(self, import_cmd: str, database_cmd: str, wipe_cmd: str) -> str:
301
293
  """Get parametrized import call for Neo4j 4 or 5+.
302
294
 
303
295
  Args:
296
+ ----
304
297
  import_cmd (str): The import command to use.
305
298
  database_cmd (str): The database command to use.
306
299
  wipe_cmd (str): The wipe command to use.
307
300
 
308
301
  Returns:
302
+ -------
309
303
  str: The import call.
304
+
310
305
  """
311
306
  import_call = f"{self.import_call_bin_prefix}neo4j-admin {import_cmd} "
312
307