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

Use exclude keyword to skip markdown files #1370

Merged
merged 4 commits into from
Jan 5, 2018

Conversation

brandongc
Copy link
Contributor

This change slightly modifies the functionality of the copy_media_files() function by changing the behavior of the unused exclude option to be a list extensions rather than a list of Unix shell patterns.

This function is only called in mkdocs/commands/build.py and does not use the functionality.

I also add a variable to define markdown extensions in a single place.

This change will greatly simplify life for a plugin developer who wishes to reused this functionality (namely me).

So my plugin to copy markdown files can simply consist of:

utils.copy_media_files(config['docs_dir'], config['site_dir'], exclude = [], dirty=True)

in a post_build event.

I understand this may get rejected as there is a private refactor in progress for the next release, but please consider allowing for a similarly flexible util function in the future.

@waylan
Copy link
Member

waylan commented Jan 4, 2018

First of all, exclude is not unused (see build.pyL276). It serves a very important function for themes that relies on Unix shell patterns (note that we are passing in more than file extensions). Apparently, we are not properly testing that as no tests are failing with your changes.

Second, why would you want to switch from the more powerful Unix shell patterns to file extensions only? That would be a regression to a less powerful solution.

That said, having Markdown extensions defined in one place makes sense. And using the exclude keyword to skip Markdown files seems like it could be a reasonable compromise. I might consider that change as long as we keep support for Unix shell patterns.

@brandongc
Copy link
Contributor Author

Strange that I missed that call with grep - possibly due to it being multiline.

For the change away from patterns there is no motivation other than it appeared unused and was convenient for passing a list of extensions.

Some design choices:

  • Is it acceptable for exclude=['.ext'] to be interpreted as exclude=['*.ext']?

    If yes then I can add the logic for that to the copy_media_files().

    If no I can change markdown_extensions=[] to a list of shell patterns instead of extensions and change utils.is_markdown_file() accordingly.

  • Is having a default exclude=markdown_extensions ok?

@brandongc brandongc changed the title refactor unused exclude option Use exclude keyword to skip markdown files Jan 4, 2018
@brandongc
Copy link
Contributor Author

The failed test is pip install codecov timing out

@brandongc brandongc force-pushed the make-utils-friendly-for-plugins branch from ecc395b to a3e15d7 Compare January 4, 2018 18:00
Copy link
Member

@waylan waylan left a comment

Choose a reason for hiding this comment

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

Looks good. Just a few suggested changes and I would be happy to accept this.

'*.mkdn',
'*.mkd',
'*.md'
]
Copy link
Member

Choose a reason for hiding this comment

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

Let's leave these as "extensions" (and call them that).

@@ -145,11 +153,12 @@ def clean_directory(directory):
os.unlink(path)


def copy_media_files(from_dir, to_dir, exclude=None, dirty=False):
def copy_media_files(from_dir, to_dir, exclude=markdown_patterns, dirty=False):
Copy link
Member

Choose a reason for hiding this comment

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

Here you can use a list comprehension to convert the list of extensions to patterns:

 exclude=['*{0}'.format(x) for x in markdown_extensions]

'.mkd',
'.md',
]
return any(fnmatch.fnmatch(ext, pattern) for pattern in markdown_patterns)
Copy link
Member

Choose a reason for hiding this comment

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

I like this, but I don't think we need to break out the extension from the path. Just pass path to fnmatch and remove line 232.

Copy link
Member

@waylan waylan Jan 4, 2018

Choose a reason for hiding this comment

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

Or, leave it unchanged as we have a list of extensions, not patterns. It probably should come down to which is more performant. If fnmatch is fast enough, then converting the extensions to patterns for each call might not matter. Otherwise, don't use fnmatch here.

@waylan
Copy link
Member

waylan commented Jan 4, 2018

I restarted the timed-out job on Travis and it is good now.

Copy link
Member

@waylan waylan left a comment

Choose a reason for hiding this comment

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

Sorry I missed this before, but could you add an entry to the release notes? Just add a new section above the most recent release titled "Development Version" followed by a list item briefly summarizing this change and referencing this PR. Similar to what was done here. Thanks.

Otherwise, it looks good.

@waylan waylan merged commit d00a8e5 into mkdocs:master Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants