Generate reference from snapcraft's "help" command. #318

Merged
merged 1 commit into from Feb 23, 2016

Conversation

Projects
None yet
5 participants
Contributor

dholbach commented Feb 11, 2016

Run:

  ./snapcraft/scripts/generate_reference.py

or

  ./snapcraft/scripts/generate_reference.py --output-file=/tmp/something.md

LP: #1544540

Contributor

dholbach commented Feb 11, 2016

This is just a first cut to get an idea of you generally like the idea. Having submitted this I wonder if I shouldn't generate just one docs/reference.md file with an auto-generated ToC instead...

Contributor

dholbach commented Feb 11, 2016

Ah... maybe I should explain the rationale for this: it'd be great if (once the md importer for developer.u.c finally lands) we could show an automatically updated reference without having to duplicate this information.

Contributor

dholbach commented Feb 11, 2016

I changed it to only write to one file.

Let me know if you want me to break out the functionality into a separate file outside setup.py.

@dholbach dholbach changed the title from First cut of generating help from snapcraft's "help" command. to Generate reference from snapcraft's "help" command. Feb 11, 2016

setup.py
+ self._write_index_doc()
+
+ def _write_index_doc(self):
+ text = '''
@sergiusens

sergiusens Feb 15, 2016

Collaborator

Use three """ instead, also, maybe call this text_template or something... @elopio will have ideas wrt to consistency on this one.

Collaborator

sergiusens commented Feb 15, 2016

I am 👍 but would like @elopio to give a final ack.

thanks for this improvement!!!!

setup.py
+def _get_help_output(topic, lines=False):
+ TRANSLATE = {
+ 'tar-content': 'tar_content',
+ }
@elopio

elopio Feb 15, 2016

Member

Does this apply to all the topics with a dash? If so, you could just replace the dash.

@dholbach

dholbach Feb 16, 2016

Contributor

Right now it's the only one and I thought I'd rather make this explicit than just changing anything which comes up with a dash.

setup.py
+
+
+def _run_snapcraft(cmd, lines=False):
+ cmd = ['./bin/snapcraft']+cmd
@elopio

elopio Feb 15, 2016

Member

pep8 doesn't check this file, which is probably a bug. You should use spaces between the operators:
cmd = ['./bin/snapcraft'] + cmd

setup.py
+def _run_snapcraft(cmd, lines=False):
+ cmd = ['./bin/snapcraft']+cmd
+ command = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ output = command.communicate()[0]
@elopio

elopio Feb 15, 2016

Member

why don't you use subprocess.check_output here?

setup.py
+ output = command.communicate()[0]
+
+ if sys.version_info.major == 3:
+ output = output.decode('utf-8') # bytes to str
@elopio

elopio Feb 15, 2016

Member

I think I would prefer just to ignore python2. @sergiusens do you know if there's a good reason to keep this check?

@dholbach

dholbach Feb 16, 2016

Contributor

We might run this on developer.u.c where I don't know which python versions are available.

@dholbach

dholbach Feb 17, 2016

Contributor

I removed the python2-ism. We have python3 available.

setup.py
+
+ def run(self):
+ assert os.getcwd() == os.path.abspath(os.path.dirname(__file__)), \
+ 'Must be run in snapcraft root.'
@elopio

elopio Feb 15, 2016

Member

This might be confusing. Root is also the user. So maybe:
'Must be run in the root directory of snapcraft.'

Member

elopio commented Feb 15, 2016

I like the idea. I don't like that it's in the setup.py.
Could we move it to something like snapcraft/scripts/generate_reference.py ?

Can one of the admins verify this patch?

Can one of the admins verify this patch?

Can one of the admins verify this patch?

Contributor

dholbach commented Feb 16, 2016

I hope it's all fine now.

Member

elopio commented Feb 16, 2016

Looks good. Your replies make a lot of sense, and thanks for moving it.
Now that you are inside the snapcraft, the static tests will check the script. (it was a trap! :)
Travis is giving this error:
snapcraft/scripts/generate_reference.py:38:9: E128 continuation line under-indented for visual indent

Generate reference from snapcraft's "help" command.
Run:

  ./snapcraft/scripts/generate_reference.py

or

  ./snapcraft/scripts/generate_reference.py -O /tmp/something.md

LP: #1544540
Contributor

dholbach commented Feb 17, 2016

It's fixed now.

Member

elopio commented Feb 17, 2016

add to whitelist

Contributor

dholbach commented Feb 18, 2016

What does "add to whitelist" mean? Do I need to do anything?

Member

kyrofa commented Feb 19, 2016

@dholbach I think he's experimenting with the bot.

Member

elopio commented Feb 23, 2016

retest this please

Can one of the admins verify this patch?

Member

elopio commented Feb 23, 2016

landing...

elopio added a commit that referenced this pull request Feb 23, 2016

Merge pull request #318 from dholbach/add-doc-command
Generate reference from snapcraft's "help" command.

@elopio elopio merged commit c76afe7 into snapcore:master Feb 23, 2016

3 checks passed

Examples tests Success 13 tests run, 0 skipped, 0 failed.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.2%) to 93.761%
Details

@dholbach dholbach deleted the dholbach:add-doc-command branch Feb 24, 2016

smoser pushed a commit to smoser/snapcraft that referenced this pull request Sep 14, 2016

kalikiana pushed a commit to kalikiana/snapcraft that referenced this pull request Apr 6, 2017

Merge pull request #318 from dholbach/add-doc-command
Generate reference from snapcraft's "help" command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment