Skip to content

Commit

Permalink
Removed support for Python 2.7. To use hookee with Python 2.7, pin …
Browse files Browse the repository at this point in the history
…`hookee>=1.2,<2`.
  • Loading branch information
alexdlaird committed Oct 25, 2020
1 parent 17f3998 commit 6535aa3
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 121 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ os: linux
dist: xenial
language: python
python:
- "2.7"
- "3.5"
- "3.8"
install:
Expand Down Expand Up @@ -34,9 +33,7 @@ jobs:
language: shell
osx_image: "xcode11.2"
install:
- python3 -m pip install virtualenv
- python3 -m virtualenv venv
- make install
- export PYTHON_BIN=python3
- name: "Windows, Python: 3.7"
os: windows
language: shell
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/alexdlaird/hookee/compare/1.2.5...HEAD)
## [Unreleased](https://github.com/alexdlaird/hookee/compare/2.0.0...HEAD)

## [2.0.0](https://github.com/alexdlaird/hookee/compare/1.2.5...2.0.0) - 2019-10-25
### Removed
- Support for Python 2.7. To use `hookee` with Python 2.7, pin `hookee>=1.2,<2`.

## [1.2.5](https://github.com/alexdlaird/hookee/compare/1.2.4...1.2.5) - 2019-10-15
### Added
Expand Down
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

| Version | Supported |
| ------- | ------------------ |
| 2.0.x | :white_check_mark: |
| 1.2.x | :white_check_mark: |
| < 1.2.x | :x: |

Expand Down
6 changes: 2 additions & 4 deletions hookee/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

from hookee import HookeeManager, pluginmanager

from future.utils import iteritems

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.2.2"
__version__ = "2.0.0"


@click.group(invoke_without_command=True)
Expand Down Expand Up @@ -50,7 +48,7 @@ def hookee(ctx, **kwargs):
ctx.exit("hookee/{} Python/{}".format(__version__, platform.python_version()))

ctx.ensure_object(dict)
for key, value in iteritems(kwargs):
for key, value in kwargs.items():
if value:
ctx.obj[key] = value

Expand Down
6 changes: 3 additions & 3 deletions hookee/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import click
import confuse

from hookee.exception import HookeeConfigError

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.2.5"

from hookee.exception import HookeeConfigError
__version__ = "2.0.0"

template = {
"port": int,
Expand Down
2 changes: 1 addition & 1 deletion hookee/hookeemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.2.5"
__version__ = "2.0.0"


class HookeeManager:
Expand Down
21 changes: 6 additions & 15 deletions hookee/pluginmanager.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import importlib.util
import os

from flask import current_app

from hookee import util

from pluginbase import PluginBase

from hookee import util
from hookee.exception import HookeePluginValidationError

if util.python3_gte():
import importlib.util
else:
import imp

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.2.2"
__version__ = "2.0.0"

BLUEPRINT_PLUGIN = "blueprint"
REQUEST_PLUGIN = "request"
Expand Down Expand Up @@ -134,12 +128,9 @@ def build_from_file(path):
"""
module_name = os.path.splitext(os.path.basename(path))[0]

if util.python3_gte():
spec = importlib.util.spec_from_file_location(module_name, path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
else:
module = imp.load_source(module_name, path)
spec = importlib.util.spec_from_file_location(module_name, path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

return Plugin.build_from_module(module)

Expand Down
24 changes: 6 additions & 18 deletions hookee/server.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
import logging
import threading
import time
from http import HTTPStatus
from urllib.error import URLError
from urllib.request import urlopen, Request

from flask import Flask

from future.standard_library import install_aliases

from hookee import pluginmanager

install_aliases()

from urllib.request import urlopen, Request
from urllib.error import URLError

try:
from http import HTTPStatus as StatusCodes
except ImportError: # pragma: no cover
try:
from http import client as StatusCodes
except ImportError:
import httplib as StatusCodes

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.1.0"
__version__ = "2.0.0"

werkzeug_logger = logging.getLogger("werkzeug")
werkzeug_logger.setLevel(logging.ERROR)
Expand Down Expand Up @@ -100,7 +88,7 @@ def start(self):
self._thread = threading.Thread(target=self._loop)
self._thread.start()

while self._server_status() != StatusCodes.OK:
while self._server_status() != HTTPStatus.OK:
time.sleep(1)

self.print_close_header()
Expand All @@ -125,7 +113,7 @@ def _server_status(self):
try:
return urlopen("http://127.0.0.1:{}/status".format(self.port)).getcode()
except URLError:
return StatusCodes.INTERNAL_SERVER_ERROR
return HTTPStatus.INTERNAL_SERVER_ERROR

def print_close_header(self):
self.print_util.print_basic(" * Port: {}".format(self.port))
Expand Down
13 changes: 6 additions & 7 deletions hookee/tunnel.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import threading
import time

from pyngrok import ngrok
from pyngrok import ngrok, conf
from pyngrok.conf import PyngrokConfig

from pyngrok.exception import PyngrokError

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.1.0"
__version__ = "2.0.0"


class Tunnel:
Expand Down Expand Up @@ -40,6 +39,7 @@ def __init__(self, hookee_manager):

self.pyngrok_config = PyngrokConfig(auth_token=self.config.get("auth_token"),
region=self.config.get("region"))
conf.set_default(self.pyngrok_config)

self.public_url = None
self.ngrok_process = None
Expand Down Expand Up @@ -81,7 +81,7 @@ def start(self):
self.print_close_header()

def _start_tunnel(self):
options = {}
options = {"bind_tls": True}
subdomain = self.config.get("subdomain")
hostname = self.config.get("hostname")
host_header = self.config.get("host_header")
Expand All @@ -96,8 +96,7 @@ def _start_tunnel(self):
options["auth"] = auth

self.public_url = ngrok.connect(self.port,
pyngrok_config=self.pyngrok_config,
options=options).replace("http", "https")
**options).public_url
self.ngrok_process = ngrok.get_ngrok_process()

def stop(self):
Expand All @@ -113,6 +112,6 @@ def stop(self):

def print_close_header(self):
self.print_util.print_basic(
" * Tunnel: {} -> http://127.0.0.1:{}".format(self.public_url.replace("http://", "https://"), self.port),
" * Tunnel: {} -> http://127.0.0.1:{}".format(self.public_url, self.port),
print_when_logging=True)
self.print_util.print_close_header()
28 changes: 2 additions & 26 deletions hookee/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import json
import logging
import os
import sys
import xml.dom.minidom

import click

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.2.2"
__version__ = "2.0.0"

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -154,26 +153,6 @@ def print_basic(self, msg="", color=None, bold=False, print_when_logging=False):
print(msg)


def python3_gte():
"""
Check if running on a Python 3.x interpreter.
:return: ``True`` if Python 3.
:rtype: bool
"""
return sys.version_info >= (3, 0)


def python36_gte():
"""
Check if running on a Python 3.6 or higher interpreter.
:return: ``True`` if Python 3.6 or higher.
:rtype: bool
"""
return sys.version_info >= (3, 6)


def get_functions(mod):
"""
Get a list of functions for the given module.
Expand All @@ -195,10 +174,7 @@ def get_args(func):
:return: The list of args.
:rtype: list[str]
"""
if python3_gte():
return inspect.getfullargspec(func)[0]
else:
return inspect.getargspec(func)[0]
return inspect.getfullargspec(func)[0]


def get_module_name(module):
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
coverage
codecov
nose
mock
twine
requests
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
future>=0.17.1
pluginbase>=1.0.0
confuse>=1.3.0
python-dotenv>=0.10.3
flask>=1.1.0
click>=7.1.0
pyngrok>=4.1,<4.2
pyngrok>=5.0.0
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.2.5"
__version__ = "2.0.0"

with open("README.md", "r") as f:
long_description = f.read()
Expand All @@ -12,15 +12,15 @@
version=__version__,
packages=["hookee",
"hookee.plugins"],
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
python_requires=">=3.5",
install_requires=[
"future",
"pluginbase",
"confuse",
"python-dotenv",
"flask",
"click",
"pyngrok>=4.1,<4.2",
"pyngrok>=5.0.0",
],
entry_points="""
[console_scripts]
Expand Down Expand Up @@ -55,8 +55,6 @@
"Operating System :: POSIX :: BSD :: FreeBSD",
"Operating System :: POSIX :: Linux",
"Operating System :: Unix",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
Expand Down
13 changes: 4 additions & 9 deletions tests/managedtestcase.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import time
import sys
import time
from contextlib import contextmanager
from io import StringIO

from hookee import HookeeManager
from hookee.conf import Config

from hookee import HookeeManager, util
from tests.testcase import HookeeTestCase

if util.python3_gte():
from io import StringIO
else:
from io import BytesIO as StringIO

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.2.1"
__version__ = "2.0.0"


class ManagedTestCase(HookeeTestCase):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os

import mock
from unittest import mock

from hookee.cli import hookee
from tests.testcase import HookeeTestCase

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.2.4"
__version__ = "2.0.0"


class TestCli(HookeeTestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import mock
from unittest import mock

from tests.testcase import HookeeTestCase

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.2.4"
__version__ = "2.0.0"


class TestConfig(HookeeTestCase):
Expand Down
Loading

0 comments on commit 6535aa3

Please sign in to comment.