refscan 0.0.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.
@@ -0,0 +1,382 @@
1
+ Metadata-Version: 2.3
2
+ Name: refscan
3
+ Version: 0.0.0
4
+ Summary: Command-line program that scans the NMDC MongoDB database for referential integrity violations
5
+ Keywords: mongodb,mongo,relationships,reference,database,data,referential integrity,scan
6
+ Requires-Python: >=3.9,<4.0
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.9
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Requires-Dist: linkml-runtime (>=1.7.5,<2.0.0)
14
+ Requires-Dist: pymongo (>=4.7.1,<5.0.0)
15
+ Requires-Dist: rich (>=13.7.1,<14.0.0)
16
+ Requires-Dist: typer (>=0.15.1,<0.16.0)
17
+ Project-URL: Documentation, https://github.com/microbiomedata/refscan
18
+ Project-URL: Homepage, https://github.com/microbiomedata/refscan
19
+ Project-URL: Repository, https://github.com/microbiomedata/refscan
20
+ Description-Content-Type: text/markdown
21
+
22
+ # refscan
23
+
24
+ `refscan` is a command-line tool people can use to **scan** the [NMDC](https://microbiomedata.org/) MongoDB database
25
+ for referential integrity violations.
26
+
27
+ ```mermaid
28
+ %% This is the source code of a Mermaid diagram, which GitHub will render as a diagram.
29
+ %% Note: PyPI does not render Mermaid diagrams, and instead displays their source code.
30
+ %% Reference: https://github.com/pypi/warehouse/issues/13083
31
+ graph LR
32
+ schema[LinkML<br>schema]
33
+ database[(MongoDB<br>database)]
34
+ script[["refscan"]]
35
+ violations["List of<br>violations"]
36
+ references["List of<br>references"]:::dashed_border
37
+ schema --> script
38
+ database --> script
39
+ script -.-> references
40
+ script --> violations
41
+
42
+ classDef dashed_border stroke-dasharray: 5 5
43
+ ```
44
+
45
+ In addition to using refscan to scan the NMDC MongoDB database for referential integrity violations,
46
+ people can use `refscan` to generate **graphs** (diagrams) depicting which collections' documents (or which classes'
47
+ instances) can contain references to which _other_ collections' documents (or classes' instances) while still being
48
+ schema compliant.
49
+
50
+ <!-- Note: We removed the hard-coded Table of Contents because—nowadays—GitHub automatically derives/presents one. -->
51
+
52
+ ## How it works
53
+
54
+ Here is a summary of how each of `refscan`'s main functions works under the hood.
55
+
56
+ ### Scan
57
+
58
+ `refscan` does this in two stages:
59
+ 1. It uses the LinkML schema to determine where references _can_ exist in a MongoDB database that conforms to the schema.
60
+ > **Example:** The schema might say that, if a document in the `biosample_set` collection has a field named
61
+ > `associated_studies`, that field must contain a list of `id`s of documents in the `study_set` collection.
62
+ 2. It scans the MongoDB database to check the integrity of all the references that _do_ exist.
63
+ > **Example:** For each document in the `biosample_set` collection that _has_ a field named `associated_studies`,
64
+ > for each value in that field, confirm there _is_ a document having that `id` in the `study_set` collection.
65
+
66
+ ### Graph
67
+
68
+ `refscan` does this in three stages:
69
+ 1. It uses the LinkML schema to determine where references _can_ exist in a MongoDB database that conforms to the schema.
70
+ 2. It formats that list of references into a data structure compatible with [`Cytoscape.js`](https://js.cytoscape.org/).
71
+ 3. It outputs an HTML document that uses `Cytoscape.js` to visualize that data structure as a graph.
72
+
73
+ ## Assumptions
74
+
75
+ `refscan` was designed under the assumption that **every document** in **every collection described by the schema** has
76
+ a **field named `type`**, whose value is the [class_uri](https://linkml.io/linkml/code/metamodel.html#linkml_runtime.linkml_model.meta.ClassDefinition.class_uri) of the schema class the document represents an instance
77
+ of. `refscan` uses that `class_uri` value (in that `type` field) to determine the _name_ of that schema class,
78
+ whose definition `refscan` then uses to determine _which fields_ of that document can contain references.
79
+
80
+ ## Usage
81
+
82
+ ### Install
83
+
84
+ Assuming you have `pipx` installed, you can install the tool by running the following command:
85
+
86
+ ```shell
87
+ pipx install refscan
88
+ ```
89
+
90
+ > [`pipx`](https://pipx.pypa.io/stable/) is a tool people can use to
91
+ > [download and install](https://pipx.pypa.io/stable/#where-does-pipx-install-apps-from)
92
+ > Python scripts that are hosted on PyPI.
93
+ > You can [install `pipx`](https://pipx.pypa.io/stable/installation/) by running `$ python -m pip install pipx`.
94
+
95
+ ### Run
96
+
97
+ Once installed, you can display the tool's `--help` snippet by running:
98
+
99
+ ```shell
100
+ refscan --help
101
+ ```
102
+
103
+ At the time of this writing, the tool's `--help` snippet is:
104
+
105
+ ```console
106
+ Usage: refscan [OPTIONS] COMMAND [ARGS]...
107
+
108
+ ╭─ Options ──────────────────────────────────────────────────────────────────────────────╮
109
+ │ --help Show this message and exit. │
110
+ ╰────────────────────────────────────────────────────────────────────────────────────────╯
111
+ ╭─ Commands ─────────────────────────────────────────────────────────────────────────────╮
112
+ │ version Show version number and exit. │
113
+ │ scan Scan the NMDC MongoDB database for referential integrity violations. │
114
+ │ graph Generate an interactive graph of the references described by a schema. │
115
+ ╰────────────────────────────────────────────────────────────────────────────────────────╯
116
+ ```
117
+
118
+ <!-- Note: The above snippet was captured from a terminal window whose width was 90 characters. -->
119
+
120
+ Each command has its own `--help` snippet.
121
+
122
+ #### The `scan` command
123
+
124
+ At the time of this writing, the `--help` snippet for the `scan` command is:
125
+
126
+ ```console
127
+ Usage: refscan scan [OPTIONS]
128
+
129
+ Scan the NMDC MongoDB database for referential integrity violations.
130
+
131
+ ╭─ Options ──────────────────────────────────────────────────────────────────────────────╮
132
+ │ * --schema FILE Filesystem path at which the YAML file │
133
+ │ representing the schema is located. │
134
+ │ [default: None] │
135
+ │ [required] │
136
+ │ --database-name TEXT Name of the database. │
137
+ │ [default: nmdc] │
138
+ │ --mongo-uri TEXT Connection string for accessing the │
139
+ │ MongoDB server. If you have Docker │
140
+ │ installed, you can spin up a temporary │
141
+ │ MongoDB server at the default URI by │
142
+ │ running: $ docker run --rm --detach -p │
143
+ │ 27017:27017 mongo │
144
+ │ [env var: MONGO_URI] │
145
+ │ [default: mongodb://localhost:27017] │
146
+ │ --verbose Show verbose output. │
147
+ │ --skip-source-collection,--skip TEXT Name of collection you do not want to │
148
+ │ search for referring documents. Option │
149
+ │ can be used multiple times. │
150
+ │ [default: None] │
151
+ │ --reference-report FILE Filesystem path at which you want the │
152
+ │ program to generate its reference │
153
+ │ report. │
154
+ │ [default: references.tsv] │
155
+ │ --violation-report FILE Filesystem path at which you want the │
156
+ │ program to generate its violation │
157
+ │ report. │
158
+ │ [default: violations.tsv] │
159
+ │ --no-scan Generate a reference report, but do │
160
+ │ not scan the database for violations. │
161
+ │ --locate-misplaced-documents For each referenced document not found │
162
+ │ in any of the collections the schema │
163
+ │ allows, also search for it in all │
164
+ │ other collections. │
165
+ │ --help Show this message and exit. │
166
+ ╰────────────────────────────────────────────────────────────────────────────────────────╯
167
+ ```
168
+
169
+ <!-- Note: The above snippet was captured from a terminal window whose width was 90 characters. -->
170
+
171
+ ##### The MongoDB connection string (`--mongo-uri`)
172
+
173
+ As documented in the `--help` snippet above, you can provide the MongoDB connection string to the tool via either
174
+ (a) the `--mongo-uri` option; or (b) an environment variable named `MONGO_URI`. The latter can come in handy
175
+ when the MongoDB connection string contains information you don't want to appear in your shell history,
176
+ such as a password.
177
+
178
+ Here's how you could create that environment variable:
179
+
180
+ ```shell
181
+ export MONGO_URI='mongodb://username:password@localhost:27017'
182
+ ```
183
+
184
+ ##### The schema (`--schema`)
185
+
186
+ As documented in the `--help` snippet above, you can provide the path to a YAML-formatted LinkML schema file to the tool
187
+ via the `--schema` option.
188
+
189
+ <details>
190
+
191
+ <summary>
192
+ Show/hide tips for getting a schema file
193
+ </summary>
194
+
195
+ ---
196
+
197
+ If you have `curl` installed, you can download a YAML file from GitHub by running the following command (after replacing
198
+ the `{...}` placeholders and customizing the path):
199
+
200
+ ```shell
201
+ # Download the raw content of https://github.com/{user_or_org}/{repo}/blob/{branch}/path/to/schema.yaml
202
+ curl -o schema.yaml https://raw.githubusercontent.com/{user_or_org}/{repo}/{branch}/path/to/schema.yaml
203
+ ```
204
+
205
+ For example:
206
+
207
+ ```shell
208
+ # Download the raw content of https://github.com/microbiomedata/nmdc-schema/blob/main/nmdc_schema/nmdc_materialized_patterns.yaml
209
+ curl -o schema.yaml https://raw.githubusercontent.com/microbiomedata/nmdc-schema/main/nmdc_schema/nmdc_materialized_patterns.yaml
210
+
211
+ # Download the raw content of https://github.com/microbiomedata/nmdc-schema/blob/v11.2.1/nmdc_schema/nmdc_materialized_patterns.yaml
212
+ curl -o schema.yaml https://raw.githubusercontent.com/microbiomedata/nmdc-schema/v11.2.1/nmdc_schema/nmdc_materialized_patterns.yaml
213
+ ```
214
+
215
+ ---
216
+ </details>
217
+
218
+ ##### Output
219
+
220
+ While `refscan` is running, it will display console output indicating what it's currently doing.
221
+
222
+ ![Screenshot of refscan console output](./docs/refscan-screenshot.png)
223
+
224
+ Once the scan is complete, the reference report (TSV file) and violation report (TSV file) will be available
225
+ in the current directory (or in custom directories, if any were specified via CLI options).
226
+
227
+ #### The `graph` command
228
+
229
+ At the time of this writing, the `--help` snippet for the `graph` command is:
230
+
231
+ ```console
232
+ Usage: refscan graph [OPTIONS]
233
+
234
+ Generate an interactive graph of the references described by a schema.
235
+
236
+ ╭─ Options ──────────────────────────────────────────────────────────────────────────────╮
237
+ │ * --schema FILE Filesystem path at which the YAML file │
238
+ │ representing the schema is located. │
239
+ │ [default: None] │
240
+ │ [required] │
241
+ │ --graph FILE Filesystem path at which you want refscan to │
242
+ │ generate the graph. │
243
+ │ [default: graph.html] │
244
+ │ --subject [collection|class] Whether you want each node of the graph to │
245
+ │ represent a collection or a class. │
246
+ │ [default: collection] │
247
+ │ --verbose Show verbose output. │
248
+ │ --help Show this message and exit. │
249
+ ╰────────────────────────────────────────────────────────────────────────────────────────╯
250
+ ```
251
+
252
+ <!-- Note: The above snippet was captured from a terminal window whose width was 90 characters. -->
253
+
254
+ ### Update
255
+
256
+ You can update the tool to [the latest version available on PyPI](https://pypi.org/project/refscan/) by running:
257
+
258
+ ```shell
259
+ pipx upgrade refscan
260
+ ```
261
+
262
+ ### Uninstall
263
+
264
+ You can uninstall the tool from your computer by running:
265
+
266
+ ```shell
267
+ pipx uninstall refscan
268
+ ```
269
+
270
+ ## Development
271
+
272
+ We use [Poetry](https://python-poetry.org/) to both (a) manage dependencies and (b) build distributable packages that can be published to PyPI.
273
+
274
+ - `pyproject.toml`: Configuration file for Poetry and other tools (was initialized via `$ poetry init`)
275
+ - `poetry.lock`: List of dependencies, both direct and [indirect/transitive](https://en.wikipedia.org/wiki/Transitive_dependency)
276
+
277
+ ### Clone repository
278
+
279
+ ```shell
280
+ git clone https://github.com/microbiomedata/refscan.git
281
+ cd refscan
282
+ ```
283
+
284
+ ### Create virtual environment
285
+
286
+ Create a Poetry virtual environment and attach to its shell:
287
+
288
+ ```shell
289
+ poetry shell
290
+ ```
291
+
292
+ > You can see information about the Poetry virtual environment by running: `$ poetry env info`
293
+
294
+ > You can detach from the Poetry virtual environment's shell by running: `$ exit`
295
+
296
+ From now on, I'll refer to the Poetry virtual environment's shell as the "Poetry shell."
297
+
298
+ ### Install dependencies
299
+
300
+ At the Poetry shell, install the project's dependencies:
301
+
302
+ ```shell
303
+ poetry install
304
+ ```
305
+
306
+ ### Make changes
307
+
308
+ Edit the tool's source code and documentation however you want.
309
+
310
+ While editing the tool's source code, you can run the tool as you normally would in order to test things out.
311
+
312
+ ```shell
313
+ poetry run refscan --help
314
+ ```
315
+
316
+ ### Check types
317
+
318
+ We use [mypy](https://mypy.readthedocs.io/en/stable/) as the static type checker for `refscan`.
319
+
320
+ You can perform static type checking by running the following command from the root directory of the repository:
321
+
322
+ ```shell
323
+ poetry run mypy
324
+ ```
325
+
326
+ ### Run tests
327
+
328
+ We use [pytest](https://docs.pytest.org/en/8.2.x/) as the testing framework for `refscan`.
329
+
330
+ Tests are defined in the `tests` directory.
331
+
332
+ You can run the tests by running the following command from the root directory of the repository:
333
+
334
+ ```shell
335
+ poetry run pytest
336
+ ```
337
+
338
+ ### Format code
339
+
340
+ We use [`black`](https://black.readthedocs.io/en/stable/) as the code formatter for `refscan`.
341
+
342
+ We do not use it with its default options. Instead, we include an option that allows lines to be 120 characters
343
+ instead of the default 88 characters. That option is defined in the `[tool.black]` section of `pyproject.toml`.
344
+
345
+ You can format all the Python code in the repository by running this command
346
+ from the root directory of the repository:
347
+
348
+ ```shell
349
+ poetry run black .
350
+ ```
351
+
352
+ #### Check format
353
+
354
+ You can _check_ the format of the Python code by including the `--check` option, like this:
355
+
356
+ ```shell
357
+ poetry run black --check .
358
+ ```
359
+
360
+ ## Building and publishing
361
+
362
+ ### Build for production
363
+
364
+ Whenever someone publishes a [GitHub Release](https://github.com/microbiomedata/refscan/releases) in this repository,
365
+ a [GitHub Actions workflow](.github/workflows/build-and-publish-package-to-pypi.yml)
366
+ will automatically build a package and publish it to [PyPI](https://pypi.org/project/refscan/).
367
+ That package will have a version identifier that matches the name of the Git tag associated with the Release.
368
+
369
+ ### Test the build process locally
370
+
371
+ In case you want to test the build process locally, you can do so by running:
372
+
373
+ ```shell
374
+ poetry build
375
+ ```
376
+
377
+ > That will create both a
378
+ > [source distribution](https://setuptools.pypa.io/en/latest/deprecated/distutils/sourcedist.html#creating-a-source-distribution)
379
+ > file (whose name ends with `.tar.gz`) and a
380
+ > [wheel](https://packaging.python.org/en/latest/specifications/binary-distribution-format/#binary-distribution-format)
381
+ > file (whose name ends with `.whl`) in the `dist` directory.
382
+
@@ -0,0 +1,20 @@
1
+ refscan/__init__.py,sha256=_5OC4h-yDX6r34HKWemKmS8NaIJwWXlMJPAtkExu9Mo,564
2
+ refscan/cli/cli.py,sha256=lovGQCelI5i30bDE4kEhgITGtQ56xVRQTJC_J9G3Uhk,1131
3
+ refscan/cli/graph.py,sha256=CfopyDwzYAQ7I82Afw-dz0KUNo-L_2E8uS_88O4SwEU,2247
4
+ refscan/cli/scan.py,sha256=xbU5zfAQKeIn5lJmP45sbqv_Yn4RRRFzDuXnuZE_L7I,7961
5
+ refscan/cli/version.py,sha256=iZ-3kRYUQqGSmw5_MMP8TWmih6MSh_eRXwm5jSAMQx8,294
6
+ refscan/grapher.py,sha256=IyJCwhqSYEiU0-WQdppDrtFdnkbjrb_-a527An6pZyQ,7654
7
+ refscan/lib/Finder.py,sha256=amBWAL_ElIpBZPBrthLD1G0hSmSR_eT-eH-luuPa5f4,13080
8
+ refscan/lib/Reference.py,sha256=PzgKCQz9eahX1rqLJCcMPXG6_O0Po89Su1gNl0PZoGA,1605
9
+ refscan/lib/ReferenceList.py,sha256=ryHsZzUzqKP6Y6FiCwoGoEtM9qHSUMP1xykqyxixaLE,9319
10
+ refscan/lib/Violation.py,sha256=kFcSRXRvDNDaK66TQbTv6u947ZJdLF-hrUpedxa-sqc,929
11
+ refscan/lib/ViolationList.py,sha256=JpAjFmY1NNYrXP16Z2RtvjNYA7nXrkCV4_J26Qt4gss,1018
12
+ refscan/lib/constants.py,sha256=btLeV-j7370aM8kPRonxQlDz0bDk6eAFar63wCz7bsk,279
13
+ refscan/lib/helpers.py,sha256=i5VXwiSHMFz5NVXmtIuE9u34x78BjmmmJ_AniCzL2bo,11854
14
+ refscan/scanner.py,sha256=58Z4iRMCBKi36sRa-VChUk5UJghFyBlRRtc7MrvM2f0,19832
15
+ refscan/templates/graph.template.html,sha256=I-_7lHp5eiD6fljDJvCrSfRcSiPrUpLBi--MWBJ-PBY,11844
16
+ refscan-0.0.0.dist-info/LICENSE,sha256=mrHOSdpKCU7N5M0-r40n8-gQGdO3zuY9dgOkKWZfXWk,2403
17
+ refscan-0.0.0.dist-info/METADATA,sha256=3NaxbNrl4ZICNnLy9xxYewvPUn8ooSWkhzUfyaW0L1w,18189
18
+ refscan-0.0.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
19
+ refscan-0.0.0.dist-info/entry_points.txt,sha256=H9qBkaDbcpTPyvG4Gu1xuwK77i9uIswGye4R70ZfC30,47
20
+ refscan-0.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.1.3
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ refscan=refscan.cli.cli:app
3
+