Skip to content

Commit 2b1ca8c

Browse files
diningPhilosopher64Prabhakar Kumar
authored and
Prabhakar Kumar
committed
feature: Enable python3.6 backward compatibility
1 parent ee790d6 commit 2b1ca8c

File tree

8 files changed

+55
-31
lines changed

8 files changed

+55
-31
lines changed

.github/workflows/release.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,22 @@ jobs:
3838
with:
3939
ref: ${{github.sha}}
4040

41-
- name: Set up Python 3.7
41+
- name: Set up Python 3.6
4242
uses: actions/setup-python@v2
4343
with:
44-
python-version: 3.7
44+
python-version: 3.6
4545

4646
- name: Install dependencies
47+
# Installing wheel package will slightly speed-up installing dependencies.
48+
# Installing the package with "[dev]" flag will install test dependecies as well,
49+
# enabling us to run pytest.
4750
run: |
4851
python -m pip install --upgrade pip
49-
python -m pip install --upgrade black
50-
51-
- name: Lint with black
52-
run: black --check .
52+
python -m pip install wheel
53+
pip install .[dev]
5354
5455
- name: Run Python Tests
55-
run: python setup.py test
56+
run: python -m pytest
5657

5758
build_and_publish:
5859
needs: [python_tests, node_tests]
@@ -65,10 +66,10 @@ jobs:
6566
with:
6667
ref: ${{github.sha}}
6768

68-
- name: Set up Python 3.7
69+
- name: Set up Python 3.6
6970
uses: actions/setup-python@v2
7071
with:
71-
python-version: 3.7
72+
python-version: 3.6
7273

7374
- name: Use Node.js 13.x
7475
uses: actions/setup-node@v2

.github/workflows/run-tests.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
strategy:
3333
matrix:
34-
python-version: [3.7, 3.8]
34+
python-version: [3.6, 3.7, 3.8, 3.9]
3535

3636
steps:
3737
- name: Checkout
@@ -43,17 +43,19 @@ jobs:
4343
python-version: ${{ matrix.python-version }}
4444

4545
- name: Install dependencies
46+
# Installing wheel package will slightly speed-up installing dependencies.
47+
# Installing the package with "[dev]" flag will install test dependecies as well,
48+
# enabling us to run pytest.
4649
run: |
4750
python -m pip install --upgrade pip
48-
pip install black pytest
51+
python -m pip install wheel
52+
pip install .[dev]
4953
5054
- name: Lint with black
51-
run: |
52-
black --check .
55+
run: black --check .
5356

5457
- name: Test with pytest
55-
run: |
56-
python setup.py test
58+
run: python -m pytest
5759

5860
generate_and_upload_code_coverage:
5961
needs: [python_tests, node_tests]
@@ -75,7 +77,9 @@ jobs:
7577

7678
- name: Install Python build dependencies
7779
run: |
78-
pip install -e .[DEV]
80+
python -m pip install --upgrade pip
81+
python -m pip install wheel
82+
pip install .[dev]
7983
8084
- name: Generate Code Coverage report for Python code
8185
run: |

jupyter_matlab_proxy/app_state.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import asyncio
44
from jupyter_matlab_proxy import mwi_environment_variables as mwi_env
55
from jupyter_matlab_proxy import mwi_embedded_connector as mwi_connector
6+
from jupyter_matlab_proxy import util
67
import os
78
import json
89
import pty
10+
import sys
911
import logging
1012
from datetime import datetime, timezone, timedelta
1113
import socket
@@ -460,7 +462,12 @@ async def matlab_stderr_reader():
460462
self.logs["matlab"].append(line)
461463
await self.handle_matlab_output()
462464

463-
loop = asyncio.get_running_loop()
465+
loop = (
466+
asyncio.get_running_loop()
467+
if util.is_python_version_newer_than_3_6()
468+
else asyncio.get_event_loop()
469+
)
470+
464471
self.tasks["matlab_stderr_reader"] = loop.create_task(matlab_stderr_reader())
465472

466473
async def stop_matlab(self):

jupyter_matlab_proxy/devel.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ def matlab(args):
140140
from pathlib import Path
141141

142142
parser = argparse.ArgumentParser()
143-
subparsers = parser.add_subparsers(dest="cmd", required=True)
143+
subparsers = (
144+
parser.add_subparsers(dest="cmd", required=True)
145+
if sys.version_info[:2] >= (3, 7)
146+
else parser.add_subparsers(dest="cmd")
147+
)
144148
matlab_parser = subparsers.add_parser("matlab")
145149
matlab_parser.add_argument("--ready-delay", default=2, type=int)
146150
matlab_parser.set_defaults(func=matlab)

jupyter_matlab_proxy/util/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
# Copyright 2020 The MathWorks, Inc.
2+
import sys
3+
4+
5+
def is_python_version_newer_than_3_6():
6+
"""Returns True if the python version being used is 3.7 or higher, else False.
7+
8+
Returns:
9+
Boolean: True if python version >= 3.7, False otherwise.
10+
"""
11+
return sys.version_info[:2] >= (3, 7)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[metadata]
2-
license_files = LICENSE
2+
license_files = LICENSE.md
33
[aliases]
44
test=pytest

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ def run(self):
4848

4949
setuptools.setup(
5050
name="jupyter-matlab-proxy",
51-
version="0.3.2",
51+
version="0.3.3",
5252
url="https://github.com/mathworks/jupyter-matlab-proxy",
5353
author="The MathWorks, Inc.",
5454
author_email="[email protected]",
5555
license="MATHWORKS CLOUD REFERENCE ARCHITECTURE LICENSE",
56-
description="Jupyter extension to proxy MATLAB JavaScript Desktop",
56+
description="Jupyter Server Proxy for MATLAB",
5757
long_description=long_description,
5858
long_description_content_type="text/markdown",
5959
packages=setuptools.find_packages(exclude=["devel", "tests"]),
6060
keywords=["Jupyter"],
6161
classifiers=["Framework :: Jupyter"],
62-
python_requires="~=3.7",
62+
python_requires="~=3.6",
6363
install_requires=["jupyter-server-proxy", "aiohttp>=3.7.4"],
6464
setup_requires=["pytest-runner"],
6565
tests_require=tests_require,
66-
extras_require={"dev": ["aiohttp-devtools"] + tests_require},
66+
extras_require={"dev": ["aiohttp-devtools", "black"] + tests_require},
6767
entry_points={
6868
"jupyter_serverproxy_servers": ["matlab = jupyter_matlab_proxy:setup_matlab"],
6969
"console_scripts": ["matlab-jupyter-app = jupyter_matlab_proxy.app:main"],

tests/util/test_mwi_custom_http_headers.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest, os, time, json, stat
55
from jupyter_matlab_proxy.util import mwi_custom_http_headers
66
from jupyter_matlab_proxy import mwi_environment_variables as mwi_env
7-
from contextlib import nullcontext as does_not_raise
87

98

109
def test_get_custom_header_env_var():
@@ -30,7 +29,7 @@ def non_existent_random_json_file_fixture(tmp_path):
3029
Returns:
3130
PosixPath: of the non-existent random json file.
3231
"""
33-
random_file = tmp_path / f"{str(time.time_ns())}.json"
32+
random_file = tmp_path / f'{str(time.time()).replace(".", "")}.json'
3433
return random_file
3534

3635

@@ -164,13 +163,12 @@ def test_check_file_validity_no_error(non_existent_temp_json_file, valid_json_co
164163
with open(random_json_file_with_valid_content, "w") as f:
165164
f.write(valid_json_content)
166165

167-
with does_not_raise():
168-
assert (
169-
mwi_custom_http_headers.__check_file_validity(
170-
random_json_file_with_valid_content
171-
)
172-
is True
166+
assert (
167+
mwi_custom_http_headers.__check_file_validity(
168+
random_json_file_with_valid_content
173169
)
170+
is True
171+
)
174172

175173

176174
def test_get_no_env_var():

0 commit comments

Comments
 (0)