fairspec-terminal 0.0.0.dev0__tar.gz
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.
- fairspec_terminal-0.0.0.dev0/.gitignore +229 -0
- fairspec_terminal-0.0.0.dev0/PKG-INFO +20 -0
- fairspec_terminal-0.0.0.dev0/README.md +3 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/__init__.py +0 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/actions/__init__.py +0 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/actions/error/__init__.py +0 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/actions/error/render.py +191 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/__init__.py +0 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/data/__init__.py +0 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/data/infer_schema.py +27 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/data/validate.py +32 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/data/validate_schema.py +24 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/dataset/__init__.py +0 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/dataset/copy.py +28 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/dataset/infer.py +62 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/dataset/list_.py +31 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/dataset/script.py +32 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/dataset/validate.py +23 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/file/__init__.py +0 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/file/copy.py +34 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/file/describe.py +31 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/file/validate.py +31 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/file_dialect/__init__.py +0 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/file_dialect/infer.py +49 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/table/__init__.py +0 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/table/describe.py +129 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/table/infer_schema.py +119 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/table/preview.py +129 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/table/query.py +139 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/table/render_schema.py +58 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/table/script.py +132 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/table/validate.py +140 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/commands/table/validate_schema.py +24 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/helpers/__init__.py +0 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/helpers/file.py +30 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/helpers/file_dialect.py +118 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/helpers/resource.py +46 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/main.py +6 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/params/__init__.py +55 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/params/data_schema.py +5 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/params/dataset.py +9 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/params/file.py +8 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/params/file_dialect.py +20 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/params/path.py +10 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/params/session.py +7 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/params/table.py +6 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/params/table_schema.py +22 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/program.py +39 -0
- fairspec_terminal-0.0.0.dev0/fairspec_terminal/session.py +157 -0
- fairspec_terminal-0.0.0.dev0/pyproject.toml +50 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
|
|
204
|
+
# Ruff stuff:
|
|
205
|
+
.ruff_cache/
|
|
206
|
+
|
|
207
|
+
# PyPI configuration file
|
|
208
|
+
.pypirc
|
|
209
|
+
|
|
210
|
+
# Marimo
|
|
211
|
+
marimo/_static/
|
|
212
|
+
marimo/_lsp/
|
|
213
|
+
__marimo__/
|
|
214
|
+
|
|
215
|
+
# Streamlit
|
|
216
|
+
.streamlit/secrets.toml
|
|
217
|
+
|
|
218
|
+
# Node
|
|
219
|
+
node_modules/
|
|
220
|
+
jspm_packages/
|
|
221
|
+
.lock-wscript
|
|
222
|
+
build/Release
|
|
223
|
+
.node_repl_history
|
|
224
|
+
*.tgz
|
|
225
|
+
.npm
|
|
226
|
+
*.so
|
|
227
|
+
|
|
228
|
+
# User
|
|
229
|
+
/.claude/settings.local.json
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fairspec-terminal
|
|
3
|
+
Version: 0.0.0.dev0
|
|
4
|
+
Summary: Fairspec Python is a fast data management framework built on top of the Fairspec standard and Polars DataFrames
|
|
5
|
+
Project-URL: homepage, https://github.com/fairspec/fairspec-python
|
|
6
|
+
Project-URL: repository, https://github.com/fairspec/fairspec-python
|
|
7
|
+
Author: Evgeny Karev
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Keywords: arrow,csv,data,dataframe,fair,fairspec,inline,json,jsonschema,ods,parquet,polars,quality,table,tableschema,typescript,validation,xlsx
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
13
|
+
Requires-Python: >=3.12
|
|
14
|
+
Requires-Dist: fairspec-library
|
|
15
|
+
Requires-Dist: typer>=0.15
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# fairspec-terminal
|
|
19
|
+
|
|
20
|
+
Fairspec Python is a fast data management framework built on top of the Fairspec standard and Polars DataFrames. It supports various formats like CSV, JSON, and Parquet and integrates with data platforms such as CKAN, Zenodo, and GitHub. For more information, please read the [project's documentation](https://python.fairspec.org).
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# fairspec-terminal
|
|
2
|
+
|
|
3
|
+
Fairspec Python is a fast data management framework built on top of the Fairspec standard and Polars DataFrames. It supports various formats like CSV, JSON, and Parquet and integrates with data platforms such as CKAN, Zenodo, and GitHub. For more information, please read the [project's documentation](https://python.fairspec.org).
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from fairspec_metadata import FairspecError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def render_error(error: FairspecError) -> str:
|
|
10
|
+
match error.type:
|
|
11
|
+
case "cell/type":
|
|
12
|
+
return _render_cell_type_error(error)
|
|
13
|
+
case "cell/missing":
|
|
14
|
+
return _render_cell_missing_error(error)
|
|
15
|
+
case "cell/minimum":
|
|
16
|
+
return _render_cell_minimum_error(error)
|
|
17
|
+
case "cell/maximum":
|
|
18
|
+
return _render_cell_maximum_error(error)
|
|
19
|
+
case "cell/exclusiveMinimum":
|
|
20
|
+
return _render_cell_exclusive_minimum_error(error)
|
|
21
|
+
case "cell/exclusiveMaximum":
|
|
22
|
+
return _render_cell_exclusive_maximum_error(error)
|
|
23
|
+
case "cell/multipleOf":
|
|
24
|
+
return _render_cell_multiple_of_error(error)
|
|
25
|
+
case "cell/minLength":
|
|
26
|
+
return _render_cell_min_length_error(error)
|
|
27
|
+
case "cell/maxLength":
|
|
28
|
+
return _render_cell_max_length_error(error)
|
|
29
|
+
case "cell/pattern":
|
|
30
|
+
return _render_cell_pattern_error(error)
|
|
31
|
+
case "cell/unique":
|
|
32
|
+
return _render_cell_unique_error(error)
|
|
33
|
+
case "cell/const":
|
|
34
|
+
return _render_cell_const_error(error)
|
|
35
|
+
case "cell/enum":
|
|
36
|
+
return _render_cell_enum_error(error)
|
|
37
|
+
case "cell/json":
|
|
38
|
+
return _render_cell_json_error(error)
|
|
39
|
+
case "cell/minItems":
|
|
40
|
+
return _render_cell_min_items_error(error)
|
|
41
|
+
case "cell/maxItems":
|
|
42
|
+
return _render_cell_max_items_error(error)
|
|
43
|
+
case "column/missing":
|
|
44
|
+
return _render_column_missing_error(error)
|
|
45
|
+
case "column/type":
|
|
46
|
+
return _render_column_type_error(error)
|
|
47
|
+
case "data":
|
|
48
|
+
return _render_data_error(error)
|
|
49
|
+
case "file/textual":
|
|
50
|
+
return _render_textual_error(error)
|
|
51
|
+
case "file/integrity":
|
|
52
|
+
return _render_integrity_error(error)
|
|
53
|
+
case "foreignKey":
|
|
54
|
+
return _render_foreign_key_error(error)
|
|
55
|
+
case "metadata":
|
|
56
|
+
return _render_metadata_error(error)
|
|
57
|
+
case "row/primaryKey":
|
|
58
|
+
return _render_row_primary_key_error(error)
|
|
59
|
+
case "row/uniqueKey":
|
|
60
|
+
return _render_row_unique_key_error(error)
|
|
61
|
+
case "resource/missing":
|
|
62
|
+
return _render_resource_missing_error(error)
|
|
63
|
+
case "resource/type":
|
|
64
|
+
return _render_resource_type_error(error)
|
|
65
|
+
case _:
|
|
66
|
+
return str(error)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _b(value: object) -> str:
|
|
70
|
+
return f"[bold]{value}[/bold]"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _in_resource(resource_name: str | None) -> str:
|
|
74
|
+
return f" in resource {_b(resource_name)}" if resource_name else ""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _render_cell_type_error(error: object) -> str:
|
|
78
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is not {_b(error.columnType)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _render_cell_missing_error(error: object) -> str:
|
|
82
|
+
return f"A cell in column {_b(error.columnName)} of row {_b(error.rowNumber)} is missing{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _render_cell_minimum_error(error: object) -> str:
|
|
86
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is less than {_b(error.minimum)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _render_cell_maximum_error(error: object) -> str:
|
|
90
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is more than {_b(error.maximum)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _render_cell_exclusive_minimum_error(error: object) -> str:
|
|
94
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is less or equal to {_b(error.minimum)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _render_cell_exclusive_maximum_error(error: object) -> str:
|
|
98
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is greater or equal to {_b(error.maximum)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _render_cell_multiple_of_error(error: object) -> str:
|
|
102
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is not a multiple of {_b(error.multipleOf)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _render_cell_min_length_error(error: object) -> str:
|
|
106
|
+
return f"Length of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is less than {_b(error.minLength)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _render_cell_max_length_error(error: object) -> str:
|
|
110
|
+
return f"Length of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is more than {_b(error.maxLength)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _render_cell_pattern_error(error: object) -> str:
|
|
114
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} does not match the {_b(error.pattern)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _render_cell_unique_error(error: object) -> str:
|
|
118
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is not unique{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _render_cell_const_error(error: object) -> str:
|
|
122
|
+
const_val = getattr(error, "const", None)
|
|
123
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is not allowed value {_b(const_val)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _render_cell_enum_error(error: object) -> str:
|
|
127
|
+
enum_values = ", ".join(_b(v) for v in error.enum) # type: ignore[union-attr]
|
|
128
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} is not in the allowed values {enum_values}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _render_cell_json_error(error: object) -> str:
|
|
132
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} violates JSON schema at {_b(error.jsonPointer)}: {error.message}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _render_cell_min_items_error(error: object) -> str:
|
|
136
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} has less than {_b(error.minItems)} items{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _render_cell_max_items_error(error: object) -> str:
|
|
140
|
+
return f"Value of the cell {_b(error.cell)} in column {_b(error.columnName)} of row {_b(error.rowNumber)} has more than {_b(error.maxItems)} items{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _render_column_missing_error(error: object) -> str:
|
|
144
|
+
return f"Required column {_b(error.columnName)} is missing{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _render_column_type_error(error: object) -> str:
|
|
148
|
+
return f"Column {_b(error.columnName)} is expected to be {_b(error.expectedColumnType)}, but it is {_b(error.actualColumnType)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _render_data_error(error: object) -> str:
|
|
152
|
+
return f"Data error at {_b(error.jsonPointer)}: {error.message}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _render_textual_error(error: object) -> str:
|
|
156
|
+
actual_encoding = getattr(error, "actualEncoding", None)
|
|
157
|
+
encoding_text = _b(actual_encoding) if actual_encoding else "binary"
|
|
158
|
+
return f"File is expected to be textual with utf-8 encoding but it is {encoding_text}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _render_integrity_error(error: object) -> str:
|
|
162
|
+
return f"File hash {_b(error.hashType)} is expected to be {_b(error.expectedHash)}, but it is {_b(error.actualHash)}){_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _render_foreign_key_error(error: object) -> str:
|
|
166
|
+
cells = ", ".join(_b(c) for c in error.cells) # type: ignore[union-attr]
|
|
167
|
+
return f"Foreign key constraint violated as cells {cells} do not reference existing values{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _render_metadata_error(error: object) -> str:
|
|
171
|
+
return f"{error.message} at {_b(error.jsonPointer)}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _render_row_primary_key_error(error: object) -> str:
|
|
175
|
+
column_names = ", ".join(_b(c) for c in error.columnNames) # type: ignore[union-attr]
|
|
176
|
+
return f"Row {_b(error.rowNumber)} violates primary key constraint on columns {column_names}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _render_row_unique_key_error(error: object) -> str:
|
|
180
|
+
column_names = ", ".join(_b(c) for c in error.columnNames) # type: ignore[union-attr]
|
|
181
|
+
return f"Row {_b(error.rowNumber)} violates unique key constraint on columns {column_names}{_in_resource(error.resourceName)}" # type: ignore[union-attr]
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _render_resource_missing_error(error: object) -> str:
|
|
185
|
+
in_ref = _in_resource(getattr(error, "referencingResourceName", None))
|
|
186
|
+
return f"Resource {_b(error.resourceName)} is missing, but expected{in_ref}" # type: ignore[union-attr]
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _render_resource_type_error(error: object) -> str:
|
|
190
|
+
in_ref = _in_resource(getattr(error, "referencingResourceName", None))
|
|
191
|
+
return f"Resource {_b(error.resourceName)} is expected to be {_b(error.expectedResourceType)}{in_ref}" # type: ignore[union-attr]
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from fairspec_library import infer_data_schema
|
|
2
|
+
from fairspec_metadata import Resource
|
|
3
|
+
|
|
4
|
+
from fairspec_terminal.params import Debug, Json, RequiredFilePath, Silent
|
|
5
|
+
from fairspec_terminal.program import data_program
|
|
6
|
+
from fairspec_terminal.session import Session
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@data_program.command(name="infer-schema")
|
|
10
|
+
def infer_schema(
|
|
11
|
+
path: RequiredFilePath,
|
|
12
|
+
silent: Silent = False,
|
|
13
|
+
debug: Debug = False,
|
|
14
|
+
json: Json = False,
|
|
15
|
+
) -> None:
|
|
16
|
+
"""Infer a Data Schema."""
|
|
17
|
+
session = Session(silent=silent, debug=debug, json=json)
|
|
18
|
+
|
|
19
|
+
def _infer() -> object:
|
|
20
|
+
data_schema = infer_data_schema(Resource(data=path))
|
|
21
|
+
if not data_schema:
|
|
22
|
+
raise ValueError("Could not infer data schema")
|
|
23
|
+
return data_schema
|
|
24
|
+
|
|
25
|
+
data_schema = session.task("Inferring data schema", _infer)
|
|
26
|
+
|
|
27
|
+
session.render_data_result(data_schema)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from fairspec_library import validate_data
|
|
2
|
+
from fairspec_metadata import Report, load_data_schema
|
|
3
|
+
|
|
4
|
+
from fairspec_terminal.params import DataSchemaPath, Debug, Json, RequiredFilePath, Silent
|
|
5
|
+
from fairspec_terminal.program import data_program
|
|
6
|
+
from fairspec_terminal.session import Session
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@data_program.command()
|
|
10
|
+
def validate(
|
|
11
|
+
path: RequiredFilePath,
|
|
12
|
+
schema: DataSchemaPath,
|
|
13
|
+
silent: Silent = False,
|
|
14
|
+
debug: Debug = False,
|
|
15
|
+
json: Json = False,
|
|
16
|
+
) -> None:
|
|
17
|
+
"""Validate a JSON Data from a local or remote path."""
|
|
18
|
+
session = Session(silent=silent, debug=debug, json=json)
|
|
19
|
+
|
|
20
|
+
def _load_schema() -> object:
|
|
21
|
+
if not schema:
|
|
22
|
+
raise ValueError("No data schema provided")
|
|
23
|
+
return load_data_schema(schema)
|
|
24
|
+
|
|
25
|
+
data_schema = session.task("Loading data schema", _load_schema)
|
|
26
|
+
|
|
27
|
+
def _validate() -> Report:
|
|
28
|
+
return validate_data({"data": path, "dataSchema": data_schema}) # type: ignore[arg-type]
|
|
29
|
+
|
|
30
|
+
report = session.task("Validating data", _validate)
|
|
31
|
+
|
|
32
|
+
session.render_report_result(report)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from fairspec_metadata import validate_data_schema
|
|
2
|
+
|
|
3
|
+
from fairspec_terminal.params import Debug, Json, RequiredFilePath, Silent
|
|
4
|
+
from fairspec_terminal.program import data_program
|
|
5
|
+
from fairspec_terminal.session import Session
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@data_program.command(name="validate-schema")
|
|
9
|
+
def validate_schema(
|
|
10
|
+
path: RequiredFilePath,
|
|
11
|
+
silent: Silent = False,
|
|
12
|
+
debug: Debug = False,
|
|
13
|
+
json: Json = False,
|
|
14
|
+
) -> None:
|
|
15
|
+
"""Validate a Data Schema."""
|
|
16
|
+
session = Session(silent=silent, debug=debug, json=json)
|
|
17
|
+
|
|
18
|
+
def _validate() -> object:
|
|
19
|
+
result = validate_data_schema(path)
|
|
20
|
+
return result
|
|
21
|
+
|
|
22
|
+
report = session.task("Validating data schema", _validate)
|
|
23
|
+
|
|
24
|
+
session.render_report_result(report) # type: ignore[arg-type]
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from fairspec_library import load_dataset, save_dataset
|
|
2
|
+
|
|
3
|
+
from fairspec_terminal.params import Debug, Json, RequiredPath, Silent, ToPathRequired
|
|
4
|
+
from fairspec_terminal.program import dataset_program
|
|
5
|
+
from fairspec_terminal.session import Session
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataset_program.command()
|
|
9
|
+
def copy(
|
|
10
|
+
path: RequiredPath,
|
|
11
|
+
to_path: ToPathRequired,
|
|
12
|
+
silent: Silent = False,
|
|
13
|
+
debug: Debug = False,
|
|
14
|
+
json: Json = False,
|
|
15
|
+
) -> None:
|
|
16
|
+
"""Copy a local or remote dataset to a local folder."""
|
|
17
|
+
session = Session(silent=silent, debug=debug, json=json)
|
|
18
|
+
|
|
19
|
+
def _copy() -> None:
|
|
20
|
+
dataset = load_dataset(path)
|
|
21
|
+
save_dataset(dataset, target=to_path) # type: ignore[arg-type]
|
|
22
|
+
|
|
23
|
+
session.task("Copy dataset", _copy)
|
|
24
|
+
|
|
25
|
+
session.render_text_result(
|
|
26
|
+
f"Copied dataset from [bold]{path}[/bold] to [bold]{to_path}[/bold]",
|
|
27
|
+
status="success",
|
|
28
|
+
)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from fairspec_library import infer_dataset
|
|
2
|
+
from fairspec_metadata import Dataset
|
|
3
|
+
|
|
4
|
+
from fairspec_terminal.params import (
|
|
5
|
+
ArrayType,
|
|
6
|
+
ColumnTypes,
|
|
7
|
+
CommaDecimal,
|
|
8
|
+
Confidence,
|
|
9
|
+
DateFormat,
|
|
10
|
+
DatetimeFormat,
|
|
11
|
+
Debug,
|
|
12
|
+
DecimalChar,
|
|
13
|
+
FalseValues,
|
|
14
|
+
GroupChar,
|
|
15
|
+
Json,
|
|
16
|
+
KeepStrings,
|
|
17
|
+
ListDelimiter,
|
|
18
|
+
ListItemType,
|
|
19
|
+
MissingValues,
|
|
20
|
+
MonthFirst,
|
|
21
|
+
SampleRows,
|
|
22
|
+
TimeFormat,
|
|
23
|
+
TrueValues,
|
|
24
|
+
VariadicPaths,
|
|
25
|
+
)
|
|
26
|
+
from fairspec_terminal.program import dataset_program
|
|
27
|
+
from fairspec_terminal.session import Session
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataset_program.command()
|
|
31
|
+
def infer(
|
|
32
|
+
paths: VariadicPaths,
|
|
33
|
+
json: Json = False,
|
|
34
|
+
debug: Debug = False,
|
|
35
|
+
sample_rows: SampleRows = None,
|
|
36
|
+
confidence: Confidence = None,
|
|
37
|
+
comma_decimal: CommaDecimal = False,
|
|
38
|
+
month_first: MonthFirst = False,
|
|
39
|
+
keep_strings: KeepStrings = False,
|
|
40
|
+
column_types: ColumnTypes = None,
|
|
41
|
+
missing_values: MissingValues = None,
|
|
42
|
+
decimal_char: DecimalChar = None,
|
|
43
|
+
group_char: GroupChar = None,
|
|
44
|
+
true_values: TrueValues = None,
|
|
45
|
+
false_values: FalseValues = None,
|
|
46
|
+
datetime_format: DatetimeFormat = None,
|
|
47
|
+
date_format: DateFormat = None,
|
|
48
|
+
time_format: TimeFormat = None,
|
|
49
|
+
array_type: ArrayType = None,
|
|
50
|
+
list_delimiter: ListDelimiter = None,
|
|
51
|
+
list_item_type: ListItemType = None,
|
|
52
|
+
) -> None:
|
|
53
|
+
"""Infer a dataset from local or remote file paths."""
|
|
54
|
+
session = Session(debug=debug, json=json)
|
|
55
|
+
|
|
56
|
+
def _infer() -> Dataset:
|
|
57
|
+
dataset = Dataset(resources=[{"data": data} for data in paths]) # type: ignore[list-item]
|
|
58
|
+
return infer_dataset(dataset)
|
|
59
|
+
|
|
60
|
+
dataset = session.task("Inferring dataset", _infer)
|
|
61
|
+
|
|
62
|
+
session.render_data_result(dataset.model_dump(exclude_none=True))
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from fairspec_library import load_dataset
|
|
2
|
+
from fairspec_metadata import infer_resource_name
|
|
3
|
+
|
|
4
|
+
from fairspec_terminal.params import Debug, Json, RequiredPath
|
|
5
|
+
from fairspec_terminal.program import dataset_program
|
|
6
|
+
from fairspec_terminal.session import Session
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataset_program.command(name="list")
|
|
10
|
+
def list_(
|
|
11
|
+
path: RequiredPath,
|
|
12
|
+
json: Json = False,
|
|
13
|
+
debug: Debug = False,
|
|
14
|
+
) -> None:
|
|
15
|
+
"""List Dataset resources."""
|
|
16
|
+
session = Session(debug=debug, json=json)
|
|
17
|
+
|
|
18
|
+
def _load() -> object:
|
|
19
|
+
dataset = load_dataset(path)
|
|
20
|
+
if not dataset:
|
|
21
|
+
raise ValueError("Could not load dataset")
|
|
22
|
+
return dataset
|
|
23
|
+
|
|
24
|
+
dataset = session.task("Loading dataset", _load)
|
|
25
|
+
|
|
26
|
+
resource_names = [
|
|
27
|
+
resource.name or infer_resource_name(resource)
|
|
28
|
+
for resource in getattr(dataset, "resources", None) or []
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
session.render_data_result(resource_names)
|