Skip to content

Commit 156a21e

Browse files
authored
Merge pull request #608 from python-gitlab/ci-output-option
docs(cli): add PyYAML requirement notice
2 parents 5ff2608 + d29a489 commit 156a21e

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ Documentation
5454
The full documentation for CLI and API is available on `readthedocs
5555
<http://python-gitlab.readthedocs.org/en/stable/>`_.
5656

57+
Build the docs
58+
--------------
59+
You can build the documentation using ``sphinx``::
60+
61+
pip install sphinx
62+
python setup.py build_sphinx
63+
5764

5865
Contributing
5966
============

docs/cli.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ These options must be defined before the mandatory arguments.
157157
``--output``, ``-o``
158158
Output format. Defaults to a custom format. Can also be ``yaml`` or ``json``.
159159

160+
**Notice:**
161+
162+
The `PyYAML package <https://pypi.org/project/PyYAML/>`_ is required to use the yaml output option.
163+
You need to install it separately using ``pip install PyYAML``
164+
160165
``--fields``, ``-f``
161166
Comma-separated list of fields to display (``yaml`` and ``json`` output
162167
formats only). If not used, all the object fields are displayed.

gitlab/v4/cli.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,24 @@ def display_list(self, data, fields, **kwargs):
302302

303303
class YAMLPrinter(object):
304304
def display(self, d, **kwargs):
305-
import yaml # noqa
306-
print(yaml.safe_dump(d, default_flow_style=False))
305+
try:
306+
import yaml # noqa
307+
print(yaml.safe_dump(d, default_flow_style=False))
308+
except ImportError:
309+
exit("PyYaml is not installed.\n"
310+
"Install it with `pip install PyYaml` "
311+
"to use the yaml output feature")
307312

308313
def display_list(self, data, fields, **kwargs):
309-
import yaml # noqa
310-
print(yaml.safe_dump(
311-
[get_dict(obj, fields) for obj in data],
312-
default_flow_style=False))
314+
try:
315+
import yaml # noqa
316+
print(yaml.safe_dump(
317+
[get_dict(obj, fields) for obj in data],
318+
default_flow_style=False))
319+
except ImportError:
320+
exit("PyYaml is not installed.\n"
321+
"Install it with `pip install PyYaml` "
322+
"to use the yaml output feature")
313323

314324

315325
class LegacyPrinter(object):

0 commit comments

Comments
 (0)