Skip to content

Commit d2d586f

Browse files
author
Jon Wayne Parrott
committed
Add basic readme generator
Change-Id: I53b753fb7e422161b443cd6d96df9501a7b37ab4
1 parent 9ee1995 commit d2d586f

File tree

10 files changed

+677
-12
lines changed

10 files changed

+677
-12
lines changed

nox.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,12 @@ def mark_if_necessary(requirement):
320320
for requirement in sorted(requirements, key=lambda s: s.lower()):
321321
if not requirement.startswith('#'):
322322
f.write(requirement)
323+
324+
325+
def session_readmegen(session):
326+
session.install('-r', 'testing/requirements-dev.txt')
327+
328+
in_files = list(list_files('.', 'README.rst.in'))
329+
330+
for in_file in in_files:
331+
session.run('python', 'scripts/readme-gen/readme_gen.py', in_file)

scripts/readme-gen/readme_gen.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (C) 2013 Google Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import argparse
18+
import io
19+
import os
20+
import subprocess
21+
22+
import jinja2
23+
import yaml
24+
25+
26+
jinja_env = jinja2.Environment(
27+
trim_blocks=True,
28+
loader=jinja2.FileSystemLoader(
29+
os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates'))))
30+
31+
README_TMPL = jinja_env.get_template('README.tmpl.rst')
32+
33+
34+
def get_help(file):
35+
return subprocess.check_output(['python', file, '--help'])
36+
37+
38+
def main():
39+
parser = argparse.ArgumentParser()
40+
parser.add_argument('source')
41+
parser.add_argument('--destination', default='README.rst')
42+
43+
args = parser.parse_args()
44+
45+
source = os.path.abspath(args.source)
46+
root = os.path.dirname(source)
47+
destination = os.path.join(root, args.destination)
48+
49+
jinja_env.globals['get_help'] = get_help
50+
51+
with io.open(source, 'r') as f:
52+
config = yaml.load(f)
53+
54+
# This allows get_help to execute in the right directory.
55+
os.chdir(root)
56+
57+
output = README_TMPL.render(config)
58+
59+
with io.open(destination, 'w') as f:
60+
f.write(output)
61+
62+
if __name__ == '__main__':
63+
main()
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.. This file is automatically generated. Do not edit this file directly.
2+
3+
{{product.name}} Python Samples
4+
===============================================================================
5+
6+
This directory contains samples for {{product.name}}. {{product.description}}
7+
8+
.. _{{product.name}}: {{product.url}}
9+
10+
{% if setup %}
11+
Setup
12+
-------------------------------------------------------------------------------
13+
14+
{% for section in setup %}
15+
16+
{% include section + '.tmpl.rst' %}
17+
18+
{% endfor %}
19+
{% endif %}
20+
21+
{% if samples %}
22+
Samples
23+
-------------------------------------------------------------------------------
24+
25+
{% for sample in samples %}
26+
{{sample.name}}
27+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28+
29+
{{sample.description}}
30+
31+
To run this sample:
32+
33+
.. code-block:: bash
34+
35+
$ python {{sample.file}}
36+
{% if sample.show_help %}
37+
38+
{{get_help(sample.file)|indent}}
39+
{% endif %}
40+
41+
42+
{% endfor %}
43+
{% endif %}
44+
45+
{% if cloud_client_library %}
46+
47+
The client library
48+
-------------------------------------------------------------------------------
49+
50+
This sample uses the `Google Cloud Client Library for Python <ccl-docs>`_.
51+
You can read the documentation for more details on API usage and use GitHub
52+
to `browse the source <ccl-source>`_ and `report issues <ccl-issues>`_.
53+
54+
.. ccl-docs: https://googlecloudplatform.github.io/google-cloud-python/
55+
.. ccl-source: https://github.com/GoogleCloudPlatform/google-cloud-python
56+
.. ccl-issues: https://github.com/GoogleCloudPlatform/google-cloud-python/issues
57+
58+
{% endif %}
59+
60+
.. _Google Cloud SDK: https://cloud.google.com/sdk/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Authentication
2+
++++++++++++++
3+
4+
Authentication is typically done through `Application Default Credentials`_,
5+
this means you do not have to change the code to authenticate as long as
6+
your environment has credentials. You have a few options for setting up
7+
authentication:
8+
9+
{% if not no_sdk_credentials %}
10+
#. When running locally, use the `Google Cloud SDK`_
11+
12+
.. code-block:: bash
13+
14+
gcloud beta auth application-default login
15+
16+
{% endif %}
17+
18+
#. When running on App Engine or Compute Engine, credentials are already
19+
set-up. However, you may need to configure your Compute Engine instance
20+
with `additional scopes <gce-auth>`_.
21+
22+
#. You can create a `Service Account key file`_. This file can be used to
23+
authenticate to Google Cloud Platform services from any environment. To use
24+
the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to
25+
the path to the key file, for example:
26+
27+
.. code-block:: bash
28+
29+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
30+
31+
.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
32+
.. _gce-auth: https://cloud.google.com/compute/docs/authentication#using
33+
.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Install Dependencies
2+
++++++++++++++++++++
3+
4+
#. Install `pip`_ and `virtualenv`_ if you do not already have them.
5+
6+
#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
7+
8+
.. code-block:: bash
9+
10+
$ virtualenv env
11+
$ source env/bin/activate
12+
13+
#. Install the dependencies needed to run the samples.
14+
15+
.. code-block:: bash
16+
17+
$ pip install -r requirements.txt
18+
19+
.. _pip: https://pip.pypa.io/
20+
.. _virtualenv: https://virtualenv.pypa.io/

storage/api/README.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)