Skip to content

Commit

Permalink
replace urllib with conda.gateways.conection Session
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Apr 26, 2020
1 parent b785f11 commit 212b481
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions conda_env/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import os
import re
import json
from conda._vendor.auxlib._vendor.six.moves import urllib

from conda.base.context import context
from conda.cli import common # TODO: this should never have to import form conda.cli
from conda.common.serialize import yaml_load_standard
from conda.core.prefix_data import PrefixData
from conda.gateways.connection.session import CondaSession
from conda.models.enums import PackageType
from conda.models.match_spec import MatchSpec
from conda.models.prefix_graph import PrefixGraph
Expand Down Expand Up @@ -146,10 +146,9 @@ def from_yaml(yamlstr, **kwargs):

def from_file(filename):
if any(filename.startswith(prefix) for prefix in ("https://", "http://")):
try:
yamlstr = urllib.request.urlopen(filename).read()
except urllib.error.HTTPError:
raise exceptions.EnvironmentFileNotFound(filename)
response = CondaSession().get(filename)
response.raise_for_status()
yamlstr = response.text
elif not os.path.exists(filename):
raise exceptions.EnvironmentFileNotFound(filename)
else:
Expand Down
3 changes: 2 additions & 1 deletion tests/conda_env/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from conda.core.prefix_data import PrefixData
from conda.base.context import conda_tests_ctxt_mgmt_def_pol
from conda.gateways.connection import HTTPError
from conda.models.match_spec import MatchSpec
from conda.common.io import env_vars
from conda.common.serialize import yaml_load
Expand Down Expand Up @@ -84,7 +85,7 @@ def test_http(self):
assert e.dependencies == f.dependencies

def test_http_raises(self):
with self.assertRaises(exceptions.EnvironmentFileNotFound):
with self.assertRaises(HTTPError):
env.from_file("https://raw.githubusercontent.com/conda/conda/master/tests/conda_env/support/does-not-exist.yml")


Expand Down

0 comments on commit 212b481

Please sign in to comment.