internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: getpelican/pelican

Issue:
Setting default summary length = 0
I want to disable the default article summary, and only show one if defined in the article metadata. I assumed this would be done with:

```
SUMMARY_MAX_LENGTH = 0
```

But this has the same effect as `SUMMARY_MAX_LENGTH = None`, meaning all content is shown. It does work however by setting a negative value:

```
SUMMARY_MAX_LENGTH = -1
```

I don't know if this is a bug or a feature. If it's a feature, it's probably good to document it. If it's a bug, setting to `0` would in my opinion the most logical way to disable default summaries.



Discussion:
Yeah it would probably make more sense if the functionality of `SUMMARY_MAX_LENGTH = 0` and `SUMMARY_MAX_LENGTH = -1` were swapped.

So `SUMMARY_MAX_LENGTH = 0` would disable implicit summaries and `SUMMARY_MAX_LENGTH = -1`  would use all content for implicit summaries.

Thanks for your reply. In your proposal, what would `SUMMARY_MAX_LENGTH = None` mean? Would you drop support for this?

I would suggest:

```
SUMMARY_MAX_LENGTH = 30 # Unless summary is specified in content, set summary to 30 words.
SUMMARY_MAX_LENGHT = 0 # Unless summary is specified in content, set summary to 0 words (= no default summary)
SUMMARY_MAX_LENGTH = None # Unless summary is specified in content, set no limit on summary (= use content as summary)
```

If that's not possible for technical reasons (e.g. if `None` means the same as `0`), we could indeed use `SUMMARY_MAX_LENGTH = -1` instead of `=None`.


Resolving patch:
diff --git a/pelican/contents.py b/pelican/contents.py
--- a/pelican/contents.py
+++ b/pelican/contents.py
@@ -231,10 +231,11 @@ def _get_summary(self):
         if hasattr(self, '_summary'):
             return self._summary
 
-        if self.settings['SUMMARY_MAX_LENGTH']:
-            return truncate_html_words(self.content,
-                    self.settings['SUMMARY_MAX_LENGTH'])
-        return self.content
+        if self.settings['SUMMARY_MAX_LENGTH'] is None:
+            return self.content
+
+        return truncate_html_words(self.content,
+                self.settings['SUMMARY_MAX_LENGTH'])
 
     def _set_summary(self, summary):
         """Dummy function"""


Test patch:
diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py
--- a/pelican/tests/test_contents.py
+++ b/pelican/tests/test_contents.py
@@ -71,6 +71,9 @@ def test_summary_max_length(self):
         settings['SUMMARY_MAX_LENGTH'] = 10
         page = Page(**page_kwargs)
         self.assertEqual(page.summary, truncate_html_words(TEST_CONTENT, 10))
+        settings['SUMMARY_MAX_LENGTH'] = 0
+        page = Page(**page_kwargs)
+        self.assertEqual(page.summary, '')
 
     def test_slug(self):
         # If a title is given, it should be used to generate the slug.
Repository: getpelican/pelican

Issue:
Exception on WP import looking for <pre> tag
Another quick one.  In `decode_wp_content()`:

``` python
start = pre_part.index("<pre")
```

should be:

``` python
start = pre_part.find("<pre")
```

because the next line checks for `start == -1`, but `index()` throws `ValueError` when the value can't be found, whereas `find()` returns -1.

I can send a PR for this tomorrow, but wanted to make sure I reported it tonight.



Discussion:
Thanks for the report (and hopefully an eventual fix). Instead of submitting a separate pull request, please use the "hub pull-request" command to attach your code to this existing issue. See our Contributing section for more details: http://docs.getpelican.com/en/latest/contribute.html#contribution-submission-guidelines


Resolving patch:
diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py
--- a/pelican/tools/pelican_import.py
+++ b/pelican/tools/pelican_import.py
@@ -37,7 +37,7 @@ def decode_wp_content(content, br=True):
         pre_index = 0
 
         for pre_part in pre_parts:
-            start = pre_part.index("<pre")
+            start = pre_part.find("<pre")
             if start == -1:
                 content = content + pre_part
                 continue


Test patch:
Repository: getpelican/pelican

Issue:
pelican-quickstart: error with accented characters
Hello,

I've got a problem with pelican-quickstart, when I put accented characters in answers.

Here is the output I got : 

> Who will be the author of this web site? Guillaume LAMÉ
> Traceback (most recent call last):
>   File "/home/lomig/StaticGen/Pelican/bin/pelican-quickstart", line 9, in <module>
>     load_entry_point('pelican==3.2.1', 'console_scripts', 'pelican-quickstart')()
>   File "/home/lomig/StaticGen/Pelican/local/lib/python2.7/site-packages/pelican/tools/pelican_quickstart.py", line 184, in main
>     CONF['author'] = ask('Who will be the author of this web site?', answer=str_compat, default=args.author)
>   File "/home/lomig/StaticGen/Pelican/local/lib/python2.7/site-packages/pelican/tools/pelican_quickstart.py", line 57, in wrapper
>     return out.decode(sys.stdin.encoding)
>   File "/home/lomig/StaticGen/Pelican/lib/python2.7/encodings/utf_8.py", line 16, in decode
>     return codecs.utf_8_decode(input, errors, True)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xc9' in position 13: ordinal not in range(128)

Thanks.



Discussion:

Resolving patch:
diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py
--- a/pelican/tools/pelican_quickstart.py
+++ b/pelican/tools/pelican_quickstart.py
@@ -37,8 +37,7 @@ def _input_compat(prompt):
     if six.PY3:
         r = input(prompt)
     else:
-        # FIXME: why use this with @decoding_strings?
-        r = raw_input(prompt).decode('utf-8')
+        r = raw_input(prompt)
     return r
 
 if six.PY3:


Test patch:
Repository: getpelican/pelican

Issue:
Can we move deleting output dir to before context generation?
I'm working on getting IPython Notebook images to write out to files when embedding into articles. The issue I'm having is that I write the files out during the context generation phase, which is then deleted via `clean_output`. 

Is it possible to move `clean_output` to above the context generation? AFAIK this won't affect anything. 

``` python
         # erase the directory if it is not the source and if that's
         # explicitely asked
         if (self.delete_outputdir and not
                 os.path.realpath(self.path).startswith(self.output_path)):
             clean_output_dir(self.output_path)

         for p in generators:
             if hasattr(p, 'generate_context'):
                 p.generate_context()
```

To clarify, the images live embedded within the ipython notebook under the content dir. So static paths don't help me here as I don't want the image files under revision control, only the notebook file. 

Thanks!



Discussion:
Sounds good to me. Clean the directory before we start generating sounds logical. :+1: 


Resolving patch:
diff --git a/pelican/__init__.py b/pelican/__init__.py
--- a/pelican/__init__.py
+++ b/pelican/__init__.py
@@ -168,16 +168,16 @@ def run(self):
             ) for cls in self.get_generator_classes()
         ]
 
-        for p in generators:
-            if hasattr(p, 'generate_context'):
-                p.generate_context()
-
         # erase the directory if it is not the source and if that's
         # explicitely asked
         if (self.delete_outputdir and not
                 os.path.realpath(self.path).startswith(self.output_path)):
             clean_output_dir(self.output_path, self.output_retention)
 
+        for p in generators:
+            if hasattr(p, 'generate_context'):
+                p.generate_context()
+
         writer = self.get_writer()
 
         for p in generators:


Test patch:
Repository: getpelican/pelican

Issue:
Issue with import tumblr
Running the command:

> pelican-import --tumblr -o output/ -b name api_key 

returns this result:

Traceback (most recent call last):
  File "/usr/local/bin/pelican-import", line 8, in <module>
    load_entry_point('pelican==3.3', 'console_scripts', 'pelican-import')()
  File "/Library/Python/2.7/site-packages/pelican-3.3-py2.7.egg/pelican/tools/pelican_import.py", line 634, in main
    filter_author=args.author)
  File "/Library/Python/2.7/site-packages/pelican-3.3-py2.7.egg/pelican/tools/pelican_import.py", line 462, in fields2pelican
    kind, in_markup) in fields:
ValueError: need more than 8 values to unpack



Discussion:

Resolving patch:
diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py
--- a/pelican/tools/pelican_import.py
+++ b/pelican/tools/pelican_import.py
@@ -400,8 +400,9 @@ def get_tumblr_posts(api_key, blogname, offset=0):
                 content = '<p><a href="%s" rel="external nofollow">%s</a>: %s</p>\n%s' % (post.get('asking_name'), post.get('asking_url'), post.get('question'), post.get('answer'))
 
             content = content.rstrip() + '\n'
-
-            yield (title, content, slug, date, post.get('blog_name'), [type], tags, format)
+            kind = 'article'
+            yield (title, content, slug, date, post.get('blog_name'), [type],
+                   tags, kind, format)
 
         offset += len(posts)
         posts = get_tumblr_posts(api_key, blogname, offset)


Test patch:
Repository: getpelican/pelican

Issue:
CATEGORIES_URL doesn't honor it's default value
First of all, thanks for this great software. But, when I'm using the variable CATEGORIES_URL in templates (category.html), it doesn't have it's default value (as said on the documentation: CATEGORIES_URL ('categories/')). I need to explicitly set this value in pelican.conf. I'm using Pelican 3.3.0

Thanks



Discussion:

Resolving patch:
diff --git a/pelican/settings.py b/pelican/settings.py
--- a/pelican/settings.py
+++ b/pelican/settings.py
@@ -68,6 +68,8 @@
     'PDF_GENERATOR': False,
     'PDF_STYLE_PATH': '',
     'PDF_STYLE': 'twelvepoint',
+    'CATEGORIES_URL': 'categories.html',
+    'CATEGORIES_SAVE_AS': 'categories.html',
     'CATEGORY_URL': 'category/{slug}.html',
     'CATEGORY_SAVE_AS': os.path.join('category', '{slug}.html'),
     'TAG_URL': 'tag/{slug}.html',


Test patch:
Repository: getpelican/pelican

Issue:
DOCUTILS_SETTINGS not documented nor initialized
DOCUTILS_SETTINGS was introduced in #864, but it has not been documented nor is it initialized in settings.py



Discussion:

Resolving patch:
diff --git a/pelican/settings.py b/pelican/settings.py
--- a/pelican/settings.py
+++ b/pelican/settings.py
@@ -49,6 +49,7 @@
     'SITENAME': 'A Pelican Blog',
     'DISPLAY_PAGES_ON_MENU': True,
     'DISPLAY_CATEGORIES_ON_MENU': True,
+    'DOCUTILS_SETTINGS': {},
     'OUTPUT_SOURCES': False,
     'OUTPUT_SOURCES_EXTENSION': '.text',
     'USE_FOLDER_AS_CATEGORY': True,


Test patch:
Repository: getpelican/pelican

Issue:
No error message for invalid syntax in period_archives.html
I have noticed that my monthly archives are using archives.html template. With some debugger help I understood that whenever there is a syntax error in period_archives.html then no error is shown and archives.html is used instead.

Would be nice to show proper error message when jinja finds existing period_archives.html but cannot process it.

No error message for invalid syntax in period_archives.html
I have noticed that my monthly archives are using archives.html template. With some debugger help I understood that whenever there is a syntax error in period_archives.html then no error is shown and archives.html is used instead.

Would be nice to show proper error message when jinja finds existing period_archives.html but cannot process it.



Discussion:
Hi Artemy. Is something you would like to work on?

Hi Justin. I am not too inspired, knowing my PRs #1408 and #1401 got zero feedback in 50 days.

Ouch. Point taken. Very sorry about that. Will review them now.

Hi Artemy. Is something you would like to work on?

Hi Justin. I am not too inspired, knowing my PRs #1408 and #1401 got zero feedback in 50 days.

Ouch. Point taken. Very sorry about that. Will review them now.


Resolving patch:
diff --git a/pelican/generators.py b/pelican/generators.py
--- a/pelican/generators.py
+++ b/pelican/generators.py
@@ -29,6 +29,9 @@
 logger = logging.getLogger(__name__)
 
 
+class PelicanTemplateNotFound(Exception):
+    pass
+
 @python_2_unicode_compatible
 class Generator(object):
     """Baseclass generator"""
@@ -88,7 +91,7 @@ def get_template(self, name):
             try:
                 self._templates[name] = self.env.get_template(name + '.html')
             except TemplateNotFound:
-                raise Exception('[templates] unable to load %s.html from %s'
+                raise PelicanTemplateNotFound('[templates] unable to load %s.html from %s'
                                 % (name, self._templates_path))
         return self._templates[name]
 
@@ -330,7 +333,7 @@ def generate_period_archives(self, write):
         """Generate per-year, per-month, and per-day archives."""
         try:
             template = self.get_template('period_archives')
-        except Exception:
+        except PelicanTemplateNotFound:
             template = self.get_template('archives')
 
         period_save_as = {


Test patch:
Repository: getpelican/pelican

Issue:
abbr support doesn't work for multiline
Eg:

``` rst
this is an :abbr:`TLA (Three Letter
Abbreviation)`
```

will output
`<abbr>TLA (Three Letter Abbreviation)</abbr>`

instead of
`<abbr title="Three Letter Abbreviation">TLA</abbr>`

I believe this could be fixed by adding the `re.M` flag to the `re.compile` call on this line: https://github.com/getpelican/pelican/blob/636fd6cc380f2537924532a587c70e96a386e25c/pelican/rstdirectives.py#L101

This refs ticket #395 



Discussion:
I'm trying to work out why this is happening. Is this (in terms of docutils) a higher priority than the transform that removes the newlines?

Hi Mattieu and Russ. Would either of you care to work on this and help improve how it's handled?

Sure thing, Captain.

Hi @magopian and @russkel. Just checking in. Would either of you care to work on this issue?


Resolving patch:
diff --git a/pelican/rstdirectives.py b/pelican/rstdirectives.py
--- a/pelican/rstdirectives.py
+++ b/pelican/rstdirectives.py
@@ -70,7 +70,7 @@ def run(self):
 directives.register_directive('sourcecode', Pygments)
 
 
-_abbr_re = re.compile('\((.*)\)$')
+_abbr_re = re.compile('\((.*)\)$', re.DOTALL)
 
 
 class abbreviation(nodes.Inline, nodes.TextElement):


Test patch:
diff --git a/pelican/tests/test_rstdirectives.py b/pelican/tests/test_rstdirectives.py
new file mode 100644
--- /dev/null
+++ b/pelican/tests/test_rstdirectives.py
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals, print_function
+
+from mock import Mock
+from pelican.tests.support import unittest
+
+class Test_abbr_role(unittest.TestCase):
+    def call_it(self, text):
+        from pelican.rstdirectives import abbr_role
+        rawtext = text
+        lineno = 42
+        inliner = Mock(name='inliner')
+        nodes, system_messages = abbr_role(
+            'abbr', rawtext, text, lineno, inliner)
+        self.assertEqual(system_messages, [])
+        self.assertEqual(len(nodes), 1)
+        return nodes[0]
+
+    def test(self):
+        node = self.call_it("Abbr (Abbreviation)")
+        self.assertEqual(node.astext(), "Abbr")
+        self.assertEqual(node['explanation'], "Abbreviation")
+
+    def test_newlines_in_explanation(self):
+        node = self.call_it("CUL (See you\nlater)")
+        self.assertEqual(node.astext(), "CUL")
+        self.assertEqual(node['explanation'], "See you\nlater")
+
+    def test_newlines_in_abbr(self):
+        node = self.call_it("US of\nA \n (USA)")
+        self.assertEqual(node.astext(), "US of\nA")
+        self.assertEqual(node['explanation'], "USA")
Repository: getpelican/pelican

Issue:
Built-in server relies on file name suffix to guess Content-Type
Pelican's built-in web server relies on the standard `SimpleHTTPServer` module to guess the appropriate `Content-Type` header for the files it serves. Sadly, that implementation relies on file name suffix to make its guesses. When I configure my site to use URLs without suffixes...

```
'PAGE_URL': 'pages/{slug}'
```

...the server sends `Content-Type: application/octet-stream`, and my browser refuses to render the HTML.

This could be better, at least on systems that have the python-magic package installed.



Discussion:

Resolving patch:
diff --git a/pelican/server.py b/pelican/server.py
--- a/pelican/server.py
+++ b/pelican/server.py
@@ -12,6 +12,11 @@
 except ImportError:
     import socketserver  # NOQA
 
+try:
+    from magic import from_file as magic_from_file
+except ImportError:
+    magic_from_file = None
+
 PORT = len(sys.argv) in (2, 3) and int(sys.argv[1]) or 8000
 SERVER = len(sys.argv) == 3 and sys.argv[2] or ""
 SUFFIXES = ['', '.html', '/index.html']
@@ -39,6 +44,18 @@ def do_GET(self):
             logging.warning("Unable to find `%s` or variations.",
                             self.original_path)
 
+    def guess_type(self, path):
+        """Guess at the mime type for the specified file.
+        """
+        mimetype = srvmod.SimpleHTTPRequestHandler.guess_type(self, path)
+
+        # If the default guess is too generic, try the python-magic library
+        if mimetype == 'application/octet-stream' and magic_from_file:
+            mimetype = magic_from_file(path, mime=True)
+
+        return mimetype
+
+
 Handler = ComplexHTTPRequestHandler
 
 socketserver.TCPServer.allow_reuse_address = True


Test patch:
Repository: getpelican/pelican

Issue:
Excluding Pages from DEFAULT_METADATA
When I set the following in pelicanconf.py:

```
DEFAULT_METADATA = {
    'status': 'draft',
}
```

My pages break:

```
ERROR: Unknown status 'Published' for file pages/about.md, skipping it.
```

In `PATH` I have the directories 'pages' and 'posts'. I attempted to fix this by explicitly setting:

```
ARTICLE_PATHS = ['posts']
PAGE_PATHS = ['pages']
```

However this still generates the same errors for pages. Any suggestions?

Excluding Pages from DEFAULT_METADATA
When I set the following in pelicanconf.py:

```
DEFAULT_METADATA = {
    'status': 'draft',
}
```

My pages break:

```
ERROR: Unknown status 'Published' for file pages/about.md, skipping it.
```

In `PATH` I have the directories 'pages' and 'posts'. I attempted to fix this by explicitly setting:

```
ARTICLE_PATHS = ['posts']
PAGE_PATHS = ['pages']
```

However this still generates the same errors for pages. Any suggestions?



Discussion:
I tested this locally, and it seems like you need to use `Status: published` (it's case-sensitive). That being said, perhaps the status check _should_ be case-insensitive. Thoughts, @justinmayer?

It _should_ be case-insensitive, `ArticlesGenerator` [does that](https://github.com/getpelican/pelican/blob/master/pelican/generators.py#L517). For some odd reason, it was [omitted](https://github.com/getpelican/pelican/blob/master/pelican/generators.py#L644) in `PagesGenerator`. So, this is a bug.

I tested this locally, and it seems like you need to use `Status: published` (it's case-sensitive). That being said, perhaps the status check _should_ be case-insensitive. Thoughts, @justinmayer?

It _should_ be case-insensitive, `ArticlesGenerator` [does that](https://github.com/getpelican/pelican/blob/master/pelican/generators.py#L517). For some odd reason, it was [omitted](https://github.com/getpelican/pelican/blob/master/pelican/generators.py#L644) in `PagesGenerator`. So, this is a bug.


Resolving patch:
diff --git a/pelican/generators.py b/pelican/generators.py
--- a/pelican/generators.py
+++ b/pelican/generators.py
@@ -641,9 +641,9 @@ def generate_context(self):
 
             self.add_source_path(page)
 
-            if page.status == "published":
+            if page.status.lower() == "published":
                 all_pages.append(page)
-            elif page.status == "hidden":
+            elif page.status.lower() == "hidden":
                 hidden_pages.append(page)
             else:
                 logger.error("Unknown status '%s' for file %s, skipping it.",


Test patch:
Repository: getpelican/pelican

Issue:
pelican-quickstart crashes on setting timezone
> What is your time zone? [Europe/Paris] 
> Traceback (most recent call last):
>   File "/usr/bin/pelican-quickstart", line 9, in <module>
>     load_entry_point('pelican==3.5.0', 'console_scripts', 'pelican-quickstart')()
>   File "/usr/lib/python3.4/site-packages/pelican/tools/pelican_quickstart.py", line 225, in main
>     CONF['timezone'] = ask_timezone('What is your time zone?', CONF['timezone'], _TZ_URL)
>   File "/usr/lib/python3.4/site-packages/pelican/tools/pelican_quickstart.py", line 170, in ask_timezone
>     r = pytz.all_timezones[lower_tz.index(r)]
> AttributeError: 'map' object has no attribute 'index'

Version: 3.5.0.r112.g249a919-1, OS: Archlinux



Discussion:
your pytz version?

2014.10-1


Resolving patch:
diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py
--- a/pelican/tools/pelican_quickstart.py
+++ b/pelican/tools/pelican_quickstart.py
@@ -162,7 +162,7 @@ def ask(question, answer=str_compat, default=None, l=None):
 
 def ask_timezone(question, default, tzurl):
     """Prompt for time zone and validate input"""
-    lower_tz = map(str.lower, pytz.all_timezones)
+    lower_tz = [tz.lower() for tz in pytz.all_timezones]
     while True:
         r = ask(question, str_compat, default)
         r = r.strip().replace(' ', '_').lower()


Test patch:
Repository: getpelican/pelican

Issue:
Intra-site links for draft posts
Probably a really low-priority issue: When you link to a file that is currently under `:status: draft`, the links will not work.

```
.. _some href: |filename|my-drafted-article.rst
```

This will create a link to the article as if it was not in the drafts folder. Not a very pressing issue but a little inconsistent.



Discussion:
Hi Florian. Is this something you would be willing to work on and help us improve?

Closing this issue, since there's been no movement on it over the last year.


Resolving patch:
diff --git a/pelican/generators.py b/pelican/generators.py
--- a/pelican/generators.py
+++ b/pelican/generators.py
@@ -525,6 +525,7 @@ def generate_context(self):
                     preread_sender=self,
                     context_signal=signals.article_generator_context,
                     context_sender=self)
+                self.add_source_path(draft)
                 all_drafts.append(draft)
             else:
                 logger.error("Unknown status '%s' for file %s, skipping it.",


Test patch:
Repository: getpelican/pelican

Issue:
-D (debug mode) doesn't show any trackbacks on internal exceptions
Also, exceptions are rendered using `str` instead of `repr`, making this worse than it already is.



Discussion:

Resolving patch:
diff --git a/pelican/__init__.py b/pelican/__init__.py
--- a/pelican/__init__.py
+++ b/pelican/__init__.py
@@ -444,7 +444,7 @@ def _ignore_cache(pelican_obj):
 
                 except Exception as e:
                     if (args.verbosity == logging.DEBUG):
-                        logger.critical(e.args)
+                        logger.critical('Internal failure: %r', e, exc_info=True)
                         raise
                     logger.warning(
                         'Caught exception "%s". Reloading.', e)


Test patch: