Skip to content

Commit

Permalink
Embedders - temporarily fix get_proxy function
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Jun 17, 2022
1 parent c05b4fb commit 09a5c2d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
37 changes: 37 additions & 0 deletions orangecontrib/text/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Set where NLTK data is downloaded
import os

# temporary solution - remove when Orange 3.33 is released
# it must be imported before nltk_data_dir
from typing import Optional, Dict
from Orange.misc.utils import embedder_utils


def _get_proxies() -> Optional[Dict[str, str]]:
"""
Return dict with proxy addresses if they exist.
Returns
-------
proxy_dict
Dictionary with format {proxy type: proxy address} or None if
they not set.
"""
def add_scheme(url: Optional[str]) -> Optional[str]:
if url is not None and "://" not in url:
# if no scheme default to http - as other libraries do (e.g. requests)
return f"http://{url}"
else:
return url

http_proxy = add_scheme(os.environ.get("http_proxy"))
https_proxy = add_scheme(os.environ.get("https_proxy"))
proxy_dict = {}
if http_proxy:
proxy_dict["http://"] = http_proxy
if https_proxy:
proxy_dict["https://"] = https_proxy
return proxy_dict if proxy_dict else None


embedder_utils.get_proxies = _get_proxies
# remove to here


from orangecontrib.text.misc import nltk_data_dir
os.environ['NLTK_DATA'] = nltk_data_dir()

Expand Down
10 changes: 10 additions & 0 deletions orangecontrib/text/tests/test_documentembedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ def test_invalid_parameters(self):
with self.assertRaises(ValueError):
self.embedder = DocumentEmbedder(aggregator='average')

def test_remove_temporary_proxy_solution(self):
"""
When it starts to fail:
- remove this test
- remove temporary implementation of get_proxy() function in text.__inint__
- set minimum version of Orange on 3.33
"""
import Orange
self.assertGreater("3.33.0", Orange.__version__)


if __name__ == "__main__":
unittest.main()

0 comments on commit 09a5c2d

Please sign in to comment.