anon-iclr-submission/benchname-bug-localization huggingface dataset:
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


Changed files:
nikola/plugins/task/scale_images.py

diff --git a/nikola/plugins/task/scale_images.py b/nikola/plugins/task/scale_images.py
index 87959ba94..f97027e71 100644
--- a/nikola/plugins/task/scale_images.py
+++ b/nikola/plugins/task/scale_images.py
@@ -58,17 +58,18 @@ class ScaleImage(Task, ImageProcessor):
                     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."""
Repository: getnikola/nikola
Issue: Spurious "scheduled to be published in the future" warning

Using Nikola 7.5.1 on Python 3, I get messages of the form

```
[2015-06-30T18:03:48Z] NOTICE: Nikola: path/to/post.rst is scheduled to be published in the future (2015-06-30 18:00:00+00:00)
```

As can be seen from the timestamps, this message isn't even self-consistent.

I tried different ways of expressing the time zone (UTC, local time etc) and nothing works except setting the publication time over an hour into the past in UTC. My local time is currently UTC+1; perhaps Nikola is applying the timezone offset twice?


Changed files:
nikola/post.py

diff --git a/nikola/post.py b/nikola/post.py
index 466d5e07e..b1892dcf4 100644
--- a/nikola/post.py
+++ b/nikola/post.py
@@ -102,7 +102,7 @@ class Post(object):
         if self.config['FUTURE_IS_NOW']:
             self.current_time = None
         else:
-            self.current_time = current_time()
+            self.current_time = current_time(tzinfo)
         self.translated_to = set([])
         self._prev_post = None
         self._next_post = None
Repository: getnikola/nikola
Issue: Possible bug in `get_asset_path`?

As mentioned in #2106, I think `nikola.util.get_asset_path` might have a bug, or it is used incorrectly. Or (third possiblity), I understand it wrongly what it is supposed to do.

I understand it as follows: if you want to know whether `output/bla/test.txt` is created by either the themes or by copying files (or already created by another plugin or by magic when called in `gen_tasks`), you do `get_asset_path('bla/test.txt', themes, files_folders)` and see if it returns `None` or a path.

I looked at how it is used for example in the `robots` plugin to detect whether `output/robots.txt` is created, and it seems to confirm my idea.

If that's correct, then it will fail in the following situation: assume that you have `file_folders = {'a': 'b'}` and have a file `a/bla/test.txt`. This will be copied to `output/b/bla/test.txt`. On the other hand, `get_asset_path('bla/test.txt', themes, files_folders)` will return `a/bla/test.txt`, so I assume that `output/bla/test.txt` will be created -- which it won't.

So -- do I understand it wrong what `get_asset_path` does, or is there a bug in its implementation? (Or am I somehow else confused? :) )


Changed files:
nikola/utils.py

diff --git a/nikola/utils.py b/nikola/utils.py
index 0067b34e4..78a3fbb02 100644
--- a/nikola/utils.py
+++ b/nikola/utils.py
@@ -986,9 +986,12 @@ def get_asset_path(path, themes, files_folders={'files': ''}, _themes_dir='theme
     >>> print(get_asset_path('nikola.py', ['bootstrap3', 'base'], {'nikola': ''}))
     /.../nikola/nikola.py
 
-    >>> print(get_asset_path('nikola/nikola.py', ['bootstrap3', 'base'], {'nikola':'nikola'}))
+    >>> print(get_asset_path('nikola.py', ['bootstrap3', 'base'], {'nikola': 'nikola'}))
     None
 
+    >>> print(get_asset_path('nikola/nikola.py', ['bootstrap3', 'base'], {'nikola': 'nikola'}))
+    /.../nikola/nikola.py
+
     """
     for theme_name in themes:
         candidate = os.path.join(
@@ -998,9 +1001,11 @@ def get_asset_path(path, themes, files_folders={'files': ''}, _themes_dir='theme
         if os.path.isfile(candidate):
             return candidate
     for src, rel_dst in files_folders.items():
-        candidate = os.path.abspath(os.path.join(src, path))
-        if os.path.isfile(candidate):
-            return candidate
+        relpath = os.path.normpath(os.path.relpath(path, rel_dst))
+        if not relpath.startswith('..' + os.path.sep):
+            candidate = os.path.abspath(os.path.join(src, relpath))
+            if os.path.isfile(candidate):
+                return candidate
 
     if output_dir:
         candidate = os.path.join(output_dir, path)
Repository: getnikola/nikola
Issue: Windows task conflict

As reported by @berezovskyi on IRC:

```
ERROR: 'output\\posts\\math-test-new\\index.html' is a target for render_indexes:output\\posts\\math-test-new\\index.html and render_pages:output\\posts\\math-test-new\\index.html
```

Happens if more than one post exists; Windows and v7.7.0 only.  Probably needs some `git bisect` first.

Repo: https://github.com/berezovskyi/nikola-troubleshoot


Changed files:
nikola/post.py

diff --git a/nikola/post.py b/nikola/post.py
index 94e1e7453..f9905e5a5 100644
--- a/nikola/post.py
+++ b/nikola/post.py
@@ -769,7 +769,7 @@ class Post(object):
 
         if not self.config['POSTS_SECTION_FROM_META']:
             dest = self.destination_path(lang)
-            if dest[-(1 + len(self.index_file)):] == '/' + self.index_file:
+            if dest[-(1 + len(self.index_file)):] == os.sep + self.index_file:
                 dest = dest[:-(1 + len(self.index_file))]
             dirname = os.path.dirname(dest)
             slug = dest.split(os.sep)
Repository: getnikola/nikola
Issue: Changing section colors does not rebuild things

I want to use section colors in all post headers, and I have to run `nikola build -a` to get the changes to appear everywhere.


Changed files:
nikola/nikola.py

diff --git a/nikola/nikola.py b/nikola/nikola.py
index e3b2ed3b9..a961d2525 100644
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -441,6 +441,7 @@ class Nikola(object):
             'POSTS': (("posts/*.txt", "posts", "post.tmpl"),),
             'POSTS_SECTIONS': True,
             'POSTS_SECTION_ARE_INDEXES': True,
+            'POSTS_SECTION_COLORS': {},
             'POSTS_SECTION_DESCRIPTIONS': "",
             'POSTS_SECTION_FROM_META': False,
             'POSTS_SECTION_NAME': "",
@@ -945,7 +946,13 @@ class Nikola(object):
         self._GLOBAL_CONTEXT['hidden_categories'] = self.config.get('HIDDEN_CATEGORIES')
         self._GLOBAL_CONTEXT['hidden_authors'] = self.config.get('HIDDEN_AUTHORS')
         self._GLOBAL_CONTEXT['url_replacer'] = self.url_replacer
-        self._GLOBAL_CONTEXT['post_section_colors'] = self.config.get('POST_SECTION_COLORS')
+        self._GLOBAL_CONTEXT['posts_sections'] = self.config.get('POSTS_SECTIONS')
+        self._GLOBAL_CONTEXT['posts_section_are_indexes'] = self.config.get('POSTS_SECTION_ARE_INDEXES')
+        self._GLOBAL_CONTEXT['posts_section_colors'] = self.config.get('POSTS_SECTION_COLORS')
+        self._GLOBAL_CONTEXT['posts_section_descriptions'] = self.config.get('POSTS_SECTION_DESCRIPTIONS')
+        self._GLOBAL_CONTEXT['posts_section_from_meta'] = self.config.get('POSTS_SECTION_FROM_META')
+        self._GLOBAL_CONTEXT['posts_section_name'] = self.config.get('POSTS_SECTION_NAME')
+        self._GLOBAL_CONTEXT['posts_section_title'] = self.config.get('POSTS_SECTION_TITLE')
 
         # IPython theme configuration.  If a website has ipynb enabled in post_pages
         # we should enable the IPython CSS (leaving that up to the theme itself).
Repository: getnikola/nikola
Issue: Post.text with strip_html=True fails for empty posts

```pytb
Scanning posts......done!
.  local_search:output/assets/js/tipuesearch_content.json
########################################
TaskError - taskid:local_search:output/assets/js/tipuesearch_content.json
PythonAction Error
Traceback (most recent call last):
  File "/home/kwpolska/virtualenvs/nikola-py3/lib/python3.5/site-packages/doit/action.py", line 383, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/home/kwpolska/nikola-logs/plugins/localsearch/localsearch/__init__.py", line 77, in save_data
    text = post.text(lang, strip_html=True)
  File "/home/kwpolska/git/nikola/nikola/post.py", line 677, in text
    data = content.text_content().strip()  # No whitespace wanted.
  File "/home/kwpolska/virtualenvs/nikola-py3/lib/python3.5/site-packages/lxml/html/__init__.py", line 411, in text_content
    return _collect_string_content(self)
  File "src/lxml/xpath.pxi", line 433, in lxml.etree.XPath.__call__ (src/lxml/lxml.etree.c:168402)
  File "src/lxml/apihelpers.pxi", line 67, in lxml.etree._rootNodeOrRaise (src/lxml/lxml.etree.c:15759)
ValueError: Input object is not an XML element: HtmlComment
```

Caused by this file:

```html
<!--
.. title: Search
.. slug: search
.. date: 2015-07-20 14:18:28 UTC
.. tags:
.. category:
.. link:
.. description:
.. type: text
-->
```

To fix this, all I had to do was to add a newline (which was probably triggering the metadata comment removal thing), but we should protect against those crashes.

Changed files:
nikola/post.py

diff --git a/nikola/post.py b/nikola/post.py
index e564e52ea..701f2a179 100644
--- a/nikola/post.py
+++ b/nikola/post.py
@@ -687,7 +687,7 @@ class Post(object):
                 # Not all posts have a body. For example, you may have a page statically defined in the template that does not take content as input.
                 content = lxml.html.fromstring(data)
                 data = content.text_content().strip()  # No whitespace wanted.
-            except lxml.etree.ParserError:
+            except (lxml.etree.ParserError, ValueError):
                 data = ""
         elif data:
             if self.demote_headers:
Repository: getnikola/nikola
Issue: Archives (CREATE_MONTHLY_ARCHIVE = True) think all months are "None"

https://irclogs.getnikola.com/2015/

To reproduce locally: get https://github.com/getnikola/irclogs-site create any random files in `posts/*.rst`.

Changed files:
nikola/plugins/task/archive.py

diff --git a/nikola/plugins/task/archive.py b/nikola/plugins/task/archive.py
index 74c28c245..40baf9e16 100644
--- a/nikola/plugins/task/archive.py
+++ b/nikola/plugins/task/archive.py
@@ -97,7 +97,7 @@ class Archive(Taxonomy):
         elif len(classification) == 1:
             return classification[0]
         elif len(classification) == 2:
-            nikola.utils.LocaleBorg().get_month_name(int(classification[1]), lang)
+            return nikola.utils.LocaleBorg().get_month_name(int(classification[1]), lang)
         else:
             # Fallback
             return '/'.join(classification)
Repository: getnikola/nikola
Issue: Wrong exit code from command line parsing

[/data/home/hayen/repos/nikola-site]> /opt/nikola/bin/nikola unknown
[2014-10-27T09:55:38Z] ERROR: Nikola: Unknown command unknown
[/data/home/hayen/repos/nikola-site]> echo $?
0

That should be "1" or so. I am using commands with "&&" and expect
Nikola to abort, if there was a problem. Not happening in this case.


Changed files:
nikola/__main__.py

diff --git a/nikola/__main__.py b/nikola/__main__.py
index f49280078..84af6df41 100644
--- a/nikola/__main__.py
+++ b/nikola/__main__.py
@@ -270,12 +270,12 @@ class DoitNikola(DoitMain):
             args = ['version']
         if args[0] not in sub_cmds.keys():
             LOGGER.error("Unknown command {0}".format(args[0]))
-            return False
+            return 3
         if not isinstance(sub_cmds[args[0]], (Command, Help)):  # Is a doit command
             if not self.nikola.configured:
                 LOGGER.error("This command needs to run inside an "
                              "existing Nikola site.")
-                return False
+                return 3
 
         return super(DoitNikola, self).run(cmd_args)
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.


Changed files:
nikola/plugins/command/deploy.py

diff --git a/nikola/plugins/command/deploy.py b/nikola/plugins/command/deploy.py
index 97142f84b..7629894a8 100644
--- a/nikola/plugins/command/deploy.py
+++ b/nikola/plugins/command/deploy.py
@@ -36,7 +36,7 @@ import time
 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 @@ class CommandDeploy(Command):
         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()))
Repository: datafold/data-diff
Issue: Profiles dir overwritten in the code for DBT version < 1.3.0

**Describe the bug**
The profiles dir is being overwritten in the code ([this lines](https://github.com/datafold/data-diff/blob/eb22d3e9a8b1a098f113c7a37dec9a8efb25c025/data_diff/dbt_parser.py#L214-L215)) after passed as an argument.
If I execute:
`data_diff --dbt --dbt-profiles-dir my/custom/dir`
Then I get
`ERROR    No profile 'my_dbt_profile' found in '/Users/myuser/.dbt/profiles.yml'`

I'm guessing this is not the intended behaviour as I believe the argument should take precedence in this case.

**Describe the environment**

I'm using the master branch of this repo ([v0.7.14](https://github.com/datafold/data-diff/commit/eb22d3e9a8b1a098f113c7a37dec9a8efb25c025)) and DBT v1.2.6 but i guess any < 1.3.0 will have this issue


Changed files:
data_diff/dbt_parser.py

diff --git a/data_diff/dbt_parser.py b/data_diff/dbt_parser.py
index 928f7130..617ce1b1 100644
--- a/data_diff/dbt_parser.py
+++ b/data_diff/dbt_parser.py
@@ -103,7 +103,6 @@ class DbtParser:
     ) -> None:
         try_set_dbt_flags()
         self.dbt_runner = try_get_dbt_runner()
-        self.profiles_dir = Path(profiles_dir_override or default_profiles_dir())
         self.project_dir = Path(project_dir_override or default_project_dir())
         self.connection = {}
         self.project_dict = self.get_project_dict()
@@ -119,6 +118,13 @@ class DbtParser:
         self.threads = None
         self.unique_columns = self.get_unique_columns()
 
+        if profiles_dir_override:
+            self.profiles_dir = Path(profiles_dir_override)
+        elif parse_version(self.dbt_version) < parse_version("1.3.0"):
+            self.profiles_dir = legacy_profiles_dir()
+        else:
+            self.profiles_dir = default_profiles_dir()
+
     def get_datadiff_config(self) -> TDatadiffConfig:
         data_diff_vars = self.project_dict.get("vars", {}).get("data_diff", {})
         prod_database = data_diff_vars.get("prod_database")
@@ -211,9 +217,6 @@ class DbtParser:
 
         dbt_version = parse_version(run_results_obj.metadata.dbt_version)
 
-        if dbt_version < parse_version("1.3.0"):
-            self.profiles_dir = legacy_profiles_dir()
-
         if dbt_version < parse_version(LOWER_DBT_V):
             raise DataDiffDbtRunResultsVersionError(
                 f"Found dbt: v{dbt_version} Expected the dbt project's version to be >= {LOWER_DBT_V}"
Repository: datafold/data-diff
Issue: "Rows Added" and "Rows Removed" are reversed in `--dbt` CLI printout

**Describe the bug**
It seems that "Rows Added" and "Rows Removed" are flipped in `--dbt` (but not `--cloud`).

These are the results of a diff that was run first with `--dbt`, and subsequently with `--cloud`. The `--cloud` summary is correct because the only change I made was a `limit` to reduce the number of rows in the dev version.

`data-diff=0.7.11`

<img width="548" alt="Screenshot 2023-06-27 at 23 02 14" src="https://github.com/datafold/data-diff/assets/1799931/df781c94-eda5-4894-9f17-251dcfd19023">



Changed files:
data_diff/diff_tables.py

diff --git a/data_diff/diff_tables.py b/data_diff/diff_tables.py
index aaf56c9c..df3f4b81 100644
--- a/data_diff/diff_tables.py
+++ b/data_diff/diff_tables.py
@@ -140,8 +140,8 @@ class DiffResultWrapper:
 
         if is_dbt:
             string_output = dbt_diff_string_template(
-                diff_stats.diff_by_sign["-"],
                 diff_stats.diff_by_sign["+"],
+                diff_stats.diff_by_sign["-"],
                 diff_stats.diff_by_sign["!"],
                 diff_stats.unchanged,
                 diff_stats.extra_column_diffs,
Repository: datafold/data-diff
Issue: --dbt multiple Diffs Complete!

**Describe the bug**
Diffs Complete! Is printing multiple times instead of after the last diff as intended



Changed files:
data_diff/dbt.py

diff --git a/data_diff/dbt.py b/data_diff/dbt.py
index 79f67a54..1d2d6303 100644
--- a/data_diff/dbt.py
+++ b/data_diff/dbt.py
@@ -84,7 +84,7 @@ def dbt_diff(
                 + "Skipped due to missing primary-key tag or multi-column primary-key (unsupported for non --cloud diffs)\\n"
             )
 
-        rich.print("Diffs Complete!")
+    rich.print("Diffs Complete!")
 
 
 def _get_diff_vars(
Repository: lightly-ai/lightly
Issue: loader.num_workers=12 doesn't actually spawn multiple workers

I've noticed that when trying to create an embedding with the param `loader.num_workers` there seems to be no difference in CPU consumption;
`lightly-embed input_dir='./75000' trainer.max_epochs=1 loader.num_workers=12`

This could be that my images are ~8kb and there is some other bottleneck preventing the CPUs to max-out? in My ActivityMonitor (macOSX) I see that I have 80% idle CPU

System: MacBook Pro (16-inch, 2019), 2.6 GHz 6-Core Intel Core i7
OS: MacOSX 11.2.3




Changed files:
lightly/api/api_workflow_upload_dataset.py, lightly/cli/upload_cli.py, tests/UNMOCKED_end2end_tests/test_api.py

diff --git a/lightly/api/api_workflow_upload_dataset.py b/lightly/api/api_workflow_upload_dataset.py
index a64220a6..4d1795fd 100644
--- a/lightly/api/api_workflow_upload_dataset.py
+++ b/lightly/api/api_workflow_upload_dataset.py
@@ -61,6 +61,7 @@ class _UploadDatasetMixin:
 
         # handle the case where len(dataset) < max_workers
         max_workers = min(len(dataset), max_workers)
+        max_workers = max(max_workers, 1)
 
         # upload the samples
         if verbose:
diff --git a/lightly/cli/upload_cli.py b/lightly/cli/upload_cli.py
index a5c648d4..d4ac0abb 100644
--- a/lightly/cli/upload_cli.py
+++ b/lightly/cli/upload_cli.py
@@ -52,7 +52,7 @@ def _upload_cli(cfg, is_cli_call=True):
         mode = cfg['upload']
         dataset = LightlyDataset(input_dir=input_dir, transform=transform)
         api_workflow_client.upload_dataset(
-            input=dataset, mode=mode
+            input=dataset, mode=mode, max_workers=cfg['loader']['num_workers']
         )
 
     if path_to_embeddings:
diff --git a/tests/UNMOCKED_end2end_tests/test_api.py b/tests/UNMOCKED_end2end_tests/test_api.py
index 7f15b2a7..da919e31 100644
--- a/tests/UNMOCKED_end2end_tests/test_api.py
+++ b/tests/UNMOCKED_end2end_tests/test_api.py
@@ -4,6 +4,9 @@ import sys
 from typing import List, Tuple
 
 import numpy as np
+from hydra.experimental import initialize, compose
+
+from lightly.cli import upload_cli
 from lightly.data.dataset import LightlyDataset
 
 from lightly.active_learning.scorers.classification import ScorerClassification
@@ -69,7 +72,14 @@ def create_new_dataset_with_embeddings(path_to_dataset: str,
     api_workflow_client.create_new_dataset_with_unique_name(dataset_basename=dataset_name)
 
     # upload to the dataset
-    api_workflow_client.upload_dataset(input=path_to_dataset)
+    initialize(config_path="../../lightly/cli/config", job_name="test_app")
+    cfg = compose(config_name="config", overrides=[
+        f"input_dir='{path_to_dataset}'",
+        f"token='{token}'",
+        f"dataset_id={api_workflow_client.dataset_id}",
+        f"loader.num_workers=9"
+        ])
+    upload_cli(cfg)
 
     # calculate and save the embeddings
     path_to_embeddings_csv = f"{path_to_dataset}/embeddings.csv"
Repository: crossbario/autobahn-python
Issue: upgrading to autobahn v0.12.1 does not install pytrie

I am using autobahn[asyncio] and when I either do a new install or pip install autobahn --upgrade, pytrie is not loaded. I have to manually load it.


Changed files:
autobahn/wamp/cryptosign.py, autobahn/wamp/cryptobox.py

diff --git a/autobahn/wamp/cryptobox.py b/autobahn/wamp/cryptobox.py
index a655ea5c..a9277b5a 100644
--- a/autobahn/wamp/cryptobox.py
+++ b/autobahn/wamp/cryptobox.py
@@ -30,18 +30,22 @@ import json
 
 import six
 
-__all__ = (
-    'HAS_NACL',
-    'Key',
-    'KeyRing',
+__all__ = [
+    'HAS_CRYPTOBOX',
     'EncryptedPayload'
-)
+]
 
 try:
-    import nacl  # noqa
-    HAS_NACL = True
+    # try to import everything we need for WAMP-cryptobox
+    from nacl.encoding import Base64Encoder
+    from nacl.public import PrivateKey, PublicKey, Box
+    from nacl.utils import random
+    from pytrie import StringTrie
 except ImportError:
-    HAS_NACL = False
+    HAS_CRYPTOBOX = False
+else:
+    HAS_CRYPTOBOX = True
+    __all__.extend(['Key', 'KeyRing'])
 
 
 class EncryptedPayload(object):
@@ -56,12 +60,7 @@ class EncryptedPayload(object):
         self.payload = payload
 
 
-if HAS_NACL:
-    from nacl.encoding import Base64Encoder
-    from nacl.public import PrivateKey, PublicKey, Box
-    from nacl.utils import random
-
-    from pytrie import StringTrie
+if HAS_CRYPTOBOX:
 
     class Key(object):
         """
@@ -232,7 +231,3 @@ if HAS_NACL:
             kwargs = payload.get(u'kwargs', None)
 
             return uri, args, kwargs
-
-else:
-
-    KeyRing = type(None)
diff --git a/autobahn/wamp/cryptosign.py b/autobahn/wamp/cryptosign.py
index 83eca335..35882221 100644
--- a/autobahn/wamp/cryptosign.py
+++ b/autobahn/wamp/cryptosign.py
@@ -39,11 +39,13 @@ from autobahn.wamp.types import Challenge
 
 from twisted.internet.defer import inlineCallbacks, returnValue
 
-__all__ = []
+__all__ = [
+    'HAS_CRYPTOSIGN',
+    'HAS_CRYPTOSIGN_SSHAGENT'
+]
 
 try:
-    # try to import everything that is optional for Autobahn in
-    # general, but which we need for WAMP-cryptosign
+    # try to import everything we need for WAMP-cryptosign
     from nacl import public, encoding, signing
 except ImportError:
     HAS_CRYPTOSIGN = False
Repository: crossbario/autobahn-python
Issue: Asyncio: ApplicationRunner doesn't handle correctly restart of the event loop

Running a `asyncio.wamp.ApplicationSession` with `ApplicationRunner.run(session start_loop=True)`
two consecutive times fails the second one.

Minimal example: https://gist.github.com/rdebroiz/1854c2bab7da929e376c273d262c805a

Adding
``` python
if loop.is_closed():
    asyncio.set_event_loop(asyncio.new_event_loop())
```
Before to run the ApplicationRunner the second times make it works as expected.

This code snippet is coming from and is already called by `asyncio.wamp.ApplicationRunner.run`
see: https://github.com/crossbario/autobahn-python/blob/master/autobahn/asyncio/wamp.py#L246

Any ideas of what is going on?

Changed files:
autobahn/asyncio/component.py, autobahn/asyncio/wamp.py

diff --git a/autobahn/asyncio/component.py b/autobahn/asyncio/component.py
index 5c766811..96edbcdf 100644
--- a/autobahn/asyncio/component.py
+++ b/autobahn/asyncio/component.py
@@ -333,6 +333,10 @@ def run(components, log_level='info'):
     if log_level is not None:
         txaio.start_logging(level=log_level)
     loop = asyncio.get_event_loop()
+    if loop.is_closed():
+        asyncio.set_event_loop(asyncio.new_event_loop())
+        loop = asyncio.get_event_loop()
+        txaio.config.loop = loop
     log = txaio.make_logger()
 
     # see https://github.com/python/asyncio/issues/341 asyncio has
diff --git a/autobahn/asyncio/wamp.py b/autobahn/asyncio/wamp.py
index a0407680..0bf3abf5 100644
--- a/autobahn/asyncio/wamp.py
+++ b/autobahn/asyncio/wamp.py
@@ -248,6 +248,8 @@ class ApplicationRunner(object):
         if loop.is_closed() and start_loop:
             asyncio.set_event_loop(asyncio.new_event_loop())
             loop = asyncio.get_event_loop()
+            if hasattr(transport_factory, 'loop'):
+                transport_factory.loop = loop
         txaio.use_asyncio()
         txaio.config.loop = loop
         coro = loop.create_connection(transport_factory, host, port, ssl=ssl)
Repository: crossbario/autobahn-python
Issue: Import from private Twisted module breaks Autobahn on Windows

When running on Windows with Twisted 15.4.0, the changes made in c517e9f generate an exception, since importing `PipeAddress` from `twisted.internet._posixstdio` calls `detectLinuxBrokenPipeBehavior`, which only works on Posix systems.

Removing the changes from this commit fixes the problem, and seems to only make a cosmetic change.  Arguably, importing from a private module is fraught with peril, and probably shouldn't be done.

Here is an example stack trace showing the problem:

```
Traceback (most recent call last):
  File "C:\\Python27\\Scripts\\crossbar-script.py", line 9, in <module>
    load_entry_point('crossbar==0.10.4', 'console_scripts', 'crossbar')()
  File "C:\\Python27\\lib\\site-packages\\crossbar\\controller\\cli.py", line 665, in run
    options.func(options)
  File "C:\\Python27\\lib\\site-packages\\crossbar\\controller\\cli.py", line 402, in run_command_start
    from crossbar.controller.node import Node
  File "C:\\Python27\\lib\\site-packages\\crossbar\\controller\\node.py", line 51, in <module>
    from crossbar.controller.process import NodeControllerSession
  File "C:\\Python27\\lib\\site-packages\\crossbar\\controller\\process.py", line 52, in <module>
    from autobahn.twisted.util import sleep
  File "C:\\Python27\\lib\\site-packages\\autobahn\\twisted\\util.py", line 31, in <module>
    from twisted.internet._posixstdio import PipeAddress
  File "C:\\Python27\\lib\\site-packages\\twisted\\internet\\_posixstdio.py", line 16, in <module>
    from twisted.internet import process, error, interfaces
  File "C:\\Python27\\lib\\site-packages\\twisted\\internet\\process.py", line 119, in <module>
    brokenLinuxPipeBehavior = detectLinuxBrokenPipeBehavior()
  File "C:\\Python27\\lib\\site-packages\\twisted\\internet\\process.py", line 107, in detectLinuxBrokenPipeBehavior
    reads, writes, exes = select.select([w], [], [], 0)
select.error: (10038, 'An operation was attempted on something that is not a socket')
```


Changed files:
autobahn/twisted/util.py

diff --git a/autobahn/twisted/util.py b/autobahn/twisted/util.py
index db305872..1e900daa 100644
--- a/autobahn/twisted/util.py
+++ b/autobahn/twisted/util.py
@@ -28,7 +28,7 @@ from __future__ import absolute_import
 
 from twisted.internet.defer import Deferred
 from twisted.internet.address import IPv4Address, UNIXAddress
-from twisted.internet._posixstdio import PipeAddress
+from twisted.internet.stdio import PipeAddress
 
 try:
     from twisted.internet.address import IPv6Address
Repository: pgmpy/pgmpy
Issue: Bug in map_query

`map_query` giving wrong values. Should be accepting the variables parameter and should eliminate all the remaining variables.


Changed files:
pgmpy/inference/ExactInference.py

diff --git a/pgmpy/inference/ExactInference.py b/pgmpy/inference/ExactInference.py
index 4f6aaaf8..41ced21c 100644
--- a/pgmpy/inference/ExactInference.py
+++ b/pgmpy/inference/ExactInference.py
@@ -58,6 +58,7 @@ class VariableElimination(Inference):
                              " variables or evidence args")
 
         for var in elimination_order:
+            # Removing all the factors containing the variables which are
             # Removing all the factors containing the variables which are
             # eliminated (as all the factors should be considered only once)
             factors = [factor for factor in working_factors[var]
@@ -180,12 +181,10 @@ class VariableElimination(Inference):
         >>> inference = VariableElimination(model)
         >>> phi_query = inference.map_query(['A', 'B'])
         """
-        if not variables:
-            variables = []
-        final_distribution = self._variable_elimination(variables, 'maximize',
+        elimination_variables = set(self.variables) - set(evidence.keys()) if evidence else set()
+        final_distribution = self._variable_elimination(elimination_variables, 'maximize',
                                                         evidence=evidence,
                                                         elimination_order=elimination_order)
-
         # To handle the case when no argument is passed then
         # _variable_elimination returns a dict.
         if isinstance(final_distribution, dict):
@@ -200,7 +199,13 @@ class VariableElimination(Inference):
             var, value = var_assignment.split('_')
             map_query_results[var] = int(value)
 
-        return map_query_results
+        if not variables:
+            return map_query_results
+        else:
+            return_dict = {}
+            for var in variables:
+                return_dict[var] = map_query_results[var]
+            return return_dict
 
     def induced_graph(self, elimination_order):
         """
Repository: pgmpy/pgmpy
Issue: Bug in __str__ method of Factor

``` python
from pgmpy.factors import Factor

phi = Factor([3, 2], [2, 2], range(4))

print(phi)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-78ba4ef7a080> in <module>()
----> 1 print(phi)

/home/ankur/pgmpy/pgmpy/factors/Factor.py in __str__(self)
    426 
    427     def __str__(self):
--> 428         return self._str(phi_or_p='phi', html=False)
    429 
    430     def _str(self, phi_or_p, html=False):

/home/ankur/pgmpy/pgmpy/factors/Factor.py in _str(self, phi_or_p, html)
    444             string_header = self.scope()
    445             string_header.append('{phi_or_p}({variables})'.format(phi_or_p=phi_or_p,
--> 446                                                                   variables=','.join(string_header)))
    447 
    448         # fun and gen are functions to generate the different values of

TypeError: sequence item 0: expected str instance, int found
```

Happening because of newer representation of states.


Changed files:
pgmpy/factors/Factor.py

diff --git a/pgmpy/factors/Factor.py b/pgmpy/factors/Factor.py
index 6c836664..22085f88 100644
--- a/pgmpy/factors/Factor.py
+++ b/pgmpy/factors/Factor.py
@@ -435,9 +435,9 @@ class Factor:
         if html:
             html_string_header = '{tr}{variable_cols}{phi}'.format(
                 tr='<tr',
-                variable_cols=''.join(['<td><b>{var}</b></td>'.format(var=var) for var in self.variables]),
+                variable_cols=''.join(['<td><b>{var}</b></td>'.format(var=str(var)) for var in self.variables]),
                 phi='<td><b>{phi_or_p}{vars}</b><d></tr>'.format(phi_or_P=phi_or_p,
-                                                                 vars=', '.join(self.variables)))
+                                                                 vars=', '.join([str(var) for var in self.variables])))
             string_list.append(html_string_header)
         else:
             string_header = self.scope()
Repository: pgmpy/pgmpy
Issue: Broken Factor Product

factor product throws a TypeError that input parameters must be factors.

``` python3
print(phi1)
A               B               phi(A, B)
--------------------------------
A_0             B_0             1.0
A_0             B_1             100.0
A_1             B_0             90.0
A_1             B_1             10.0


print(phi2)
B               C               phi(B, C)
--------------------------------
B_0             C_0             10.0
B_0             C_1             80.0
B_1             C_0             70.0
B_1             C_1             30.0


phi1 * phi2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-48-e0a56e1ddb88> in <module>()
----> 1 phi1 * phi2

/home/ankur/pgmpy/pgmpy/factors/Factor.py in __mul__(self, other)
    370 
    371     def __mul__(self, other):
--> 372         return self.product(other)
    373 
    374     def __eq__(self, other):

/home/ankur/pgmpy/pgmpy/factors/Factor.py in product(self, *factors)
    300                 ('x3', ['x3_0', 'x3_1']), ('x4', ['x4_0', 'x4_1'])])
    301         """
--> 302         return factor_product(self, *factors)
    303 
    304     def divide(self, factor):

/home/ankur/pgmpy/pgmpy/factors/Factor.py in factor_product(*args)
    479     """
    480     if not all(isinstance(phi, Factor) for phi in args):
--> 481         raise TypeError("Input parameters must be factors")
    482     return functools.reduce(lambda phi1, phi2: _bivar_factor_operation(phi1, phi2, operation='M'), args)
    483 

TypeError: Input parameters must be factors
```


Changed files:
pgmpy/tests/test_factors/test_Factor.py, pgmpy/factors/Factor.py

diff --git a/pgmpy/factors/Factor.py b/pgmpy/factors/Factor.py
index dcb07e93..1bcab70a 100644
--- a/pgmpy/factors/Factor.py
+++ b/pgmpy/factors/Factor.py
@@ -503,8 +503,8 @@ def factor_product(*args):
     --------
     factor_divide
     """
-    # if not all(isinstance(phi, Factor) for phi in args):
-    #     raise TypeError("Input parameters must be factors")
+    if not all(isinstance(phi, Factor) for phi in args):
+        raise TypeError("Input parameters must be factors")
     return functools.reduce(lambda phi1, phi2: _bivar_factor_operation(phi1, phi2, operation='M'), args)
 
 
diff --git a/pgmpy/tests/test_factors/test_Factor.py b/pgmpy/tests/test_factors/test_Factor.py
index af33202c..9bfa06c0 100644
--- a/pgmpy/tests/test_factors/test_Factor.py
+++ b/pgmpy/tests/test_factors/test_Factor.py
@@ -152,7 +152,6 @@ class TestFactorMethods(unittest.TestCase):
              ('x2', ['x2_0', 'x2_1']),
              ('x3', ['x3_0', 'x3_1'])]))
 
-    @unittest.skip('fix this issue #233')
     def test_factor_product_non_factor_arg(self):
         from pgmpy import factors
         self.assertRaises(TypeError, factors.factor_product, 1, 2)