Skip to content

Add basic readme generator #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 20, 2016
Merged

Add basic readme generator #580

merged 3 commits into from
Oct 20, 2016

Conversation

theacodes
Copy link
Contributor

(Only used for storage, but once in I'll start adding other products)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 13, 2016
@theacodes
Copy link
Contributor Author

/cc @jmdobry

@jerjou
Copy link
Contributor

jerjou commented Oct 13, 2016

  • We don't want this to be part of dpebot's functionality? Seems a bit meta to put into the repo itself
  • rst > md?

@theacodes
Copy link
Contributor Author

We don't want this to be part of dpebot's functionality? Seems a bit meta to put into the repo itself

Nah, at least not for now. The templates and generator are pretty python-specific right now. DPEbot could handle running nox -s readmegen on a schedule and sending PRs as needed.

rst > md?

Many Python projects use rst and github supports both (yay). I personally prefer rst.

Copy link
Contributor

@jerjou jerjou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine, technically (though you might want to add tests, if we're going to be using this extensively).

I'm concerned that this is overengineering the problem, though. eg what are the pros and cons of this approach, vs having a template directory that you can copy and modify when you create a new sample?

My take:

  • Pro: common templates for auth, setup - easier management for commonly-repeated instructions
  • Con: Another management system to learn and maintain

It sort of feels like this is a tool to make github READMEs into a CMS...

@@ -320,3 +320,12 @@ def mark_if_necessary(requirement):
for requirement in sorted(requirements, key=lambda s: s.lower()):
if not requirement.startswith('#'):
f.write(requirement)


def session_readmegen(session):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...read-memegen 😏

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

def session_readmegen(session):
session.install('-r', 'testing/requirements-dev.txt')

in_files = list(list_files('.', 'README.rst.in'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a .yaml extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.in indicates that the file is used to generate the file of the same name before it, so README.rst.in -> README.rst, whereas README.yaml.in -> README.yaml.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh - I meant README.rst.yaml to make clear that it's a yaml file (and for syntax highlighting, etc). The fact that it's an input to the resulting rst would be implied.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think .in is clearer that it's used exclusively for generating the README.rst file, but I'm happy to be disagreed with. @waprin, thoughts?

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A module-level docstring would be nice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a simple one for now.

@@ -0,0 +1,63 @@
#!/usr/bin/env python

# Copyright (C) 2013 Google Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2016

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

loader=jinja2.FileSystemLoader(
os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates'))))

README_TMPL = jinja_env.get_template('README.tmpl.rst')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: we could adopt the rails convention of ordering the file extensions by processing order? ie README.rst.jinja2, where it'd get processed by jinja2 first, then as an rst

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh.

@@ -0,0 +1,60 @@
.. This file is automatically generated. Do not edit this file directly.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly add a jinja2 comment that's like:

{# The following line is a lie. BUT! Once jinja2 is done with it, it will become truth! #}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (verbatim)

nox --stop-on-first-error -s lint travis;
source ${TRAVIS_BUILD_DIR}/testing/test-env.sh;
export GOOGLE_APPLICATION_CREDENTIALS=${TRAVIS_BUILD_DIR}/testing/service-account.json
nox --stop-on-first-error -s lint travis;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a purist if you want to sneak this in there, but it does look like this should be a separate PR? Or is this somehow related and I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I need to rebase. Just consider this part of the diffbase.

@waprin
Copy link
Contributor

waprin commented Oct 14, 2016

Overall very nice idea, writing the README is a pain and good to standardize on our texts etc. Might be helpful to add a quick usage doc on using the README generator?

Change-Id: I53b753fb7e422161b443cd6d96df9501a7b37ab4
@theacodes
Copy link
Contributor Author

theacodes commented Oct 14, 2016

I'm concerned that this is overengineering the problem, though. eg what are the pros and cons of this approach, vs having a template directory that you can copy and modify when you create a new sample?

The pros of this approach is knowing that everything is always consistent. The cons of course are that it is a bit over-engineered and might be hard to maintain down the road, and it might be difficult to accommodate special situations (like speech's portaudio dependency). If we just have a template directory we will inevitably forget to update READMEs after their initial creation.

I could also go the other direction, like we did with auto-docs-links. Instead of this generating READMEs, it could just fill in sections of READMEs automatically:

README.rst

Blah Blah Blah

<!-- include: auth --><!-- end -->
<!-- include: install_deps --><!-- end -->

Then when you run the generator/filler:

Blah Blah Blah

<!-- include: auth -->
Blah Blah
<!-- end -->

<!-- include: install_deps -->
Blah Blah
<!-- end -->

Might be helpful to add a quick usage doc on using the README generator?

Let me get it working across several more samples and then I'll add a README.rst to the README generator. ;)

@pfritzsche
Copy link
Contributor

yo dawg

@theacodes
Copy link
Contributor Author

@pfritzsche should readme-gen generate its own readme and read memegen at once?

Change-Id: I67bd8a38f39feb78c669c4e5b25e0293094c10be
++++++++++++++

Authentication is typically done through `Application Default Credentials`_,
this means you do not have to change the code to authenticate as long as
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sentence fragment. Consider:

Authentication is typically done through Application Default Credentials, which...

instead of "this"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@jerjou jerjou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*shrug
Have at it!

def session_readmegen(session):
session.install('-r', 'testing/requirements-dev.txt')

in_files = list(list_files('.', 'README.rst.in'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh - I meant README.rst.yaml to make clear that it's a yaml file (and for syntax highlighting, etc). The fact that it's an input to the resulting rst would be implied.

Change-Id: Ie33893bd2a1f36a34ab7dbb14c01425c9d0eebb5
@theacodes
Copy link
Contributor Author

@jerjou thanks! I'd like to see how @waprin thinks about it first.

@theacodes
Copy link
Contributor Author

@waprin ping?


.. code-block:: bash

gcloud beta auth application-default login
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think the command is out of beta

samples:
- name: Snippets
file: snippets.py
show_help: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe show_help defaults to true?

@waprin
Copy link
Contributor

waprin commented Oct 18, 2016

LGTM

@theacodes theacodes merged commit 530ab8a into master Oct 20, 2016
@theacodes theacodes deleted the readme-script branch October 20, 2016 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants