Skip to content

Commit c828a07

Browse files
authored
Document usage of pico as a module. (#200)
1 parent f9d8f9b commit c828a07

File tree

3 files changed

+83
-30
lines changed

3 files changed

+83
-30
lines changed

docs/source/api_ref.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,10 @@ This document is for developers and/or advanced users of OSP-core, it contains a
8484
.. automodule:: osp.core.utils
8585
:imported-members:
8686
:members:
87-
```
87+
```
88+
89+
### pico
90+
```{eval-rst}
91+
.. automodule:: osp.core.pico
92+
:members: install, uninstall, packages, namespaces
93+
```

docs/source/utils.md

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
# Utilities
22
In this section we will compile a list of useful utility functions, tools and examples of their usage.
3-
These functions are part of OSP-core and are used as an extension of the
4-
[main API](./detailed_design.md#cuds-api).
3+
These functions are part of OSP-core and are used as an extension of the [main API](./detailed_design.md#cuds-api).
54

6-
## Pico Installs Cuds Ontologies
5+
## pico (Pico Installs Cuds Ontologies)
76
Our tool for installing ontologies is called `pico`.
87
It is a recursive acronym that stands for _Pico Installs Cuds Ontologies_.
98

10-
There are 3 main things that can be done with pico:
9+
There are 3 main operations that can be done with pico:
1110
- Install ontologies.
1211
- List the installed ontologies.
1312
- Remove installed ontologies.
1413

15-
There are different possible levels of log available, and they can be set via
14+
`pico` can be used both from the [command-line](utils.md#using-pico-from-the-command-line)
15+
and [as a Python module within the Python shell](utils.md#using-pico-as-a-python-module).
16+
17+
### Using pico from the command line
18+
19+
There are different possible logging levels available, and they can be set via
1620
`--log-level <ERROR|WARNING|INFO|DEBUG>`. The default value is `INFO`.
1721

18-
### Pico installs
19-
_Usage:_ `pico install <path/to/ontology.yml>|city|cuba`
22+
#### pico installs
23+
_Usage:_
24+
- `pico install <path/to/ontology_yml_file.yml>`
25+
- `pico install <path/to/ontology_yml_file1.yml> <path/to/ontology_yml_file2.yml> ...`
26+
- `pico install city foaf emmo dcat2` (the installation of these specific
27+
well-known ontologies is available via this shortcut)
2028

2129
_Behaviour:_
22-
- The ontology file is parsed, and the entities mapped to python objects.
23-
- The python classes can be imported via their namespace
24-
`from osp.core.namespaces import namespace`
30+
- The ontology file is parsed, and the entities mapped to Python objects.
31+
- The Python objects can be imported via their namespace `from osp.core.namespaces import namespace`.
2532

2633
_Example:_
2734
```console
@@ -33,12 +40,13 @@ INFO [osp.core.ontology.parser]: Loaded 367 ontology triples in total
3340
INFO [osp.core.ontology.installation]: Installation successful
3441
```
3542

36-
### Pico lists
43+
#### pico lists
3744
_Usage:_ `pico list`
3845

3946
_Behaviour:_
4047
- The installed namespaces and packages are printed out. A package can be
41-
uninstalled and can contain many namespaces. A namespace can be imported in code.
48+
uninstalled and can contain many namespaces. A namespace can be imported
49+
within the Python shell.
4250

4351
_Example:_
4452
```console
@@ -56,34 +64,26 @@ Namespaces:
5664
- city
5765
```
5866

59-
### Pico uninstalls
60-
_Usage:_ `pico uninstall <package>|all`.
61-
Note that to select all the packages, `all` must be quoted.
67+
#### pico uninstalls
68+
_Usage:_
69+
- `pico uninstall <package>`
70+
- `pico uninstall all`
6271

6372
_Behaviour:_
64-
- All installed packages / namespaces are uninstalled.
65-
- All namespaces except the uninstalled ones are re-installed.
73+
- The specified packages are uninstalled.
74+
- All packages except the uninstalled ones are re-installed.
6675

6776
_Example:_
6877
```console
78+
(venv) user@PC:~$ pico uninstall city
6979
INFO [osp.core.ontology.installation]: Will install the following namespaces: ['qe']
7080
INFO [osp.core.ontology.yml.yml_parser]: Parsing YAML ontology file /home/<username>/.osp_ontologies/qe.yml
7181
INFO [osp.core.ontology.yml.yml_parser]: You can now use `from osp.core.namespaces import qe`.
7282
INFO [osp.core.ontology.parser]: Loaded 205 ontology triples in total
7383
INFO [osp.core.ontology.installation]: Uninstallation successful
7484
```
7585

76-
### Ontology installation folder
77-
78-
The installed ontologies are stored in the directory `~/.osp-ontologies` by
79-
default. On Windows, `~` usually refers to the path
80-
`C:\Users\<my username>`.
81-
82-
The installation directory can be changed by setting the
83-
environment variable `OSP_ONTOLOGIES_DIR`. Such action would move it to
84-
`$OSP_ONTOLOGIES_DIR/.osp-ontologies`.
85-
86-
### Conflicts with other "pico" installations
86+
#### Conflicts with other "pico" installations
8787
Some Operating Systems might have a pre-existing tool called _pico_.
8888
In most cases, the previous commands should work, but if any problem arises,
8989
you can use the following alternative:
@@ -97,6 +97,54 @@ For example:
9797
python -m osp.core.pico install city
9898
```
9999

100+
### Using pico as a Python module
101+
102+
`pico` can also be used within the Python shell. In particular, four
103+
functions are available to be imported from the `osp.core.pico` module,
104+
105+
```python
106+
from osp.core.pico import install, namespaces, packages, uninstall
107+
```
108+
109+
that cover the three main operations that pico is meant to perform: installing
110+
ontologies (`install`), uninstalling ontologies (`uninstall`), and listing the
111+
installed ontologies (`packages`, `namespaces`).
112+
113+
Each function is used in a similar way to its command-line counterpart.
114+
115+
- `install`: accepts _one or more_ positional arguments of string
116+
type, which can be either paths to `yml` ontology installation files or
117+
names of ontologies that can be installed via this shortcut. It is meant to
118+
clone the
119+
[behavior of its command-line counterpart](https://simphony.readthedocs.io/en/latest/utils.html#pico-installs).
120+
121+
- `uninstall`: accepts _one or more_ positional arguments of string type,
122+
which must be names of already installed ontology packages. It also
123+
clones the [behavior of its command-line counterpart](https://simphony.readthedocs.io/en/latest/utils.html#pico-uninstalls).
124+
125+
- `packages`: accepts no arguments and returns an [iterator](https://wiki.python.org/moin/Iterator)
126+
over the names of the installed packages.
127+
128+
- `namespaces`: accepts no arguments and returns an iterator yielding one
129+
[`OntologyNamespace` object](https://simphony.readthedocs.io/en/latest/api_ref.html#osp.core.ontology.namespace.OntologyNamespace) for each installed namespace.
130+
131+
Usage examples:
132+
133+
- `install('city', 'path/to/ontology_yml_file.yml')`, `install('foaf', 'dcat2')`
134+
- `uninstall('city', 'foaf')`
135+
- `print(list(packages()))`
136+
- `print(list(namespaces()))`
137+
138+
### Ontology installation folder
139+
140+
The installed ontologies are stored in the directory `~/.osp-ontologies` by
141+
default. On Windows, `~` usually refers to the path
142+
`C:\Users\<my username>`.
143+
144+
The installation directory can be changed by setting the
145+
environment variable `OSP_ONTOLOGIES_DIR`. Such action would move it to
146+
`$OSP_ONTOLOGIES_DIR/.osp-ontologies`.
147+
100148
## Tips and tricks
101149
The following are some utility functions and shortcuts for working with cuds.
102150
For those that are present in the util package, the import is `from osp.core import utils`.

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ sphinx-autobuild==2021.3.14
1111
sphinx-panels==0.5.2
1212
jinja2==2.11.3
1313
markupsafe==2.0.1
14-

0 commit comments

Comments
 (0)