Skip to content

Commit

Permalink
Merge pull request #163 from marcelotrevisani/main
Browse files Browse the repository at this point in the history
Remain backwards compatible with Python 3.6 and 3.7
  • Loading branch information
mariusvniekerk authored Mar 8, 2022
2 parents e3e2b8d + 8ea95eb commit 41c9c8c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
python-version: [ 3.8 ]
python-version: [ 3.7, 3.8 ]
defaults:
run:
shell: bash -l {0}
Expand Down
2 changes: 1 addition & 1 deletion conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
Dict,
Iterator,
List,
Literal,
Optional,
Sequence,
Set,
Expand All @@ -36,6 +35,7 @@
import yaml

from ensureconda import ensureconda
from typing_extensions import Literal

from conda_lock.click_helpers import OrderedGroup
from conda_lock.common import read_file, read_json, relative_path, write_file
Expand Down
17 changes: 12 additions & 5 deletions conda_lock/conda_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
MutableSequence,
Optional,
Sequence,
TypedDict,
cast,
)
from urllib.parse import urlsplit, urlunsplit

from typing_extensions import TypedDict

from conda_lock.invoke_conda import (
PathLike,
_get_conda_flags,
Expand Down Expand Up @@ -159,9 +160,12 @@ def solve_conda(
def normalize_url(url: str) -> str:
for channel in channels:
candidate1 = channel.conda_token_replaced_url()
url = re.sub(rf"^{candidate1}(.*)", rf"{channel.url}\1", url)
if url.startswith(candidate1):
url = url.replace(candidate1, channel.url, 1)

candidate2 = channel.env_replaced_url()
url = re.sub(rf"^{candidate2}(.*)", rf"{channel.url}\1", url)
if url.startswith(candidate2):
url = url.replace(candidate2, channel.url, 1)
return url

# extract dependencies from package plan
Expand Down Expand Up @@ -314,7 +318,7 @@ def solve_specs_for_arch(
args.extend(specs)
logger.info("%s using specs %s", platform, specs)
proc = subprocess.run(
args,
[str(arg) for arg in args],
env=conda_env_override(platform),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down Expand Up @@ -437,7 +441,10 @@ def update_specs_for_arch(
*_get_conda_flags(channels=channels, platform=platform),
]
proc = subprocess.run(
args + ["-p", prefix, "--json", "--dry-run", *to_update],
[
str(arg)
for arg in args + ["-p", prefix, "--json", "--dry-run", *to_update]
],
env=conda_env_override(platform),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down
4 changes: 2 additions & 2 deletions conda_lock/invoke_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def determine_conda_executable(
if candidate is not None:
if is_micromamba(candidate):
if ensureconda.api.determine_micromamba_version(
candidate
str(candidate)
) < LooseVersion("0.17"):
mamba_root_prefix()
return candidate
Expand Down Expand Up @@ -102,7 +102,7 @@ def _invoke_conda(
if conda_flags:
common_args.extend(shlex.split(conda_flags))

cmd = [str(conda), *command_args, *common_args, *post_args]
cmd = [str(arg) for arg in [conda, *command_args, *common_args, *post_args]]

with subprocess.Popen(
cmd,
Expand Down
3 changes: 2 additions & 1 deletion conda_lock/src_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

from collections import defaultdict, namedtuple
from itertools import chain
from typing import ClassVar, Dict, List, Literal, Optional, Sequence, Set, Tuple, Union
from typing import ClassVar, Dict, List, Optional, Sequence, Set, Tuple, Union

from pydantic import BaseModel, Field, validator
from typing_extensions import Literal

from conda_lock.common import ordered_union, suffix_union
from conda_lock.errors import ChannelAggregationError
Expand Down
4 changes: 3 additions & 1 deletion conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import pathlib

from functools import partial
from typing import AbstractSet, Any, List, Literal, Mapping, Optional, Sequence, Union
from typing import AbstractSet, Any, List, Mapping, Optional, Sequence, Union
from urllib.parse import urldefrag

import toml

from typing_extensions import Literal

from conda_lock.common import get_in
from conda_lock.lookup import get_forward_lookup as get_lookup
from conda_lock.src_parser import (
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ click
click-default-group
pydantic
poetry
ruamel.yaml
ruamel.yaml
typing_extensions
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ install_requires =
pydantic >=1.8.1
ruamel.yaml
poetry
typing-extensions
python_requires = >=3.6
packages = find:
setup_requires =
Expand Down
8 changes: 7 additions & 1 deletion tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,13 @@ def test_run_lock_with_locked_environment_files(
make_lock_files = MagicMock()
monkeypatch.setattr("conda_lock.conda_lock.make_lock_files", make_lock_files)
run_lock(DEFAULT_FILES, conda_exe=conda_exe, update=["pydantic"])
assert [p.resolve() for p in make_lock_files.call_args.kwargs["src_files"]] == [
if sys.version_info < (3, 8):
# backwards compat
src_files = make_lock_files.call_args_list[0][1]["src_files"]
else:
src_files = make_lock_files.call_args.kwargs["src_files"]

assert [p.resolve() for p in src_files] == [
pathlib.Path(update_environment.parent / "environment-preupdate.yml")
]

Expand Down

0 comments on commit 41c9c8c

Please sign in to comment.