internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: getnikola/nikola

Issue:
i18n: Link behind site name/logo is not aware of the current language
The upper-left link always redirect to the “site-wide index” a.k.a. `SITE_URL` (regardless if the site is a blog of a non-blog using a custom index.html and non-null `INDEX_PATH`).

This means that if you are browsing the site in a non-default language, clicking on that link will send you to the home page (that's correct) but will switch you back to the default language (not correct).

That link should send to the "localized index":
- `SITE_URL` for the default language
- `SITE_URL + "/es/"` for non-default language (here with Spanish as an example)



Discussion:
Looking at the templates, the link is generated by the `abs_link` function defined in `nikola/nikola.py`. That function takes `self.config['BASE_URL']`, and optionally appends the content of `dst`
How about adding an extra 2 lines at the beginning of that function that would do (pseudo-code, as I don't know how to determine that the current page is in a non-standard language, assuming here that there would be a `lang_code` variable set with e.g. "/es/"):

```
if lang_code:   # Make the URL aware of the current language
    url = self.config['BASE_URL'] + lang_code
```

And then use the `url` variable instead of `self.config['BASE_URL']` in that first if/else block?


Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -234,6 +234,7 @@ def __init__(self, **config):
         self.path_handlers = {
             'slug': self.slug_path,
             'post_path': self.post_path,
+            'root': self.root_path,
             'filename': self.filename_path,
         }
 
@@ -1093,12 +1094,13 @@ def generic_rss_renderer(self, lang, title, link, description, timeline, output_
     def path(self, kind, name, lang=None, is_link=False):
         """Build the path to a certain kind of page.
 
-        These are mostly defined by plugins by registering via
-        the register_path_handler method, except for slug and
-        post_path which are defined in this class' init method.
+        These are mostly defined by plugins by registering via the
+        register_path_handler method, except for slug, post_path, root
+        and filename which are defined in this class' init method.
 
         Here's some of the others, for historical reasons:
 
+        * root (name is ignored)
         * tag_index (name is ignored)
         * tag (and name is the tag name)
         * tag_rss (name is the tag name)
@@ -1150,6 +1152,14 @@ def post_path(self, name, lang):
                               os.path.dirname(name),
                               self.config['INDEX_FILE']] if _f]
 
+    def root_path(self, name, lang):
+        """root_path path handler"""
+        d = self.config['TRANSLATIONS'][lang]
+        if d:
+            return [d, '']
+        else:
+            return []
+
     def slug_path(self, name, lang):
         """slug path handler"""
         results = [p for p in self.timeline if p.meta('slug') == name]


Test patch:
Repository: getnikola/nikola

Issue:
Cannot deploy after removing cache
Hello,

the deploy command crashes like this:

IOError: [Errno 2] No such file or directory: 'cache/lastdeploy'

Why, yes, of course, I can remove "cache", can't I? Seems I have to "mkdir" it. Also I would like to disable its usage, as the point is unclear to my, using rsync does the trick to me.



Discussion:
`rsync` is _recommended_ by Nikola, but we use this worthless thing for deploy signals (so that they can know what was changed).  An easy fix.


Resolving patch:
diff --git a/nikola/plugins/command/deploy.py b/nikola/plugins/command/deploy.py
--- a/nikola/plugins/command/deploy.py
+++ b/nikola/plugins/command/deploy.py
@@ -36,7 +36,7 @@
 from blinker import signal
 
 from nikola.plugin_categories import Command
-from nikola.utils import get_logger, remove_file, unicode_str
+from nikola.utils import get_logger, remove_file, unicode_str, makedirs
 
 
 class CommandDeploy(Command):
@@ -111,7 +111,7 @@ def _execute(self, command, args):
         new_deploy = datetime.utcnow()
         self._emit_deploy_event(last_deploy, new_deploy, clean, undeployed_posts)
 
-        os.makedirs(self.site.config['CACHE_FOLDER'])
+        makedirs(self.site.config['CACHE_FOLDER'])
         # Store timestamp of successful deployment
         with io.open(timestamp_path, 'w+', encoding='utf8') as outf:
             outf.write(unicode_str(new_deploy.isoformat()))


Test patch:
Repository: getnikola/nikola

Issue:
nikola bootswatch_theme paper installs slate
I seem to be getting an issue when I try to install the [paper](https://bootswatch.com/paper/) theme from bootswatch by running `nikola bootswatch_theme paper`, it seems to install slate instead. 

The output is as follows:

```
$ nikola bootswatch_theme paper
[2015-04-16T00:24:34Z] WARNING: Nikola: Your BASE_URL doesn't end in / -- adding it, but please fix it in your config file!
[2015-04-16T00:24:34Z] WARNING: Nikola: In order to USE_BUNDLES, you must install the "webassets" Python package.
[2015-04-16T00:24:34Z] WARNING: bundles: Setting USE_BUNDLES to False.
[2015-04-16T00:24:34Z] INFO: bootswatch_theme: Creating 'custom' theme from 'slate' and 'bootstrap3'
[2015-04-16T00:24:34Z] INFO: bootswatch_theme: Downloading: http://bootswatch.com/slate/bootstrap.min.css
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): bootswatch.com
[2015-04-16T00:24:34Z] INFO: bootswatch_theme: Downloading: http://bootswatch.com/slate/bootstrap.css
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): bootswatch.com
[2015-04-16T00:24:34Z] NOTICE: bootswatch_theme: Theme created.  Change the THEME setting to "custom" to use it.
```

If you notice it says `Creating 'custom' theme from 'slate' and 'bootstrap3'` and installs slate instead. 

This is on osx but I was able replicate it on my friends box as well which is running fedora.



Discussion:
So after reading the docs (duh) it turns out `nikola bootswatch_theme -s paper` installs paper. I suppose slate is just the default but it may be a good idea to instead of going with a default, printing a warning or outright erroring out and printing an error message.

I think we should just remove the default, since it's unlikely anyone wants to use the random bootswatch we chose. @Kwpolska want me to take it?

@ralsina go on, do it!


Resolving patch:
diff --git a/nikola/plugins/command/bootswatch_theme.py b/nikola/plugins/command/bootswatch_theme.py
--- a/nikola/plugins/command/bootswatch_theme.py
+++ b/nikola/plugins/command/bootswatch_theme.py
@@ -26,6 +26,7 @@
 
 from __future__ import print_function
 import os
+import sys
 
 try:
     import requests
@@ -57,7 +58,7 @@ class CommandBootswatchTheme(Command):
         {
             'name': 'swatch',
             'short': 's',
-            'default': 'slate',
+            'default': '',
             'type': str,
             'help': 'Name of the swatch from bootswatch.com.'
         },
@@ -77,6 +78,9 @@ def _execute(self, options, args):
 
         name = options['name']
         swatch = options['swatch']
+        if not swatch:
+            LOGGER.error('The -s option is mandatory')
+            sys.exit(1)
         parent = options['parent']
         version = ''
 


Test patch:
Repository: getnikola/nikola

Issue:
Sitemap indications of alternate language pages
https://support.google.com/webmasters/answer/2620865?hl=en

I do not have a multi-lingual page myself at this time, so I have no interest in implementing this. Nikola should support it, though.



Discussion:

Resolving patch:
diff --git a/nikola/plugins/task/sitemap/__init__.py b/nikola/plugins/task/sitemap/__init__.py
--- a/nikola/plugins/task/sitemap/__init__.py
+++ b/nikola/plugins/task/sitemap/__init__.py
@@ -50,6 +50,7 @@
 loc_format = """ <url>
   <loc>{0}</loc>
   <lastmod>{1}</lastmod>
+  {2}
  </url>
 """
 
@@ -69,6 +70,13 @@
  </sitemap>
 """
 
+alternates_format = """<xhtml:link
+                 rel="alternate"
+                 hreflang="{0}"
+                 href="{1}"
+                 />"""
+
+
 sitemapindex_footer = "</sitemapindex>"
 
 
@@ -114,6 +122,7 @@ def gen_tasks(self):
             "mapped_extensions": self.site.config.get('MAPPED_EXTENSIONS', ['.html', '.htm', '.xml', '.rss']),
             "robots_exclusions": self.site.config["ROBOTS_EXCLUSIONS"],
             "filters": self.site.config["FILTERS"],
+            "translations": self.site.config["TRANSLATIONS"],
         }
 
         output = kw['output_folder']
@@ -140,7 +149,14 @@ def scan_locs():
                     post = self.site.post_per_file.get(path + kw['index_file'])
                     if post and (post.is_draft or post.is_private or post.publish_later):
                         continue
-                    urlset[loc] = loc_format.format(loc, lastmod)
+                    alternates = []
+                    if post:
+                        for lang in kw['translations']:
+                            alt_url = post.permalink(lang=lang, absolute=True)
+                            if loc == alt_url:
+                                continue
+                            alternates.append(alternates_format.format(lang, alt_url))
+                    urlset[loc] = loc_format.format(loc, lastmod, '\n'.join(alternates))
                 for fname in files:
                     if kw['strip_indexes'] and fname == kw['index_file']:
                         continue  # We already mapped the folder
@@ -179,7 +195,14 @@ def scan_locs():
                         path = path.replace(os.sep, '/')
                         lastmod = self.get_lastmod(real_path)
                         loc = urljoin(base_url, base_path + path)
-                        urlset[loc] = loc_format.format(loc, lastmod)
+                        alternates = []
+                        if post:
+                            for lang in kw['translations']:
+                                alt_url = post.permalink(lang=lang, absolute=True)
+                                if loc == alt_url:
+                                    continue
+                                alternates.append(alternates_format.format(lang, alt_url))
+                        urlset[loc] = loc_format.format(loc, lastmod, '\n'.join(alternates))
 
         def robot_fetch(path):
             for rule in kw["robots_exclusions"]:


Test patch:
Repository: getnikola/nikola

Issue:
No useful error when two posts have same slug
As noticed in #1748, if two posts (or pages) in the same output directory have the same slug, no good error message is given. (Usually doit will emit an error since two tasks generate the same target.)

I think it would be a good idea if after scanning all posts, a check for duplicate slugs in the same directory is performed and warnings are emitted if such situations occurr. (I'm hesitant to make this an error since depending on where -- and by whom -- things are written to in the output, the tags might not collide in the end.) What do you think about that?



Discussion:
Checking if two posts have the same output file is very easy, just look at them after the timeline is built :-)

If you don't want to do it, I can!

Assuming that the posts plugin isn't disabled for some reason, that makes sense. I can add it, though probably neither today nor tomorrow. So if you want to do it before that, feel free :)

I got it then


Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -1463,8 +1463,22 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False):
                 self.pages.append(post)
 
             for lang in self.config['TRANSLATIONS'].keys():
-                self.post_per_file[post.destination_path(lang=lang)] = post
-                self.post_per_file[post.destination_path(lang=lang, extension=post.source_ext())] = post
+                dest = post.destination_path(lang=lang)
+                src_dest = post.destination_path(lang=lang, extension=post.source_ext())
+                if dest in self.post_per_file:
+                    utils.LOGGER.error('Two posts are trying to generate {0}: {1} and {2}'.format(
+                        dest,
+                        self.post_per_file[dest].source_path,
+                        post.source_path))
+                    sys.exit(1)
+                if (src_dest in self.post_per_file) and self.config['COPY_SOURCES']:
+                    utils.LOGGER.error('Two posts are trying to generate {0}: {1} and {2}'.format(
+                        src_dest,
+                        self.post_per_file[dest].source_path,
+                        post.source_path))
+                    sys.exit(1)
+                self.post_per_file[dest] = post
+                self.post_per_file[src_dest] = post
 
         # Sort everything.
 


Test patch:
Repository: getnikola/nikola

Issue:
nikola check misses scaled images
If your site has images to be thumbnailed by the scale_images plugin, this happens:

foo$ nikola check -f
Scanning posts....done!
[2015-06-01T01:27:55Z] WARNING: check: Files from unknown origins (orphans):
[2015-06-01T01:27:55Z] WARNING: check: output/images/architecture.thumbnail.png
[2015-06-01T01:27:55Z] WARNING: check: output/images/lanyon-0.thumbnail.png
[2015-06-01T01:27:55Z] WARNING: check: output/images/lanyon-1.thumbnail.png
[2015-06-01T01:27:55Z] WARNING: check: output/images/lanyon-2.thumbnail.png
[2015-06-01T01:27:55Z] WARNING: check: output/images/lanyon-3.thumbnail.png
[2015-06-01T01:27:55Z] WARNING: check: output/images/lanyon-4.thumbnail.png
[2015-06-01T01:27:55Z] WARNING: check: output/images/lanyon-5.thumbnail.png
[2015-06-01T01:27:55Z] WARNING: check: output/images/lanyon-6.thumbnail.png
[2015-06-01T01:27:55Z] WARNING: check: output/images/lanyon-7.thumbnail.png



Discussion:

Resolving patch:
diff --git a/nikola/plugins/task/scale_images.py b/nikola/plugins/task/scale_images.py
--- a/nikola/plugins/task/scale_images.py
+++ b/nikola/plugins/task/scale_images.py
@@ -58,17 +58,18 @@ def process_tree(self, src, dst):
                     continue
                 dst_file = os.path.join(dst_dir, src_name)
                 src_file = os.path.join(root, src_name)
+                thumb_file = '.thumbnail'.join(os.path.splitext(dst_file))
                 yield {
                     'name': dst_file,
                     'file_dep': [src_file],
-                    'targets': [dst_file],
-                    'actions': [(self.process_image, (src_file, dst_file))],
+                    'targets': [dst_file, thumb_file],
+                    'actions': [(self.process_image, (src_file, dst_file, thumb_file))],
                     'clean': True,
                 }
 
-    def process_image(self, src, dst):
+    def process_image(self, src, dst, thumb):
         self.resize_image(src, dst, self.kw['max_image_size'], False)
-        self.resize_image(src, '.thumbnail'.join(os.path.splitext(dst)), self.kw['image_thumbnail_size'], False)
+        self.resize_image(src, thumb, self.kw['image_thumbnail_size'], False)
 
     def gen_tasks(self):
         """Copy static files into the output folder."""


Test patch:
Repository: getnikola/nikola

Issue:
nikola install_theme --get-path
now:

``` console
$ nikola install_theme base
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): themes.getnikola.com
[2015-05-28T19:08:36Z] ERROR: install_theme: Theme 'base' is already installed in /home/kwpolska/git/nikola/nikola/data/themes/base
```

proposal:

``` console
$ nikola install_theme --get-path base
/home/kwpolska/git/nikola/nikola/data/themes/base
$ nikola install_theme --get-path unicorns
not installed
```

Via Lanyon theme guide.



Discussion:

Resolving patch:
diff --git a/nikola/plugins/command/check.py b/nikola/plugins/command/check.py
--- a/nikola/plugins/command/check.py
+++ b/nikola/plugins/command/check.py
@@ -260,7 +260,6 @@ def analyze(self, fname, find_sources=False, check_remote=False):
                         self.existing_targets.add(target_filename)
                     else:
                         rv = True
-                        import pdb; pdb.set_trace()
                         self.logger.warn("Broken link in {0}: {1}".format(filename, target))
                         if find_sources:
                             self.logger.warn("Possible sources:")
diff --git a/nikola/plugins/command/install_theme.py b/nikola/plugins/command/install_theme.py
--- a/nikola/plugins/command/install_theme.py
+++ b/nikola/plugins/command/install_theme.py
@@ -88,6 +88,14 @@ class CommandInstallTheme(Command):
                     "https://themes.getnikola.com/v7/themes.json)",
             'default': 'https://themes.getnikola.com/v7/themes.json'
         },
+        {
+            'name': 'getpath',
+            'short': 'g',
+            'long': 'get-path',
+            'type': bool,
+            'default': False,
+            'help': "Print the path for installed theme",
+        },
     ]
 
     def _execute(self, options, args):
@@ -102,6 +110,14 @@ def _execute(self, options, args):
         else:
             name = None
 
+        if options['getpath'] and name:
+            path = utils.get_theme_path(name)
+            if path:
+                print(path)
+            else:
+                print('not installed')
+            exit(0)
+
         if name is None and not listing:
             LOGGER.error("This command needs either a theme name or the -l option.")
             return False


Test patch:
Repository: getnikola/nikola

Issue:
Make ipython work with all themes
AFAIK this involves:
- [x] Adding some CSS (the CSS needs reviewing)
- [x] Enabling mathjax for ipynb posts/stories

Is there anything else, @damianavila ?



Discussion:
I don't think so... should be enough... btw, the ipython/jupyter css does not have to break the themes for people not using ipynbs...

We could check if the user has any posts that would be compiled with ipynb, and if yes, include the CSS.

And mark those posts as mathjax immediately.

yes... sounds like a good idea...


Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -796,6 +796,16 @@ def __init__(self, **config):
         self._GLOBAL_CONTEXT['hidden_categories'] = self.config.get('HIDDEN_CATEGORIES')
         self._GLOBAL_CONTEXT['url_replacer'] = self.url_replacer
 
+        # IPython theme configuration.  If a website can potentially have ipynb
+        # posts (as determined by checking POSTS/PAGES against ipynb
+        # extensions), we should enable the IPython CSS (leaving that up to the
+        # theme itself).
+
+        self._GLOBAL_CONTEXT['needs_ipython_css'] = False
+        for i in self.config['post_pages']:
+            if os.path.splitext(i[0])[1] in self.config['COMPILERS'].get('ipynb', []):
+                self._GLOBAL_CONTEXT['needs_ipython_css'] = True
+
         self._GLOBAL_CONTEXT.update(self.config.get('GLOBAL_CONTEXT', {}))
 
         # Load compiler plugins
diff --git a/nikola/post.py b/nikola/post.py
--- a/nikola/post.py
+++ b/nikola/post.py
@@ -224,8 +224,8 @@ def __init__(
         self.use_in_feeds = use_in_feeds and not is_draft and not is_private \
             and not self.publish_later
 
-        # If mathjax is a tag, then enable mathjax rendering support
-        self.is_mathjax = 'mathjax' in self.tags
+        # If mathjax is a tag, or it's a ipynb post, then enable mathjax rendering support
+        self.is_mathjax = ('mathjax' in self.tags) or (self.compiler.name == 'ipynb')
 
         # Register potential extra dependencies
         self.compiler.register_extra_dependencies(self)


Test patch:
diff --git a/tests/test_rss_feeds.py b/tests/test_rss_feeds.py
--- a/tests/test_rss_feeds.py
+++ b/tests/test_rss_feeds.py
@@ -33,6 +33,7 @@ class FakeCompiler(object):
     demote_headers = False
     compile_html = None
     extension = lambda self: '.html'
+    name = "fake"
 
     def read_metadata(*args, **kwargs):
         return {}
Repository: getnikola/nikola

Issue:
`nikola version` should check for updates
if `//rdf/RDF/Project/release/Version/revision` (from https://pypi.python.org/pypi?:action=doap&name=Nikola) differs from current version, suggest updating using pip.



Discussion:
Only concern is: without a network or bad network, the nikola version command will hang for seconds. So maybe as a separate option.


Resolving patch:
diff --git a/nikola/plugins/command/version.py b/nikola/plugins/command/version.py
--- a/nikola/plugins/command/version.py
+++ b/nikola/plugins/command/version.py
@@ -26,9 +26,18 @@
 
 from __future__ import print_function
 
+import lxml
+try:
+    import requests
+except ImportError:
+    requests = None
+
 from nikola.plugin_categories import Command
+from nikola.utils import req_missing
 from nikola import __version__
 
+URL = 'https://pypi.python.org/pypi?:action=doap&name=Nikola'
+
 
 class CommandVersion(Command):
     """Print the version."""
@@ -38,7 +47,28 @@ class CommandVersion(Command):
     doc_usage = ""
     needs_config = False
     doc_purpose = "print the Nikola version number"
+    cmd_options = [
+        {
+            'name': 'check',
+            'long': 'check',
+            'short': '',
+            'default': False,
+            'type': bool,
+            'help': "Check for new versions.",
+        }
+    ]
 
     def _execute(self, options={}, args=None):
         """Print the version number."""
         print("Nikola v" + __version__)
+        if options.get('check'):
+            if requests is None:
+                req_missing(['requests'], 'check for updates')
+                exit(1)
+            data = requests.get(URL).text
+            doc = lxml.etree.fromstring(data.encode('utf8'))
+            revision = doc.findall('*//{http://usefulinc.com/ns/doap#}revision')[0].text
+            if revision == __version__:
+                print("Nikola is up-to-date")
+            else:
+                print("The latest version of Nikola is v{0} -- please upgrade using `pip install --upgrade Nikola=={0}` or your system package manager".format(revision))


Test patch:
Repository: getnikola/nikola

Issue:
Nikola auto doesn't work in python3
```
$ nikola auto
ERROR:yapsy:Unable to import plugin: /home/ralsina/Desktop/proyectos/nikola/master/nikola/plugins/command/auto
Traceback (most recent call last):
  File "/home/ralsina/.virtualenvs/nikola3/lib/python3.4/site-packages/Yapsy-1.10.423-py3.4.egg/yapsy/PluginManager.py", line 485, in loadPlugins
    candidate_module = imp.load_module(plugin_module_name,None,candidate_filepath,("py","r",imp.PKG_DIRECTORY))
  File "/home/ralsina/.virtualenvs/nikola3/lib/python3.4/imp.py", line 245, in load_module
    return load_package(name, filename)
  File "/home/ralsina/.virtualenvs/nikola3/lib/python3.4/imp.py", line 217, in load_package
    return methods.load()
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/plugins/command/auto/__init__.py", line 260, in <module>
    class LRSocket(WebSocket):
TypeError: NoneType takes no arguments
[2015-06-10T12:45:52Z] ERROR: Nikola: Unknown command auto
```



Discussion:

Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -1026,7 +1026,8 @@ def url_replacer(self, src, dst, lang=None, url_type=None):
                         # python 3: already unicode
                         pass
                     nl = nl.encode('idna')
-
+                    if isinstance(nl, utils.bytes_str):
+                        nl = nl.decode('latin-1')  # so idna stays unchanged
                     dst = urlunsplit((dst_url.scheme,
                                       nl,
                                       dst_url.path,


Test patch: