Klaus: Extend Readme discovery via environment variable

12 views
Skip to first unread message

Ariana Giroux

unread,
May 31, 2020, 8:38:30 PM5/31/20
to klaus...@googlegroups.com, ariana...@gmail.com
As of version 1.5.2, the software relies on a hardcoded list of
acceptable readme filenames. This is inconvienient to users who do not
use naming conventions provided within the aforementioned list. This
patch provides a simple enviornment variable based approach to
extending that list via the variable 'KLAUS_README_FILENAMES'.

This could save users a lot of hassle, as I for one ended up refactoring
a plethora of repos because I didn't use a supported naming convention.


Ariana Giroux

unread,
May 31, 2020, 8:38:31 PM5/31/20
to klaus...@googlegroups.com, ariana...@gmail.com
- Adds a new environment variable for expanding the list of known readme
filenames. Now, the user can set 'KLAUS_README_FILENAMES' to a space
separated list of filenames to add to the search space.

- Also enforces strict PEP8 adherance in klaus.views.
---
klaus/views.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/klaus/views.py b/klaus/views.py
index 6fafdd1..73c5e63 100644
--- a/klaus/views.py
+++ b/klaus/views.py
@@ -13,6 +13,7 @@ import dulwich.archive
import dulwich.config
from dulwich.object_store import tree_lookup_path

+
try:
import ctags
except ImportError:
@@ -29,6 +30,16 @@ from klaus.utils import parent_directory, subpaths, force_unicode, guess_is_bina

README_FILENAMES = [b'README', b'README.md', b'README.mkdn', b'README.mdwn', b'README.markdown', b'README.rst']

+# If 'KLAUS_README_FILENAMES' is defined on the command line, then we can
+# attempt to append the provided data to our list of filenames.
+# For example:
+#
+# $ export KLAUS_README_FILENAMES='readme.rst readme.md readme.txt'
+#
+# Will add b'readme.rst', b'readme.md', and b'readme.txt' to the list.
+if list(os.environb).count(b'KLAUS_README_FILENAMES'):
+ README_FILENAMES += os.environb[b'KLAUS_README_FILENAMES'].split()
+

def repo_list():
"""Show a list of all repos and can be sorted by last update."""
@@ -44,7 +55,6 @@ def repo_list():
order_by=order_by, base_href=None)


-
def robots_txt():
"""Serve the robots.txt file to manage the indexing of the site by search engines."""
return current_app.send_static_file('robots.txt')
@@ -280,7 +290,7 @@ class IndexView(TreeViewMixin, BaseRepoView):
'rendered_code': None,
})
else:
- readme_filename = force_unicode(readme_filename)
+ readme_filename = force_unicode(readme_filename)
readme_data = force_unicode(readme_data)
self.context.update({
'is_markup': markup.can_render(readme_filename),
--
2.17.1

Jonas Haag

unread,
Jun 4, 2020, 4:48:58 AM6/4/20
to klaus...@googlegroups.com
Hi Ariana, thanks for the patch, will review shortly!

Jonas
> --
> You received this message because you are subscribed to the Google Groups "klaus-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to klaus-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/klaus-users/20200601003824.32238-2-ariana.giroux%40gmail.com.

Jonas Haag

unread,
Jun 7, 2020, 5:40:06 AM6/7/20
to klaus...@googlegroups.com
I think making this list dynamic is not worth the added complexity. I’d rather add the naming convention you were using to klaus.
> To view this discussion on the web visit https://groups.google.com/d/msgid/klaus-users/B02F5E3A-67CC-4D09-9FC2-85C24CA7E8E1%40lophus.org.

Reply all
Reply to author
Forward
0 new messages