Skip to content
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

Implement ability to limit module documentation building #24576

Merged
merged 4 commits into from Aug 4, 2017

Conversation

azaghal
Copy link
Contributor

@azaghal azaghal commented May 13, 2017

SUMMARY

The purpose of this pull request is to introduce option for limiting which module documentation gets built. Implementation achieves this via MODULES environment variable that can get passed-in to make webdocs.

The reason for this change is to allow both module developers and documentation contributors to more quickly see and test their changes. Building entire documentation for all modules can take quite a while, and it deters from fixing small syntax, typos and similar errors.

ISSUE TYPE
  • Docs Pull Request
COMPONENT NAME

Documentation build system

ANSIBLE VERSION
ansible 2.4.0 (doc_module_selection 7b6dd1f4d0) last updated 2017/05/13 13:43:50 (GMT +200)
  config file = 
  configured module search path = [u'REDACTED', u'/usr/share/ansible/plugins/modules']
  ansible python module location = REDACTED
  executable location = REDACTED
  python version = 2.7.12 (default, Dec 13 2016, 14:29:11) [GCC 4.9.3]
ADDITIONAL INFORMATION

In order to test the change, you can do the following:

cd docs/docsite/

# Build documentation for apt module.
MODULES=apt make webdocs

# Build documentation for a couple of modules.
MODULES=apt,setup,yum make webdocs

# Don't build documentation for modules.
MODULES=none make webdocs

# Build documentation for all modules.
MODULES=all make webdocs
make webdocs

@ansibot
Copy link
Contributor

ansibot commented May 13, 2017

The test ansible-test sanity --test pep8 failed with the following error:

docs/bin/plugin_formatter.py:203:161: E501 line too long (163 > 160 characters)

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented May 13, 2017

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 ci_verified Changes made in this PR are causing tests to fail. docs_pull_request needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_triage Needs a first human triage before being processed. labels May 13, 2017
- Added new option to plugin_formatter.py to support passing-in a list of
  modules for which the documentation should be built.
- Updated docuemtnation Makefile to allow specifying list of modules via
  environment variables (defaulting to all modules).
- Update instructions for building documentation and module development to
  include commands and description of limiting module documentation builds.
@azaghal
Copy link
Contributor Author

azaghal commented May 13, 2017

Ok, next time I should run the sanity test myself :P

@ansibot ansibot removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels May 13, 2017
@gundalow gundalow removed the needs_triage Needs a first human triage before being processed. label May 13, 2017
Copy link
Contributor

@dharmabumstead dharmabumstead left a comment

Choose a reason for hiding this comment

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

Fantastic - thanks @azaghal!

@dharmabumstead
Copy link
Contributor

Looks good to me. Someone from the core team please review and merge if no issues.

@bcoca
Copy link
Member

bcoca commented May 18, 2017

making it a 'limit' but also forcing to specify seem counter indicative, I would either rename to 'list' or would default to None/absent and filter against list if it is passed in.

Also i would make into list on args parsing, not in the function that is rendering.

other than that minutia, looks good

@@ -125,12 +125,13 @@ def write_data(text, options, outputname, module):
#####################################################################################


def list_modules(module_dir, depth=0):
def list_modules(module_dir, depth=0, limit_to_modules="all"):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would make limit_to_modules arg a list here, and do the comma split on the cli arg before calling list_modules.

(currently it looks this would do odd things if attempting to build module docs for a module with a name like 'ec2_vps_cwt_jkg_none_facts' or 'firewalld' or 'easy_install'? Haven't tested though so that may be covered...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

limit_to_modules is currently supposed to be comma-separated string, so modules with mentioned names should not be a problem.

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'll see what I can do to switch to lists and conditionals. One problem is my Makefile expertise is virtually non-existent (and don't have much time/will to learn it atm :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm... Another thing is how to specify "no modules" at all. I.e. without using the "all" or "none" keywords? Or would it be ok to preserve a variant where value of all or none means that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sheesh... So, before I get any deeper into this, the limit_to_modules parameter received after option parser is invoked should end-up producing one of the following values:

  • None - no limitation, default if option is not specified.
  • [] - don't build any modules. This should be set if you specify special keyword - --limit-to-modules none.
  • ['a', 'b', 'c'] - build only specified module. This should be set if you specify --limit-to-modules a,b,c.

Three ways that I can see to go around this (with one simply not working):

  1. Massage option value after call to (options, args) = p.parse_args().

  2. Add a new type to option parser.

  3. Use callback, but this won't work since we need to set type, and there is no list type (plus, we need list + None type in this particular case I guess).

Preferences? Or am I just overcomplicating this?

- Pass list of modules (or None) to list_modules function instead of string.
- Move conversion of module list to argument parsing code.
- No special keywords. Default ("") means build all modules. For no modules just
  specify non-existing module name.
- Updated documentation to reflect the changes.
@azaghal
Copy link
Contributor Author

azaghal commented May 18, 2017

Ok, updated the pull request based on comments from review (gave-up on complicated solution :).

@@ -194,6 +197,8 @@ def generate_parser():
p.add_option("-v", "--verbose", action='store_true', default=False, help="Verbose")
p.add_option("-o", "--output-dir", action="store", dest="output_dir", default=None, help="Output directory for module files")
p.add_option("-I", "--includes-file", action="store", dest="includes_file", default=None, help="Create a file containing list of processed modules")
p.add_option("-l", "--limit-to-modules", action="store", dest="limit_to_modules", default="",
Copy link
Member

Choose a reason for hiding this comment

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

making None the default saves you some code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, right... Was playing around with setting type, and that one did not like None. Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually... I don't think it does, but I will fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed again.

- Use better default value, and don't treat "" as special case.
- Conditionally invoke different variants of command in Makefile instead of
  using special value "".
mod_info, categories, aliases = list_modules(options.module_dir)
# Convert passed-in limit_to_modules to None or list of modules.
if options.limit_to_modules is not None:
options.limit_to_modules = [s.lower() for s in options.limit_to_modules.split(",")]
Copy link
Contributor

Choose a reason for hiding this comment

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

dont reassign options.limit_to_modules, just created a new limit_to_modules var

if options.limit_to_modules is not None:
    limit_to_modules = [s.lower() for s in options.limit_to_modules.split(",")]

mod_info, categories, aliases = list_modules(options.module_dir, limit_to_modules=limit_to_modules)

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't block on this but stylewise, I do agree with alikins that it's better to do all modifications of things in options inside of the argument parsing functions and then set other variables if the code is outside of it. (In my own code I tend to have a parse_options function that would combine generate_parser, validate_options, and also do transformations on the arguments like this. That function would return the options data structure at the end and then I'd try to treat it as immutable thereafter).

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jun 8, 2017
@gundalow
Copy link
Contributor

so @nitzmahone #25313 gives the ability to generate a single non-module html page. Combined with this we can generate any page.

This would save lots of people lots of time, so +1000 from me

@abadger
Copy link
Contributor

abadger commented Jun 19, 2017

+1 for this. Note that running html docs build with a subset of modules can lead to false positive errors (due to modules being able to link to other modules and those other modules perhaps not being present). So you do have to be careful if you add this to some sort of automated testing.

@jhawkesworth
Copy link
Contributor

Likely we don't need #25791 if this gets merged, so cross referencing it.
Would perhaps be nice if this wasn't limited just to modules and you could use it to build a page in the documentation too.

@azaghal
Copy link
Contributor Author

azaghal commented Jun 19, 2017

Given that #25313 got merged, not sure this pull request is relevant? I actually thought I had closed it already :)

@gundalow
Copy link
Contributor

What's the plan for this & #25791
Looks like we are very close to amazingness, just need to get the ability to build a single module done and then update the docs.

@azaghal
Copy link
Contributor Author

azaghal commented Jun 28, 2017

Well, at least I have no idea what the plans are. I took a bit different approach compared to #25313, more centered around modules. For what it's worth, my patch is faster on initial build (since processing of most modules is skipped). Otherwise, the other approach covers everything (minus the docs :)

@jhawkesworth
Copy link
Contributor

I updated #25791 with docs and shellcheck fixes now.
I just wanted an easy-to-remember command I could run to build a bit of the docs as a full build of the docs takes longer than my daily train journey. No objection to making ansible-makepage.sh faster though, if it gets accepted.

make webdocs` instead. This should make testing module documentation syntax much
faster. Instead of a single module, you can also specify a comma-separated list
of modules. In order to skip building documentation for all modules, specify
non-existing module name, for example `MODULES=none make webdocs`.
Copy link
Member

Choose a reason for hiding this comment

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

I recommend passing vars as args in all new make examples. Example: make webdocs MODULES=none

Also, use a non-existent module name instead of non-existing module name.

Not a blocker, just a suggestion to improve readability. If you do change it, update all new occurrences.

@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@gundalow
Copy link
Contributor

We've agreed to go with this and close #25791

Wording tweak
Copy link
Contributor

@dharmabumstead dharmabumstead left a comment

Choose a reason for hiding this comment

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

Docs OK with some minor edits. Can't wait to implement this. Thanks @azaghal!

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jun 30, 2017
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jul 18, 2017
@azaghal
Copy link
Contributor Author

azaghal commented Jul 19, 2017

Sorry for late reply (as usual...), but going through my mail backlog :)

Should I continue in the same direction, probably just double-checking on reviews? I am happy to invest time as long as it's not a dead (or super-prolonged) end :)

@dharmabumstead dharmabumstead merged commit f78baa1 into ansible:devel Aug 4, 2017
@dharmabumstead
Copy link
Contributor

Thanks very much @azaghal!

@azaghal
Copy link
Contributor Author

azaghal commented Aug 11, 2017

Oh, no changes needed in the end? Great, I hope it will help people :)

@ansibot ansibot added docs This issue/PR relates to or includes documentation. and removed docs_pull_request labels Mar 4, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 docs This issue/PR relates to or includes documentation. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants