Skip to content

Commit

Permalink
Add windows support (#382)
Browse files Browse the repository at this point in the history
* Start on windows support

* More windows fixes

* Remove linting on appveyor

* Get it linting and passing on unix again

* Try namedtempfile for logging test

* Fix PYTHONPATH for tests

* Skip file cleanup on error

* Add helper test and couple more windows tweaks

* Add appveyor badge

* Forgot to lint

* That shound't have been committed
  • Loading branch information
jacobtomlinson committed Jan 17, 2018
1 parent ea11086 commit eaac31e
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 85 deletions.
3 changes: 1 addition & 2 deletions README.md
@@ -1,7 +1,6 @@
![opsdroid](https://github.com/opsdroid/style-guidelines/raw/master/logos/logo-wide-light.png)

[![Build Status](https://travis-ci.org/opsdroid/opsdroid.svg?branch=release)](https://travis-ci.org/opsdroid/opsdroid) [![codecov](https://codecov.io/gh/opsdroid/opsdroid/branch/master/graph/badge.svg)](https://codecov.io/gh/opsdroid/opsdroid) [![Updates](https://pyup.io/repos/github/opsdroid/opsdroid/shield.svg)](https://pyup.io/repos/github/opsdroid/opsdroid/) [![Dependency Status](https://dependencyci.com/github/opsdroid/opsdroid/badge)](https://dependencyci.com/github/opsdroid/opsdroid)
[![Docker Image](https://img.shields.io/badge/docker-ready-blue.svg)](https://hub.docker.com/r/opsdroid/opsdroid/) [![Docker Layers](https://images.microbadger.com/badges/image/opsdroid/opsdroid.svg)](https://microbadger.com/#/images/opsdroid/opsdroid) [![Documentation Status](https://readthedocs.org/projects/opsdroid/badge/?version=stable)](http://opsdroid.readthedocs.io/en/stable/?badge=stable) [![Gitter Badge](https://badges.gitter.im/opsdroid.png)](https://gitter.im/opsdroid)
[![Build Status](https://travis-ci.org/opsdroid/opsdroid.svg?branch=release)](https://travis-ci.org/opsdroid/opsdroid) [![Build status](https://ci.appveyor.com/api/projects/status/9qodmi74r234x4cv/branch/master?svg=true)](https://ci.appveyor.com/project/jacobtomlinson/opsdroid/branch/master) [![codecov](https://codecov.io/gh/opsdroid/opsdroid/branch/master/graph/badge.svg)](https://codecov.io/gh/opsdroid/opsdroid) [![Updates](https://pyup.io/repos/github/opsdroid/opsdroid/shield.svg)](https://pyup.io/repos/github/opsdroid/opsdroid/) [![Dependency Status](https://dependencyci.com/github/opsdroid/opsdroid/badge)](https://dependencyci.com/github/opsdroid/opsdroid) [![Docker Image](https://img.shields.io/badge/docker-ready-blue.svg)](https://hub.docker.com/r/opsdroid/opsdroid/) [![Docker Layers](https://images.microbadger.com/badges/image/opsdroid/opsdroid.svg)](https://microbadger.com/#/images/opsdroid/opsdroid) [![Documentation Status](https://readthedocs.org/projects/opsdroid/badge/?version=stable)](http://opsdroid.readthedocs.io/en/stable/?badge=stable) [![Gitter Badge](https://badges.gitter.im/opsdroid.png)](https://gitter.im/opsdroid)

An open source chat bot framework written in python. It is designed to be extendable, scalable and simple.

Expand Down
19 changes: 19 additions & 0 deletions appveyor.yml
@@ -0,0 +1,19 @@
environment:

matrix:

# For Python versions available on Appveyor, see
# http://www.appveyor.com/docs/installed-software#python

- PYTHON: "C:\\Python35-x64"
TOXENV: "py35"
- PYTHON: "C:\\Python36-x64"
TOXENV: "py36"

install:
- "%PYTHON%\\python.exe -m pip install tox"

build: off

test_script:
- "%PYTHON%\\python.exe -m tox"
6 changes: 4 additions & 2 deletions opsdroid/core.py
Expand Up @@ -2,6 +2,7 @@

import copy
import logging
import os
import signal
import sys
import weakref
Expand Down Expand Up @@ -40,8 +41,9 @@ def __init__(self):
self.connectors = []
self.connector_tasks = []
self.eventloop = asyncio.get_event_loop()
for sig in (signal.SIGINT, signal.SIGTERM):
self.eventloop.add_signal_handler(sig, self.call_stop)
if os.name != 'nt':
for sig in (signal.SIGINT, signal.SIGTERM):
self.eventloop.add_signal_handler(sig, self.call_stop)
self.skills = []
self.memory = Memory()
self.loader = Loader(self)
Expand Down
9 changes: 9 additions & 0 deletions opsdroid/helper.py
@@ -1,5 +1,8 @@
"""Helper functions to use within OpsDroid."""

import os
import stat


def get_opsdroid():
"""Return the running opsdroid instance."""
Expand All @@ -8,3 +11,9 @@ def get_opsdroid():
return OpsDroid.instances[0]

return None


def del_rw(action, name, exc):
"""Error handler for removing read only files."""
os.chmod(name, stat.S_IWRITE)
os.remove(name)
19 changes: 11 additions & 8 deletions opsdroid/loader.py
Expand Up @@ -82,8 +82,9 @@ def build_module_path(self, path_type, config):
path = MODULES_DIRECTORY + "." + config["type"] + \
"." + config["name"]
elif path_type == "install":
path = self.modules_directory + "/" + config["type"] + \
"/" + config["name"]
path = os.path.join(self.modules_directory,
config["type"],
config["name"])
return path

@staticmethod
Expand Down Expand Up @@ -118,7 +119,7 @@ def pip_install_deps(requirements_path):

@staticmethod
def _load_intents(config):
intent_file = config["install_path"] + "/intents.md"
intent_file = os.path.join(config["install_path"], "intents.md")
if os.path.isfile(intent_file):
with open(intent_file, 'r') as intent_file_handle:
intents = intent_file_handle.read()
Expand Down Expand Up @@ -314,9 +315,10 @@ def _install_module(self, config):
_LOGGER.error("Install of %s failed.", config["name"])

# Install module dependencies
if os.path.isfile(config["install_path"] + "/requirements.txt"):
self.pip_install_deps(config["install_path"] +
"/requirements.txt")
if os.path.isfile(os.path.join(
config["install_path"], "requirements.txt")):
self.pip_install_deps(os.path.join(config["install_path"],
"requirements.txt"))

def _install_git_module(self, config):
"""Install a module from a git repository."""
Expand Down Expand Up @@ -358,8 +360,9 @@ def _install_local_module(config):

if os.path.isfile(config["path"]):
os.makedirs(config["install_path"], exist_ok=True)
shutil.copyfile(config["path"], config["install_path"] +
"/__init__.py")
shutil.copyfile(config["path"],
os.path.join(config["install_path"],
"__init__.py"))
installed = True

if not installed:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_core.py
Expand Up @@ -112,6 +112,7 @@ def test_start_databases(self):
def test_start_connectors(self):
with OpsDroid() as opsdroid:
opsdroid.start_connector_tasks([])

module = {}
module["config"] = {}
module["module"] = importlib.import_module(
Expand All @@ -125,6 +126,7 @@ def test_start_connectors(self):
def test_start_connectors_not_implemented(self):
with OpsDroid() as opsdroid:
opsdroid.start_connector_tasks([])

module = {}
module["config"] = {}
module["module"] = importlib.import_module(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_helper.py
@@ -1,6 +1,16 @@

import unittest
import unittest.mock as mock

from opsdroid.helper import del_rw


class TestHelper(unittest.TestCase):
"""Test the opsdroid helper classes."""

def test_del_rw(self):
with mock.patch('os.chmod') as mock_chmod,\
mock.patch('os.remove') as mock_remove:
del_rw(None, None, None)
self.assertTrue(mock_chmod.called)
self.assertTrue(mock_remove.called)

0 comments on commit eaac31e

Please sign in to comment.