robot_obo_tool 0.0.1__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Charles Tapley Hoyt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,383 @@
1
+ Metadata-Version: 2.4
2
+ Name: robot_obo_tool
3
+ Version: 0.0.1
4
+ Summary: A wrapper around ROBOT
5
+ Keywords: snekpack,cookiecutter,ontologies,obo,robot,open biomedical ontologies
6
+ Author: Charles Tapley Hoyt
7
+ Author-email: Charles Tapley Hoyt <cthoyt@gmail.com>
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 1 - Planning
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Framework :: Pytest
15
+ Classifier: Framework :: tox
16
+ Classifier: Framework :: Sphinx
17
+ Classifier: Natural Language :: English
18
+ Classifier: Programming Language :: Python
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Programming Language :: Python :: 3 :: Only
25
+ Classifier: Typing :: Typed
26
+ Requires-Dist: pystow
27
+ Maintainer: Charles Tapley Hoyt
28
+ Maintainer-email: Charles Tapley Hoyt <cthoyt@gmail.com>
29
+ Requires-Python: >=3.10
30
+ Project-URL: Bug Tracker, https://github.com/cthoyt/robot-obo-tool/issues
31
+ Project-URL: Homepage, https://github.com/cthoyt/robot-obo-tool
32
+ Project-URL: Repository, https://github.com/cthoyt/robot-obo-tool.git
33
+ Project-URL: Documentation, https://robot_obo_tool.readthedocs.io
34
+ Project-URL: Funding, https://github.com/sponsors/cthoyt
35
+ Description-Content-Type: text/markdown
36
+
37
+ <!--
38
+ <p align="center">
39
+ <img src="https://github.com/cthoyt/robot-obo-tool/raw/main/docs/source/logo.png" height="150">
40
+ </p>
41
+ -->
42
+
43
+ <h1 align="center">
44
+ ROBOT is an OBO Tool
45
+ </h1>
46
+
47
+ <p align="center">
48
+ <a href="https://github.com/cthoyt/robot-obo-tool/actions/workflows/tests.yml">
49
+ <img alt="Tests" src="https://github.com/cthoyt/robot-obo-tool/actions/workflows/tests.yml/badge.svg" /></a>
50
+ <a href="https://pypi.org/project/robot_obo_tool">
51
+ <img alt="PyPI" src="https://img.shields.io/pypi/v/robot_obo_tool" /></a>
52
+ <a href="https://pypi.org/project/robot_obo_tool">
53
+ <img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/robot_obo_tool" /></a>
54
+ <a href="https://github.com/cthoyt/robot-obo-tool/blob/main/LICENSE">
55
+ <img alt="PyPI - License" src="https://img.shields.io/pypi/l/robot_obo_tool" /></a>
56
+ <a href='https://robot_obo_tool.readthedocs.io/en/latest/?badge=latest'>
57
+ <img src='https://readthedocs.org/projects/robot_obo_tool/badge/?version=latest' alt='Documentation Status' /></a>
58
+ <a href="https://codecov.io/gh/cthoyt/robot-obo-tool/branch/main">
59
+ <img src="https://codecov.io/gh/cthoyt/robot-obo-tool/branch/main/graph/badge.svg" alt="Codecov status" /></a>
60
+ <a href="https://github.com/cthoyt/cookiecutter-python-package">
61
+ <img alt="Cookiecutter template from @cthoyt" src="https://img.shields.io/badge/Cookiecutter-snekpack-blue" /></a>
62
+ <a href="https://github.com/astral-sh/ruff">
63
+ <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff" style="max-width:100%;"></a>
64
+ <a href="https://github.com/cthoyt/robot-obo-tool/blob/main/.github/CODE_OF_CONDUCT.md">
65
+ <img src="https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg" alt="Contributor Covenant"/></a>
66
+ <!-- uncomment if you archive on zenodo
67
+ <a href="https://doi.org/10.5281/zenodo.XXXXXX">
68
+ <img src="https://zenodo.org/badge/DOI/10.5281/zenodo.XXXXXX.svg" alt="DOI"></a>
69
+ -->
70
+ </p>
71
+
72
+ A Python wrapper around [ROBOT](https://robot.obolibrary.org/) that automates
73
+ downloading the Java JAR and wraps calls via the console using `subprocess`.
74
+
75
+ ## 💪 Getting Started
76
+
77
+ The `convert` can be called like in:
78
+
79
+ ```python
80
+ import robot_obo_tool
81
+
82
+ robot_obo_tool.convert(
83
+ "https://raw.githubusercontent.com/pato-ontology/pato/master/pato.owl",
84
+ "pato.obo",
85
+ check=False, # remove pesky errors for incorrect OWL
86
+ )
87
+ ```
88
+
89
+ Other ROBOT commands don't (yet) have a wrapper, but you can directly call ROBOT
90
+ with `call()`:
91
+
92
+ ```python
93
+ import robot_obo_tool
94
+
95
+ robot_obo_tool.call(
96
+ "convert",
97
+ "-I"
98
+ "https://raw.githubusercontent.com/pato-ontology/pato/master/pato.owl",
99
+ "-o",
100
+ "pato.obo",
101
+ "--check=false",
102
+ )
103
+ ```
104
+
105
+ ## 🚀 Installation
106
+
107
+ The most recent release can be installed from
108
+ [PyPI](https://pypi.org/project/robot_obo_tool/) with uv:
109
+
110
+ ```console
111
+ $ uv pip install robot_obo_tool
112
+ ```
113
+
114
+ or with pip:
115
+
116
+ ```console
117
+ $ python3 -m pip install robot_obo_tool
118
+ ```
119
+
120
+ The most recent code and data can be installed directly from GitHub with uv:
121
+
122
+ ```console
123
+ $ uv pip install git+https://github.com/cthoyt/robot-obo-tool.git
124
+ ```
125
+
126
+ or with pip:
127
+
128
+ ```console
129
+ $ python3 -m pip install git+https://github.com/cthoyt/robot-obo-tool.git
130
+ ```
131
+
132
+ ## 👐 Contributing
133
+
134
+ Contributions, whether filing an issue, making a pull request, or forking, are
135
+ appreciated. See
136
+ [CONTRIBUTING.md](https://github.com/cthoyt/robot-obo-tool/blob/master/.github/CONTRIBUTING.md)
137
+ for more information on getting involved.
138
+
139
+ ## 👋 Attribution
140
+
141
+ ### ⚖️ License
142
+
143
+ The code in this package is licensed under the MIT License.
144
+
145
+ <!--
146
+ ### 📖 Citation
147
+
148
+ Citation goes here!
149
+ -->
150
+
151
+ <!--
152
+ ### 🎁 Support
153
+
154
+ This project has been supported by the following organizations (in alphabetical order):
155
+
156
+ - [Biopragmatics Lab](https://biopragmatics.github.io)
157
+
158
+ -->
159
+
160
+ <!--
161
+ ### 💰 Funding
162
+
163
+ This project has been supported by the following grants:
164
+
165
+ | Funding Body | Program | Grant Number |
166
+ |---------------|--------------------------------------------------------------|--------------|
167
+ | Funder | [Grant Name (GRANT-ACRONYM)](https://example.com/grant-link) | ABCXYZ |
168
+ -->
169
+
170
+ ### 🍪 Cookiecutter
171
+
172
+ This package was created with
173
+ [@audreyfeldroy](https://github.com/audreyfeldroy)'s
174
+ [cookiecutter](https://github.com/cookiecutter/cookiecutter) package using
175
+ [@cthoyt](https://github.com/cthoyt)'s
176
+ [cookiecutter-snekpack](https://github.com/cthoyt/cookiecutter-snekpack)
177
+ template.
178
+
179
+ ## 🛠️ For Developers
180
+
181
+ <details>
182
+ <summary>See developer instructions</summary>
183
+
184
+ The final section of the README is for if you want to get involved by making a
185
+ code contribution.
186
+
187
+ ### Development Installation
188
+
189
+ To install in development mode, use the following:
190
+
191
+ ```console
192
+ $ git clone git+https://github.com/cthoyt/robot-obo-tool.git
193
+ $ cd robot-obo-tool
194
+ $ uv pip install -e .
195
+ ```
196
+
197
+ Alternatively, install using pip:
198
+
199
+ ```console
200
+ $ python3 -m pip install -e .
201
+ ```
202
+
203
+ ### Pre-commit
204
+
205
+ You can optionally use [pre-commit](https://pre-commit.com) to automate running
206
+ key code quality checks on each commit. Enable it with:
207
+
208
+ ```console
209
+ $ uvx pre-commit install
210
+ ```
211
+
212
+ Or using `pip`:
213
+
214
+ ```console
215
+ $ pip install pre-commit
216
+ $ pre-commit install
217
+ ```
218
+
219
+ ### 🥼 Testing
220
+
221
+ After cloning the repository and installing `tox` with
222
+ `uv tool install tox --with tox-uv` or `python3 -m pip install tox tox-uv`, the
223
+ unit tests in the `tests/` folder can be run reproducibly with:
224
+
225
+ ```console
226
+ $ tox -e py
227
+ ```
228
+
229
+ Additionally, these tests are automatically re-run with each commit in a
230
+ [GitHub Action](https://github.com/cthoyt/robot-obo-tool/actions?query=workflow%3ATests).
231
+
232
+ ### 📖 Building the Documentation
233
+
234
+ The documentation can be built locally using the following:
235
+
236
+ ```console
237
+ $ git clone git+https://github.com/cthoyt/robot-obo-tool.git
238
+ $ cd robot-obo-tool
239
+ $ tox -e docs
240
+ $ open docs/build/html/index.html
241
+ ```
242
+
243
+ The documentation automatically installs the package as well as the `docs` extra
244
+ specified in the [`pyproject.toml`](pyproject.toml). `sphinx` plugins like
245
+ `texext` can be added there. Additionally, they need to be added to the
246
+ `extensions` list in [`docs/source/conf.py`](docs/source/conf.py).
247
+
248
+ The documentation can be deployed to [ReadTheDocs](https://readthedocs.io) using
249
+ [this guide](https://docs.readthedocs.io/en/stable/intro/import-guide.html). The
250
+ [`.readthedocs.yml`](.readthedocs.yml) YAML file contains all the configuration
251
+ you'll need. You can also set up continuous integration on GitHub to check not
252
+ only that Sphinx can build the documentation in an isolated environment (i.e.,
253
+ with `tox -e docs-test`) but also that
254
+ [ReadTheDocs can build it too](https://docs.readthedocs.io/en/stable/pull-requests.html).
255
+
256
+ </details>
257
+
258
+ ## 🧑‍💻 For Maintainers
259
+
260
+ <details>
261
+ <summary>See maintainer instructions</summary>
262
+
263
+ ### Initial Configuration
264
+
265
+ #### Configuring ReadTheDocs
266
+
267
+ [ReadTheDocs](https://readthedocs.org) is an external documentation hosting
268
+ service that integrates with GitHub's CI/CD. Do the following for each
269
+ repository:
270
+
271
+ 1. Log in to ReadTheDocs with your GitHub account to install the integration at
272
+ https://readthedocs.org/accounts/login/?next=/dashboard/
273
+ 2. Import your project by navigating to https://readthedocs.org/dashboard/import
274
+ then clicking the plus icon next to your repository
275
+ 3. You can rename the repository on the next screen using a more stylized name
276
+ (i.e., with spaces and capital letters)
277
+ 4. Click next, and you're good to go!
278
+
279
+ #### Configuring Archival on Zenodo
280
+
281
+ [Zenodo](https://zenodo.org) is a long-term archival system that assigns a DOI
282
+ to each release of your package. Do the following for each repository:
283
+
284
+ 1. Log in to Zenodo via GitHub with this link:
285
+ https://zenodo.org/oauth/login/github/?next=%2F. This brings you to a page
286
+ that lists all of your organizations and asks you to approve installing the
287
+ Zenodo app on GitHub. Click "grant" next to any organizations you want to
288
+ enable the integration for, then click the big green "approve" button. This
289
+ step only needs to be done once.
290
+ 2. Navigate to https://zenodo.org/account/settings/github/, which lists all of
291
+ your GitHub repositories (both in your username and any organizations you
292
+ enabled). Click the on/off toggle for any relevant repositories. When you
293
+ make a new repository, you'll have to come back to this
294
+
295
+ After these steps, you're ready to go! After you make "release" on GitHub (steps
296
+ for this are below), you can navigate to
297
+ https://zenodo.org/account/settings/github/repository/cthoyt/robot-obo-tool to
298
+ see the DOI for the release and link to the Zenodo record for it.
299
+
300
+ #### Registering with the Python Package Index (PyPI)
301
+
302
+ The [Python Package Index (PyPI)](https://pypi.org) hosts packages so they can
303
+ be easily installed with `pip`, `uv`, and equivalent tools.
304
+
305
+ 1. Register for an account [here](https://pypi.org/account/register)
306
+ 2. Navigate to https://pypi.org/manage/account and make sure you have verified
307
+ your email address. A verification email might not have been sent by default,
308
+ so you might have to click the "options" dropdown next to your address to get
309
+ to the "re-send verification email" button
310
+ 3. 2-Factor authentication is required for PyPI since the end of 2023 (see this
311
+ [blog post from PyPI](https://blog.pypi.org/posts/2023-05-25-securing-pypi-with-2fa/)).
312
+ This means you have to first issue account recovery codes, then set up
313
+ 2-factor authentication
314
+ 4. Issue an API token from https://pypi.org/manage/account/token
315
+
316
+ This only needs to be done once per developer.
317
+
318
+ #### Configuring your machine's connection to PyPI
319
+
320
+ This needs to be done once per machine.
321
+
322
+ ```console
323
+ $ uv tool install keyring
324
+ $ keyring set https://upload.pypi.org/legacy/ __token__
325
+ $ keyring set https://test.pypi.org/legacy/ __token__
326
+ ```
327
+
328
+ Note that this deprecates previous workflows using `.pypirc`.
329
+
330
+ ### 📦 Making a Release
331
+
332
+ #### Uploading to PyPI
333
+
334
+ After installing the package in development mode and installing `tox` with
335
+ `uv tool install tox --with tox-uv` or `python3 -m pip install tox tox-uv`, run
336
+ the following from the console:
337
+
338
+ ```console
339
+ $ tox -e finish
340
+ ```
341
+
342
+ This script does the following:
343
+
344
+ 1. Uses [bump-my-version](https://github.com/callowayproject/bump-my-version) to
345
+ switch the version number in the `pyproject.toml`, `CITATION.cff`,
346
+ `src/robot_obo_tool/version.py`, and
347
+ [`docs/source/conf.py`](docs/source/conf.py) to not have the `-dev` suffix
348
+ 2. Packages the code in both a tar archive and a wheel using
349
+ [`uv build`](https://docs.astral.sh/uv/guides/publish/#building-your-package)
350
+ 3. Uploads to PyPI using
351
+ [`uv publish`](https://docs.astral.sh/uv/guides/publish/#publishing-your-package).
352
+ 4. Push to GitHub. You'll need to make a release going with the commit where the
353
+ version was bumped.
354
+ 5. Bump the version to the next patch. If you made big changes and want to bump
355
+ the version by minor, you can use `tox -e bumpversion -- minor` after.
356
+
357
+ #### Releasing on GitHub
358
+
359
+ 1. Navigate to https://github.com/cthoyt/robot-obo-tool/releases/new to draft a
360
+ new release
361
+ 2. Click the "Choose a Tag" dropdown and select the tag corresponding to the
362
+ release you just made
363
+ 3. Click the "Generate Release Notes" button to get a quick outline of recent
364
+ changes. Modify the title and description as you see fit
365
+ 4. Click the big green "Publish Release" button
366
+
367
+ This will trigger Zenodo to assign a DOI to your release as well.
368
+
369
+ ### Updating Package Boilerplate
370
+
371
+ This project uses `cruft` to keep boilerplate (i.e., configuration, contribution
372
+ guidelines, documentation configuration) up-to-date with the upstream
373
+ cookiecutter package. Install cruft with either `uv tool install cruft` or
374
+ `python3 -m pip install cruft` then run:
375
+
376
+ ```console
377
+ $ cruft update
378
+ ```
379
+
380
+ More info on Cruft's update command is available
381
+ [here](https://github.com/cruft/cruft?tab=readme-ov-file#updating-a-project).
382
+
383
+ </details>
@@ -0,0 +1,347 @@
1
+ <!--
2
+ <p align="center">
3
+ <img src="https://github.com/cthoyt/robot-obo-tool/raw/main/docs/source/logo.png" height="150">
4
+ </p>
5
+ -->
6
+
7
+ <h1 align="center">
8
+ ROBOT is an OBO Tool
9
+ </h1>
10
+
11
+ <p align="center">
12
+ <a href="https://github.com/cthoyt/robot-obo-tool/actions/workflows/tests.yml">
13
+ <img alt="Tests" src="https://github.com/cthoyt/robot-obo-tool/actions/workflows/tests.yml/badge.svg" /></a>
14
+ <a href="https://pypi.org/project/robot_obo_tool">
15
+ <img alt="PyPI" src="https://img.shields.io/pypi/v/robot_obo_tool" /></a>
16
+ <a href="https://pypi.org/project/robot_obo_tool">
17
+ <img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/robot_obo_tool" /></a>
18
+ <a href="https://github.com/cthoyt/robot-obo-tool/blob/main/LICENSE">
19
+ <img alt="PyPI - License" src="https://img.shields.io/pypi/l/robot_obo_tool" /></a>
20
+ <a href='https://robot_obo_tool.readthedocs.io/en/latest/?badge=latest'>
21
+ <img src='https://readthedocs.org/projects/robot_obo_tool/badge/?version=latest' alt='Documentation Status' /></a>
22
+ <a href="https://codecov.io/gh/cthoyt/robot-obo-tool/branch/main">
23
+ <img src="https://codecov.io/gh/cthoyt/robot-obo-tool/branch/main/graph/badge.svg" alt="Codecov status" /></a>
24
+ <a href="https://github.com/cthoyt/cookiecutter-python-package">
25
+ <img alt="Cookiecutter template from @cthoyt" src="https://img.shields.io/badge/Cookiecutter-snekpack-blue" /></a>
26
+ <a href="https://github.com/astral-sh/ruff">
27
+ <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff" style="max-width:100%;"></a>
28
+ <a href="https://github.com/cthoyt/robot-obo-tool/blob/main/.github/CODE_OF_CONDUCT.md">
29
+ <img src="https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg" alt="Contributor Covenant"/></a>
30
+ <!-- uncomment if you archive on zenodo
31
+ <a href="https://doi.org/10.5281/zenodo.XXXXXX">
32
+ <img src="https://zenodo.org/badge/DOI/10.5281/zenodo.XXXXXX.svg" alt="DOI"></a>
33
+ -->
34
+ </p>
35
+
36
+ A Python wrapper around [ROBOT](https://robot.obolibrary.org/) that automates
37
+ downloading the Java JAR and wraps calls via the console using `subprocess`.
38
+
39
+ ## 💪 Getting Started
40
+
41
+ The `convert` can be called like in:
42
+
43
+ ```python
44
+ import robot_obo_tool
45
+
46
+ robot_obo_tool.convert(
47
+ "https://raw.githubusercontent.com/pato-ontology/pato/master/pato.owl",
48
+ "pato.obo",
49
+ check=False, # remove pesky errors for incorrect OWL
50
+ )
51
+ ```
52
+
53
+ Other ROBOT commands don't (yet) have a wrapper, but you can directly call ROBOT
54
+ with `call()`:
55
+
56
+ ```python
57
+ import robot_obo_tool
58
+
59
+ robot_obo_tool.call(
60
+ "convert",
61
+ "-I"
62
+ "https://raw.githubusercontent.com/pato-ontology/pato/master/pato.owl",
63
+ "-o",
64
+ "pato.obo",
65
+ "--check=false",
66
+ )
67
+ ```
68
+
69
+ ## 🚀 Installation
70
+
71
+ The most recent release can be installed from
72
+ [PyPI](https://pypi.org/project/robot_obo_tool/) with uv:
73
+
74
+ ```console
75
+ $ uv pip install robot_obo_tool
76
+ ```
77
+
78
+ or with pip:
79
+
80
+ ```console
81
+ $ python3 -m pip install robot_obo_tool
82
+ ```
83
+
84
+ The most recent code and data can be installed directly from GitHub with uv:
85
+
86
+ ```console
87
+ $ uv pip install git+https://github.com/cthoyt/robot-obo-tool.git
88
+ ```
89
+
90
+ or with pip:
91
+
92
+ ```console
93
+ $ python3 -m pip install git+https://github.com/cthoyt/robot-obo-tool.git
94
+ ```
95
+
96
+ ## 👐 Contributing
97
+
98
+ Contributions, whether filing an issue, making a pull request, or forking, are
99
+ appreciated. See
100
+ [CONTRIBUTING.md](https://github.com/cthoyt/robot-obo-tool/blob/master/.github/CONTRIBUTING.md)
101
+ for more information on getting involved.
102
+
103
+ ## 👋 Attribution
104
+
105
+ ### ⚖️ License
106
+
107
+ The code in this package is licensed under the MIT License.
108
+
109
+ <!--
110
+ ### 📖 Citation
111
+
112
+ Citation goes here!
113
+ -->
114
+
115
+ <!--
116
+ ### 🎁 Support
117
+
118
+ This project has been supported by the following organizations (in alphabetical order):
119
+
120
+ - [Biopragmatics Lab](https://biopragmatics.github.io)
121
+
122
+ -->
123
+
124
+ <!--
125
+ ### 💰 Funding
126
+
127
+ This project has been supported by the following grants:
128
+
129
+ | Funding Body | Program | Grant Number |
130
+ |---------------|--------------------------------------------------------------|--------------|
131
+ | Funder | [Grant Name (GRANT-ACRONYM)](https://example.com/grant-link) | ABCXYZ |
132
+ -->
133
+
134
+ ### 🍪 Cookiecutter
135
+
136
+ This package was created with
137
+ [@audreyfeldroy](https://github.com/audreyfeldroy)'s
138
+ [cookiecutter](https://github.com/cookiecutter/cookiecutter) package using
139
+ [@cthoyt](https://github.com/cthoyt)'s
140
+ [cookiecutter-snekpack](https://github.com/cthoyt/cookiecutter-snekpack)
141
+ template.
142
+
143
+ ## 🛠️ For Developers
144
+
145
+ <details>
146
+ <summary>See developer instructions</summary>
147
+
148
+ The final section of the README is for if you want to get involved by making a
149
+ code contribution.
150
+
151
+ ### Development Installation
152
+
153
+ To install in development mode, use the following:
154
+
155
+ ```console
156
+ $ git clone git+https://github.com/cthoyt/robot-obo-tool.git
157
+ $ cd robot-obo-tool
158
+ $ uv pip install -e .
159
+ ```
160
+
161
+ Alternatively, install using pip:
162
+
163
+ ```console
164
+ $ python3 -m pip install -e .
165
+ ```
166
+
167
+ ### Pre-commit
168
+
169
+ You can optionally use [pre-commit](https://pre-commit.com) to automate running
170
+ key code quality checks on each commit. Enable it with:
171
+
172
+ ```console
173
+ $ uvx pre-commit install
174
+ ```
175
+
176
+ Or using `pip`:
177
+
178
+ ```console
179
+ $ pip install pre-commit
180
+ $ pre-commit install
181
+ ```
182
+
183
+ ### 🥼 Testing
184
+
185
+ After cloning the repository and installing `tox` with
186
+ `uv tool install tox --with tox-uv` or `python3 -m pip install tox tox-uv`, the
187
+ unit tests in the `tests/` folder can be run reproducibly with:
188
+
189
+ ```console
190
+ $ tox -e py
191
+ ```
192
+
193
+ Additionally, these tests are automatically re-run with each commit in a
194
+ [GitHub Action](https://github.com/cthoyt/robot-obo-tool/actions?query=workflow%3ATests).
195
+
196
+ ### 📖 Building the Documentation
197
+
198
+ The documentation can be built locally using the following:
199
+
200
+ ```console
201
+ $ git clone git+https://github.com/cthoyt/robot-obo-tool.git
202
+ $ cd robot-obo-tool
203
+ $ tox -e docs
204
+ $ open docs/build/html/index.html
205
+ ```
206
+
207
+ The documentation automatically installs the package as well as the `docs` extra
208
+ specified in the [`pyproject.toml`](pyproject.toml). `sphinx` plugins like
209
+ `texext` can be added there. Additionally, they need to be added to the
210
+ `extensions` list in [`docs/source/conf.py`](docs/source/conf.py).
211
+
212
+ The documentation can be deployed to [ReadTheDocs](https://readthedocs.io) using
213
+ [this guide](https://docs.readthedocs.io/en/stable/intro/import-guide.html). The
214
+ [`.readthedocs.yml`](.readthedocs.yml) YAML file contains all the configuration
215
+ you'll need. You can also set up continuous integration on GitHub to check not
216
+ only that Sphinx can build the documentation in an isolated environment (i.e.,
217
+ with `tox -e docs-test`) but also that
218
+ [ReadTheDocs can build it too](https://docs.readthedocs.io/en/stable/pull-requests.html).
219
+
220
+ </details>
221
+
222
+ ## 🧑‍💻 For Maintainers
223
+
224
+ <details>
225
+ <summary>See maintainer instructions</summary>
226
+
227
+ ### Initial Configuration
228
+
229
+ #### Configuring ReadTheDocs
230
+
231
+ [ReadTheDocs](https://readthedocs.org) is an external documentation hosting
232
+ service that integrates with GitHub's CI/CD. Do the following for each
233
+ repository:
234
+
235
+ 1. Log in to ReadTheDocs with your GitHub account to install the integration at
236
+ https://readthedocs.org/accounts/login/?next=/dashboard/
237
+ 2. Import your project by navigating to https://readthedocs.org/dashboard/import
238
+ then clicking the plus icon next to your repository
239
+ 3. You can rename the repository on the next screen using a more stylized name
240
+ (i.e., with spaces and capital letters)
241
+ 4. Click next, and you're good to go!
242
+
243
+ #### Configuring Archival on Zenodo
244
+
245
+ [Zenodo](https://zenodo.org) is a long-term archival system that assigns a DOI
246
+ to each release of your package. Do the following for each repository:
247
+
248
+ 1. Log in to Zenodo via GitHub with this link:
249
+ https://zenodo.org/oauth/login/github/?next=%2F. This brings you to a page
250
+ that lists all of your organizations and asks you to approve installing the
251
+ Zenodo app on GitHub. Click "grant" next to any organizations you want to
252
+ enable the integration for, then click the big green "approve" button. This
253
+ step only needs to be done once.
254
+ 2. Navigate to https://zenodo.org/account/settings/github/, which lists all of
255
+ your GitHub repositories (both in your username and any organizations you
256
+ enabled). Click the on/off toggle for any relevant repositories. When you
257
+ make a new repository, you'll have to come back to this
258
+
259
+ After these steps, you're ready to go! After you make "release" on GitHub (steps
260
+ for this are below), you can navigate to
261
+ https://zenodo.org/account/settings/github/repository/cthoyt/robot-obo-tool to
262
+ see the DOI for the release and link to the Zenodo record for it.
263
+
264
+ #### Registering with the Python Package Index (PyPI)
265
+
266
+ The [Python Package Index (PyPI)](https://pypi.org) hosts packages so they can
267
+ be easily installed with `pip`, `uv`, and equivalent tools.
268
+
269
+ 1. Register for an account [here](https://pypi.org/account/register)
270
+ 2. Navigate to https://pypi.org/manage/account and make sure you have verified
271
+ your email address. A verification email might not have been sent by default,
272
+ so you might have to click the "options" dropdown next to your address to get
273
+ to the "re-send verification email" button
274
+ 3. 2-Factor authentication is required for PyPI since the end of 2023 (see this
275
+ [blog post from PyPI](https://blog.pypi.org/posts/2023-05-25-securing-pypi-with-2fa/)).
276
+ This means you have to first issue account recovery codes, then set up
277
+ 2-factor authentication
278
+ 4. Issue an API token from https://pypi.org/manage/account/token
279
+
280
+ This only needs to be done once per developer.
281
+
282
+ #### Configuring your machine's connection to PyPI
283
+
284
+ This needs to be done once per machine.
285
+
286
+ ```console
287
+ $ uv tool install keyring
288
+ $ keyring set https://upload.pypi.org/legacy/ __token__
289
+ $ keyring set https://test.pypi.org/legacy/ __token__
290
+ ```
291
+
292
+ Note that this deprecates previous workflows using `.pypirc`.
293
+
294
+ ### 📦 Making a Release
295
+
296
+ #### Uploading to PyPI
297
+
298
+ After installing the package in development mode and installing `tox` with
299
+ `uv tool install tox --with tox-uv` or `python3 -m pip install tox tox-uv`, run
300
+ the following from the console:
301
+
302
+ ```console
303
+ $ tox -e finish
304
+ ```
305
+
306
+ This script does the following:
307
+
308
+ 1. Uses [bump-my-version](https://github.com/callowayproject/bump-my-version) to
309
+ switch the version number in the `pyproject.toml`, `CITATION.cff`,
310
+ `src/robot_obo_tool/version.py`, and
311
+ [`docs/source/conf.py`](docs/source/conf.py) to not have the `-dev` suffix
312
+ 2. Packages the code in both a tar archive and a wheel using
313
+ [`uv build`](https://docs.astral.sh/uv/guides/publish/#building-your-package)
314
+ 3. Uploads to PyPI using
315
+ [`uv publish`](https://docs.astral.sh/uv/guides/publish/#publishing-your-package).
316
+ 4. Push to GitHub. You'll need to make a release going with the commit where the
317
+ version was bumped.
318
+ 5. Bump the version to the next patch. If you made big changes and want to bump
319
+ the version by minor, you can use `tox -e bumpversion -- minor` after.
320
+
321
+ #### Releasing on GitHub
322
+
323
+ 1. Navigate to https://github.com/cthoyt/robot-obo-tool/releases/new to draft a
324
+ new release
325
+ 2. Click the "Choose a Tag" dropdown and select the tag corresponding to the
326
+ release you just made
327
+ 3. Click the "Generate Release Notes" button to get a quick outline of recent
328
+ changes. Modify the title and description as you see fit
329
+ 4. Click the big green "Publish Release" button
330
+
331
+ This will trigger Zenodo to assign a DOI to your release as well.
332
+
333
+ ### Updating Package Boilerplate
334
+
335
+ This project uses `cruft` to keep boilerplate (i.e., configuration, contribution
336
+ guidelines, documentation configuration) up-to-date with the upstream
337
+ cookiecutter package. Install cruft with either `uv tool install cruft` or
338
+ `python3 -m pip install cruft` then run:
339
+
340
+ ```console
341
+ $ cruft update
342
+ ```
343
+
344
+ More info on Cruft's update command is available
345
+ [here](https://github.com/cruft/cruft?tab=readme-ov-file#updating-a-project).
346
+
347
+ </details>
@@ -0,0 +1,254 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.9.6,<1.0"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "robot_obo_tool"
7
+ version = "0.0.1"
8
+ description = "A wrapper around ROBOT"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "Charles Tapley Hoyt", email = "cthoyt@gmail.com" }
12
+ ]
13
+ maintainers = [
14
+ { name = "Charles Tapley Hoyt", email = "cthoyt@gmail.com" }
15
+ ]
16
+
17
+ # See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#classifiers
18
+ # Search tags using the controlled vocabulary at https://pypi.org/classifiers
19
+ classifiers = [
20
+ "Development Status :: 1 - Planning",
21
+ "Environment :: Console",
22
+ "Intended Audience :: Developers",
23
+ "License :: OSI Approved :: MIT License",
24
+ "Operating System :: OS Independent",
25
+ "Framework :: Pytest",
26
+ "Framework :: tox",
27
+ "Framework :: Sphinx",
28
+ "Natural Language :: English",
29
+ "Programming Language :: Python",
30
+ "Programming Language :: Python :: 3.10",
31
+ "Programming Language :: Python :: 3.11",
32
+ "Programming Language :: Python :: 3.12",
33
+ "Programming Language :: Python :: 3.13",
34
+ "Programming Language :: Python :: 3.14",
35
+ "Programming Language :: Python :: 3 :: Only",
36
+ "Typing :: Typed",
37
+ # TODO add your topics from the Trove controlled vocabulary (see https://pypi.org/classifiers)
38
+ ]
39
+ keywords = [
40
+ "snekpack", # please keep this keyword to credit the cookiecutter-snekpack template
41
+ "cookiecutter",
42
+ "ontologies",
43
+ "obo",
44
+ "robot",
45
+ "open biomedical ontologies",
46
+ ]
47
+
48
+ # License Information.
49
+ # See PEP-639 at https://peps.python.org/pep-0639/#add-license-files-key
50
+ license-files = [
51
+ "LICENSE",
52
+ ]
53
+
54
+ requires-python = ">=3.10"
55
+ dependencies = [
56
+ "pystow",
57
+ ]
58
+
59
+ # see https://peps.python.org/pep-0735/ and https://docs.astral.sh/uv/concepts/dependencies/#dependency-groups
60
+ [dependency-groups]
61
+ tests = [
62
+ "pytest",
63
+ "coverage[toml]",
64
+ ]
65
+ docs = [
66
+ "sphinx>=8,<9",
67
+ "sphinx-rtd-theme>=3.0",
68
+ "sphinx_automodapi",
69
+ ]
70
+ lint = [
71
+ "ruff",
72
+ ]
73
+ typing = [
74
+ { include-group = "tests" },
75
+ "mypy",
76
+ ]
77
+ docs-lint = [
78
+ { include-group = "docs" },
79
+ "doc8",
80
+ ]
81
+ format-docs = [
82
+ { include-group = "docs" },
83
+ "docstrfmt",
84
+ ]
85
+ doctests = [
86
+ "xdoctest",
87
+ "pygments",
88
+ ]
89
+ pyroma = [
90
+ "pyroma",
91
+ "pygments",
92
+ ]
93
+
94
+ # see https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#dependencies-optional-dependencies
95
+ [project.optional-dependencies]
96
+
97
+
98
+ # See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#urls
99
+ # and also https://packaging.python.org/en/latest/specifications/well-known-project-urls/
100
+ [project.urls]
101
+ "Bug Tracker" = "https://github.com/cthoyt/robot-obo-tool/issues"
102
+ Homepage = "https://github.com/cthoyt/robot-obo-tool"
103
+ Repository = "https://github.com/cthoyt/robot-obo-tool.git"
104
+ Documentation = "https://robot_obo_tool.readthedocs.io"
105
+ Funding = "https://github.com/sponsors/cthoyt"
106
+
107
+
108
+
109
+ [tool.cruft]
110
+ skip = [
111
+ "**/__init__.py",
112
+ "tests/*"
113
+ ]
114
+
115
+ # MyPy, see https://mypy.readthedocs.io/en/stable/config_file.html
116
+ [tool.mypy]
117
+ plugins = [
118
+ ]
119
+
120
+ # Doc8, see https://doc8.readthedocs.io/en/stable/readme.html#ini-file-usage
121
+ [tool.doc8]
122
+ max-line-length = 120
123
+
124
+ # Pytest, see https://docs.pytest.org/en/stable/reference/customize.html#pyproject-toml
125
+ [tool.pytest.ini_options]
126
+ markers = [
127
+ "slow: marks tests as slow (deselect with '-m \"not slow\"')",
128
+ ]
129
+
130
+ # Coverage, see https://coverage.readthedocs.io/en/latest/config.html
131
+ [tool.coverage.run]
132
+ branch = true
133
+ source = [
134
+ "robot_obo_tool",
135
+ ]
136
+ omit = [
137
+ "tests/*",
138
+ "docs/*",
139
+ "src/robot_obo_tool/version.py",
140
+ "src/robot_obo_tool/__main__.py",
141
+ "src/robot_obo_tool/cli.py",
142
+ ]
143
+
144
+ [tool.coverage.paths]
145
+ source = [
146
+ "src/robot_obo_tool",
147
+ ".tox/*/lib/python*/site-packages/robot_obo_tool",
148
+ ]
149
+
150
+ [tool.coverage.report]
151
+ show_missing = true
152
+ exclude_lines = [
153
+ "pragma: no cover",
154
+ "raise NotImplementedError",
155
+ "if __name__ == \"__main__\":",
156
+ "if TYPE_CHECKING:",
157
+ "def __str__",
158
+ "def __repr__",
159
+ ]
160
+
161
+ [tool.ruff]
162
+ line-length = 100
163
+ extend-include = ["*.ipynb"]
164
+
165
+ [tool.ruff.lint]
166
+ # See https://docs.astral.sh/ruff/rules
167
+ extend-select = [
168
+ "F", # pyflakes
169
+ "E", # pycodestyle errors
170
+ "W", # pycodestyle warnings
171
+ "C90", # mccabe
172
+ "I", # isort
173
+ "UP", # pyupgrade
174
+ "D", # pydocstyle
175
+ "DOC", # pydoclint
176
+ "B", # bugbear
177
+ "S", # bandit
178
+ "T20", # print
179
+ "N", # pep8 naming
180
+ "ERA", # eradicate commented out code
181
+ "NPY", # numpy checks
182
+ "RUF", # ruff rules
183
+ "C4", # comprehensions
184
+ ]
185
+ ignore = [
186
+ "D105", # Missing docstring in magic method
187
+ "E203", # Black conflicts with the following
188
+ ]
189
+
190
+ # See https://docs.astral.sh/ruff/settings/#per-file-ignores
191
+ [tool.ruff.lint.per-file-ignores]
192
+ # Ignore security issues in the version.py, which are inconsistent
193
+ "src/robot_obo_tool/version.py" = ["S603", "S607"]
194
+ # Ignore commented out code in Sphinx configuration file
195
+ "docs/source/conf.py" = ["ERA001"]
196
+ # Prints are okay in notebooks
197
+ "notebooks/**/*.ipynb" = ["T201"]
198
+
199
+ [tool.ruff.lint.pydocstyle]
200
+ convention = "pep257"
201
+
202
+ [tool.ruff.lint.isort]
203
+ relative-imports-order = "closest-to-furthest"
204
+ known-third-party = [
205
+ "tqdm",
206
+ ]
207
+ known-first-party = [
208
+ "robot_obo_tool",
209
+ "tests",
210
+ ]
211
+
212
+ [tool.ruff.format]
213
+ # see https://docs.astral.sh/ruff/settings/#format_docstring-code-format
214
+ docstring-code-format = true
215
+
216
+ [tool.bumpversion]
217
+ current_version = "0.0.1"
218
+ parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(?:-(?P<release>[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+(?P<build>[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?"
219
+ serialize = [
220
+ "{major}.{minor}.{patch}-{release}+{build}",
221
+ "{major}.{minor}.{patch}+{build}",
222
+ "{major}.{minor}.{patch}-{release}",
223
+ "{major}.{minor}.{patch}",
224
+ ]
225
+ commit = true
226
+ tag = false
227
+
228
+ [tool.bumpversion.parts.release]
229
+ optional_value = "production"
230
+ first_value = "dev"
231
+ values = [
232
+ "dev",
233
+ "production",
234
+ ]
235
+
236
+ [[tool.bumpversion.files]]
237
+ filename = "pyproject.toml"
238
+ search = "version = \"{current_version}\""
239
+ replace = "version = \"{new_version}\""
240
+
241
+ [[tool.bumpversion.files]]
242
+ filename = "docs/source/conf.py"
243
+ search = "release = \"{current_version}\""
244
+ replace = "release = \"{new_version}\""
245
+
246
+ [[tool.bumpversion.files]]
247
+ filename = "src/robot_obo_tool/version.py"
248
+ search = "VERSION = \"{current_version}\""
249
+ replace = "VERSION = \"{new_version}\""
250
+
251
+ [[tool.bumpversion.files]]
252
+ filename = "CITATION.cff"
253
+ search = "version: {current_version}"
254
+ replace = "version: {new_version}"
@@ -0,0 +1,12 @@
1
+ """A wrapper around ROBOT."""
2
+
3
+ from .api import ROBOT_VERSION, ROBOTError, call, convert, ensure_jar, is_available
4
+
5
+ __all__ = [
6
+ "ROBOT_VERSION",
7
+ "ROBOTError",
8
+ "call",
9
+ "convert",
10
+ "ensure_jar",
11
+ "is_available",
12
+ ]
@@ -0,0 +1,232 @@
1
+ """A wrapper around ROBOT functionality.
2
+
3
+ .. seealso:: https://robot.obolibrary.org
4
+ """
5
+
6
+ import logging
7
+ import os
8
+ import subprocess
9
+ from pathlib import Path
10
+ from shutil import which
11
+ from subprocess import check_output
12
+ from textwrap import indent, shorten
13
+ from typing import Literal
14
+
15
+ import pystow
16
+
17
+ __all__ = [
18
+ "ROBOT_VERSION",
19
+ "ROBOTError",
20
+ "call",
21
+ "convert",
22
+ "ensure_jar",
23
+ "is_available",
24
+ ]
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+ #: The default ROBOT version to download
29
+ ROBOT_VERSION = "1.9.8"
30
+ ROBOT_MODULE = pystow.module("robot")
31
+
32
+
33
+ def ensure_jar(*, version: str | None = None) -> Path:
34
+ """Ensure the ROBOT JAR is cached."""
35
+ if version is None:
36
+ version = ROBOT_VERSION
37
+ url = f"https://github.com/ontodev/robot/releases/download/v{version}/robot.jar"
38
+ return ROBOT_MODULE.ensure(url=url, version=version)
39
+
40
+
41
+ def is_available(*, version: str | None = None) -> bool:
42
+ """Check if ROBOT is available."""
43
+ if which("java") is None:
44
+ # suggested in https://stackoverflow.com/questions/11210104/check-if-a-program-exists-from-a-python-script
45
+ logger.error("java is not on the PATH")
46
+ return False
47
+
48
+ try:
49
+ check_output(["java", "--help"]) # noqa: S607
50
+ except Exception:
51
+ logger.error(
52
+ "java --help failed - this means the java runtime environment (JRE) "
53
+ "might not be configured properly"
54
+ )
55
+ return False
56
+
57
+ robot_jar_path = ensure_jar(version=version)
58
+ if not robot_jar_path.is_file():
59
+ logger.error("ROBOT was not successfully downloaded to %s", robot_jar_path)
60
+ # ROBOT was unsuccessfully downloaded
61
+ return False
62
+
63
+ try:
64
+ call("--help")
65
+ except Exception:
66
+ logger.error("ROBOT was downloaded to %s but could not be run with --help", robot_jar_path)
67
+ return False
68
+
69
+ return True
70
+
71
+
72
+ def call(*args: str, version: str | None = None) -> str:
73
+ """Run a ROBOT command and return the output as a string."""
74
+ rr = ["java", "-jar", str(ensure_jar(version=version)), *args]
75
+ logger.debug("Running shell command: %s", rr)
76
+ try:
77
+ ret = check_output( # noqa:S603
78
+ rr,
79
+ cwd=os.path.dirname(__file__),
80
+ stderr=subprocess.PIPE,
81
+ )
82
+ except subprocess.CalledProcessError as e:
83
+ raise ROBOTError(
84
+ command=e.cmd,
85
+ return_code=e.returncode,
86
+ output=e.output.decode() if e.output is not None else None,
87
+ stderr=e.stderr.decode() if e.stderr is not None else None,
88
+ ) from None
89
+
90
+ return ret.decode()
91
+
92
+
93
+ def convert(
94
+ input_path: str | Path,
95
+ output_path: str | Path,
96
+ input_flag: Literal["-i", "-I"] | None = None,
97
+ *,
98
+ merge: bool = False,
99
+ fmt: str | None = None,
100
+ check: bool = True,
101
+ reason: bool = False,
102
+ extra_args: list[str] | None = None,
103
+ debug: bool = False,
104
+ version: str | None = None,
105
+ ) -> str:
106
+ """Convert an OBO file to an OWL file with ROBOT.
107
+
108
+ :param input_path: Either a local file path or IRI. If a local file path
109
+ is used, pass ``"-i"`` to ``flag``. If an IRI is used, pass ``"-I"``
110
+ to ``flag``.
111
+ :param output_path: The local file path to save the converted ontology to.
112
+ Will infer format from the extension, otherwise, use the ``fmt`` param.
113
+ :param input_flag: The flag to denote if the file is local or remote.
114
+ Tries to infer from input string if none is given
115
+ :param merge: Use ROBOT's merge command to squash all graphs together
116
+ :param fmt: Explicitly set the format
117
+ :param check:
118
+ By default, the OBO writer strictly enforces
119
+ `document structure rules <http://owlcollab.github.io/oboformat/doc/obo-syntax.html#4>`.
120
+ If an ontology violates these, the convert to OBO operation will fail.
121
+ These checks can be ignored by setting this to false.
122
+ :param reason:
123
+ Turn on ontology reasoning
124
+ :param extra_args:
125
+ Extra positional arguments to pass in the command line
126
+ :param debug:
127
+ Turn on -vvv
128
+ :param version: the version of ROBOT to use
129
+ :return: Output from standard out from running ROBOT
130
+ """
131
+ if input_flag is None:
132
+ input_flag = "-I" if _is_remote(input_path) else "-i"
133
+
134
+ args: list[str] = []
135
+
136
+ if merge and not reason:
137
+ args.extend(["merge", str(input_flag), str(input_path), "convert"])
138
+ elif merge and reason:
139
+ args.extend(
140
+ [
141
+ "merge",
142
+ str(input_flag),
143
+ str(input_path),
144
+ "reason",
145
+ "convert",
146
+ ]
147
+ )
148
+ elif not merge and reason:
149
+ args.extend(
150
+ [
151
+ "reason",
152
+ str(input_flag),
153
+ str(input_path),
154
+ "convert",
155
+ ]
156
+ )
157
+ else:
158
+ args.extend(
159
+ [
160
+ "convert",
161
+ str(input_flag),
162
+ str(input_path),
163
+ ]
164
+ )
165
+
166
+ args.extend(("-o", str(output_path)))
167
+ if extra_args:
168
+ args.extend(extra_args)
169
+ if not check:
170
+ args.append("--check=false")
171
+ if fmt:
172
+ args.extend(("--format", fmt))
173
+ if debug:
174
+ args.append("-vvv")
175
+
176
+ return call(*args, version=version)
177
+
178
+
179
+ #: Prefixes that denote remote resources
180
+ PROTOCOLS = {
181
+ "https://",
182
+ "http://",
183
+ "ftp://",
184
+ "ftps://",
185
+ }
186
+
187
+
188
+ def _is_remote(url: str | Path) -> bool:
189
+ return isinstance(url, str) and any(url.startswith(protocol) for protocol in PROTOCOLS)
190
+
191
+
192
+ class ROBOTError(Exception):
193
+ """Custom error for ROBOT command failures that includes output preview."""
194
+
195
+ def __init__(
196
+ self,
197
+ command: list[str],
198
+ return_code: int,
199
+ output: str | None = None,
200
+ stderr: str | None = None,
201
+ preview_length: int = 500,
202
+ ) -> None:
203
+ """Initialize a wrapper around a ROBOT exception.
204
+
205
+ :param command: The command that was executed and failed
206
+ :param return_code: The exit code returned by the command
207
+ :param output: The stdout/stderr output from the command execution
208
+ :param preview_length:
209
+ Maximum number of characters to include in the
210
+ error message preview. Default is 500 characters.
211
+
212
+ The error message will contain the command, return code, and a preview
213
+ of the output truncated to preview_length characters.
214
+ """
215
+ self.command = command
216
+ self.return_code = return_code
217
+ self.stdout = output or "<no stdout>"
218
+ self.preview_length = preview_length
219
+ self.stderr = stderr or "<no stderr>"
220
+
221
+ # Create the error message
222
+ command_str = " ".join(command)
223
+ stdout_preview = indent(shorten(self.stdout, preview_length), " ")
224
+ stderr_preview = indent(shorten(self.stderr, preview_length), " ")
225
+
226
+ message = (
227
+ f"Command `{command_str}` returned non-zero exit status {return_code}.\n\n"
228
+ f"stderr:\n\n{stderr_preview}"
229
+ f"\n\nstdout:\n\n{stdout_preview}"
230
+ )
231
+
232
+ super().__init__(message)
@@ -0,0 +1,39 @@
1
+ """Version information for :mod:`robot_obo_tool`.
2
+
3
+ Run with ``python -m robot_obo_tool.version``
4
+ """
5
+
6
+ import os
7
+ from subprocess import CalledProcessError, check_output
8
+
9
+ __all__ = [
10
+ "VERSION",
11
+ "get_git_hash",
12
+ "get_version",
13
+ ]
14
+
15
+ VERSION = "0.0.1"
16
+
17
+
18
+ def get_git_hash() -> str:
19
+ """Get the :mod:`robot_obo_tool` git hash."""
20
+ with open(os.devnull, "w") as devnull:
21
+ try:
22
+ ret = check_output(
23
+ ["git", "rev-parse", "HEAD"],
24
+ cwd=os.path.dirname(__file__),
25
+ stderr=devnull,
26
+ )
27
+ except CalledProcessError:
28
+ return "UNHASHED"
29
+ else:
30
+ return ret.strip().decode("utf-8")[:8]
31
+
32
+
33
+ def get_version(with_git_hash: bool = False) -> str:
34
+ """Get the :mod:`robot_obo_tool` version string, including a git hash."""
35
+ return f"{VERSION}-{get_git_hash()}" if with_git_hash else VERSION
36
+
37
+
38
+ if __name__ == "__main__":
39
+ print(get_version(with_git_hash=True)) # noqa:T201