Skip to content

Commit

Permalink
Merge pull request #4527 from RasaHQ/drop-py-3.5
Browse files Browse the repository at this point in the history
Drop Python 3.5 support
  • Loading branch information
ricwo authored Sep 27, 2019
2 parents 19fa8a3 + 20a9370 commit 7a2b7c2
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 89 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ jobs:
- make types
- &run-tests
stage: test
name: "Test 3.5"
python: "3.5"
name: "Test 3.6"
python: "3.6"
script:
- make test
- <<: *run-tests
name: "Test 3.6"
python: '3.6'
- <<: *run-tests
name: "Test 3.7"
python: '3.7'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Changed

Removed
-------
- Removed Python 3.5 support

Fixed
-----
Expand Down
12 changes: 4 additions & 8 deletions rasa/core/channels/console.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
# this builtin is needed so we can overwrite in test
import aiohttp
import json
import logging
import questionary
from typing import Text, Optional

import aiohttp
import questionary
from aiohttp import ClientTimeout
from async_generator import async_generator, yield_
from prompt_toolkit.styles import Style

from rasa.cli import utils as cli_utils

from rasa.core import utils
from rasa.core.channels.channel import UserMessage
from rasa.core.channels.channel import RestInput
from rasa.core.channels.channel import UserMessage
from rasa.core.constants import DEFAULT_SERVER_URL
from rasa.core.interpreter import INTENT_MESSAGE_PREFIX

logger = logging.getLogger(__name__)


DEFAULT_STREAM_READING_TIMEOUT_IN_SECONDS = 10


Expand Down Expand Up @@ -88,7 +85,6 @@ async def send_message_receive_block(server_url, auth_token, sender_id, message)
return await resp.json()


@async_generator # needed for python 3.5 compatibility
async def send_message_receive_stream(server_url, auth_token, sender_id, message):
payload = {"sender": sender_id, "message": message}

Expand All @@ -102,7 +98,7 @@ async def send_message_receive_stream(server_url, auth_token, sender_id, message

async for line in resp.content:
if line:
await yield_(json.loads(line.decode("utf-8")))
yield json.loads(line.decode("utf-8"))


async def record_messages(
Expand Down
13 changes: 6 additions & 7 deletions rasa/core/lock_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import json
import logging
import os
from typing import Text, Optional, Union
from typing import Text, Optional, Union, AsyncGenerator, Coroutine

from async_generator import asynccontextmanager, async_generator, yield_
from async_generator import asynccontextmanager

from rasa.core.constants import DEFAULT_LOCK_LIFETIME
from rasa.core.lock import TicketLock, NO_TICKET_ISSUED
Expand Down Expand Up @@ -124,13 +124,12 @@ def issue_ticket(
return ticket

@asynccontextmanager
@async_generator
async def lock(
self,
conversation_id: Text,
lock_lifetime: int = LOCK_LIFETIME,
wait_time_in_seconds: Union[int, float] = 1,
) -> None:
) -> AsyncGenerator[TicketLock, None]:
"""Acquire lock with lifetime `lock_lifetime`for `conversation_id`.
Try acquiring lock with a wait time of `wait_time_in_seconds` seconds
Expand All @@ -140,10 +139,10 @@ async def lock(
ticket = self.issue_ticket(conversation_id, lock_lifetime)

try:
# have to use async_generator.yield_() for py 3.5 compatibility
await yield_(
await self._acquire_lock(conversation_id, ticket, wait_time_in_seconds)
yield await self._acquire_lock(
conversation_id, ticket, wait_time_in_seconds
)

finally:
self.cleanup(conversation_id, ticket)

Expand Down
10 changes: 1 addition & 9 deletions rasa/core/training/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,7 @@ def with_cycles_removed(self) -> "StoryGraph":
# we need to remove the start steps and replace them with steps ending
# in a special end checkpoint

# as in python 3.5, dict is not ordered, in order to generate
# reproducible result with random seed in python 3.5, we have
# to use OrderedDict
if sys.version_info >= (3, 6):
story_steps = {s.id: s for s in self.story_steps}
else:
from collections import OrderedDict

story_steps = OrderedDict([(s.id, s) for s in self.story_steps])
story_steps = {s.id: s for s in self.story_steps}

# collect all overlapping checkpoints
# we will remove unused start ones
Expand Down
3 changes: 0 additions & 3 deletions rasa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ def unpack_model(

tar = tarfile.open(model_file)

# cast `working_directory` as str for py3.5 compatibility
working_directory = str(working_directory)

# All files are in a subdirectory.
tar.extractall(working_directory)
tar.close()
Expand Down
17 changes: 9 additions & 8 deletions rasa/nlu/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def get_component_class(component_name: Text) -> Type["Component"]:
return class_from_module_path(component_name)

except AttributeError:
# when component_name is a path to a class but the path does not contain that class
# when component_name is a path to a class but the path does not contain
# that class
module_name, _, class_name = component_name.rpartition(".")
raise Exception(
"Failed to find class '{}' in module '{}'.\n"
Expand All @@ -155,23 +156,23 @@ def get_component_class(component_name: Text) -> Type["Component"]:
except ImportError as e:
# when component_name is a path to a class but that path is invalid or
# when component_name is a class name and not part of old_style_names
# TODO: Raise ModuleNotFoundError when component_name is a path to a class but that path is invalid
# as soon as we no longer support Python 3.5. See PR #4166 for details

is_path = "." in component_name

if is_path:
module_name, _, _ = component_name.rpartition(".")
exception_message = "Failed to find module '{}'. \n{}".format(
module_name, e.msg
module_name, e
)
else:
exception_message = "Cannot find class '{0}' from global namespace. Please check that there is no typo in the class "
"name and that you have imported the class into the global namespace.".format(
component_name
exception_message = (
"Cannot find class '{0}' from global namespace. "
"Please check that there is no typo in the class "
"name and that you have imported the class into the global "
"namespace.".format(component_name)
)

raise Exception(exception_message)
raise ModuleNotFoundError(exception_message)
else:
# DEPRECATED ensures compatibility, remove in future versions
logger.warning(
Expand Down
7 changes: 4 additions & 3 deletions rasa/nlu/training_data/training_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ def filter_by_intent(self, intent: Text):
def __hash__(self) -> int:
from rasa.core import utils as core_utils

# Sort keys to ensure dictionary order in Python 3.5
stringified = self.nlu_as_json(sort_keys=True) + self.nlg_as_markdown()
stringified = self.nlu_as_json() + self.nlg_as_markdown()
text_hash = core_utils.get_text_hash(stringified)

return int(text_hash, 16)
Expand Down Expand Up @@ -222,7 +221,9 @@ def as_json(self) -> Text:
return self.nlu_as_json()

def nlg_as_markdown(self) -> Text:
"""Generates the markdown representation of the response phrases(NLG) of TrainingData."""
"""Generates the markdown representation of the response phrases(NLG) of
TrainingData."""

from rasa.nlu.training_data.formats import ( # pytype: disable=pyi-error
NLGMarkdownWriter,
)
Expand Down
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"aioresponses~=0.6.0",
"moto~=1.3.8",
"fakeredis~=1.0",
# upstream dep from fakeredis, should be removed if fakeredis properly depends on
# at least 1.12
"six>=1.12.0",
]

install_requires = [
Expand Down Expand Up @@ -108,11 +105,11 @@
"License :: OSI Approved :: Apache Software License",
# supported python versions
"Programming Language :: Python",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Software Development :: Libraries",
],
python_requires=">=3.6",
packages=find_packages(exclude=["tests", "tools", "docs", "contrib"]),
entry_points={"console_scripts": ["rasa=rasa.__main__:main"]},
version=__version__,
Expand Down
Loading

0 comments on commit 7a2b7c2

Please sign in to comment.