Skip to content

Commit

Permalink
Remove python 2.7/3.5 compatibility code (#3405)
Browse files Browse the repository at this point in the history
* Remove python 2.7/3.5 compatibility code

This change removes code, dependencies and tests related to python 2.7
and 3.5 compatibility. The minimum supported runtime python version
for poetry is now 3.6.

* tests: mitigate httpretty urllib incompatibility

Relates-to: #3404
  • Loading branch information
abn authored Nov 24, 2020
1 parent 639d5e0 commit bf30ca6
Show file tree
Hide file tree
Showing 76 changed files with 343 additions and 1,151 deletions.
570 changes: 98 additions & 472 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import re

from copy import deepcopy
from pathlib import Path
from typing import Any
from typing import Callable
from typing import Dict
from typing import Optional

from poetry.locations import CACHE_DIR
from poetry.utils._compat import Path
from poetry.utils._compat import basestring

from .config_source import ConfigSource
from .dict_config_source import DictConfigSource
Expand Down Expand Up @@ -131,7 +130,7 @@ def get(self, setting_name, default=None): # type: (str, Any) -> Any
return self.process(value)

def process(self, value): # type: (Any) -> Any
if not isinstance(value, basestring):
if not isinstance(value, str):
return value

return re.sub(r"{(.+?)}", lambda m: self.get(m.group(1)), value)
Expand Down
3 changes: 2 additions & 1 deletion poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ def __init__(self):

@property
def poetry(self):
from pathlib import Path

from poetry.factory import Factory
from poetry.utils._compat import Path

if self._poetry is not None:
return self._poetry
Expand Down
3 changes: 2 additions & 1 deletion poetry/console/commands/check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

from poetry.core.pyproject.toml import PyProjectTOML
from poetry.factory import Factory
from poetry.utils._compat import Path

from .command import Command

Expand Down
13 changes: 6 additions & 7 deletions poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ class ConfigCommand(Command):

@property
def unique_config_values(self):
from pathlib import Path

from poetry.config.config import boolean_normalizer
from poetry.config.config import boolean_validator
from poetry.locations import CACHE_DIR
from poetry.utils._compat import Path

unique_config_values = {
"cache-dir": (
Expand Down Expand Up @@ -75,10 +76,10 @@ def unique_config_values(self):
return unique_config_values

def handle(self):
from pathlib import Path

from poetry.config.file_config_source import FileConfigSource
from poetry.locations import CONFIG_DIR
from poetry.utils._compat import Path
from poetry.utils._compat import basestring

config = Factory.create_config(self.io)
config_file = TOMLFile(Path(CONFIG_DIR) / "config.toml")
Expand Down Expand Up @@ -134,7 +135,7 @@ def handle(self):

value = config.get(setting_key)

if not isinstance(value, basestring):
if not isinstance(value, str):
value = json.dumps(value)

self.line(value)
Expand Down Expand Up @@ -267,8 +268,6 @@ def _handle_single_value(self, source, key, callbacks, values):
return 0

def _list_configuration(self, config, raw, k=""):
from poetry.utils._compat import basestring

orig_k = k
for key, value in sorted(config.items()):
if k + key in self.LIST_PROHIBITED_SETTINGS:
Expand All @@ -293,7 +292,7 @@ def _list_configuration(self, config, raw, k=""):
message = "<c1>{}</c1> = <c2>{}</c2>".format(
k + key, json.dumps(raw_val)
)
elif isinstance(raw_val, basestring) and raw_val != value:
elif isinstance(raw_val, str) and raw_val != value:
message = "<c1>{}</c1> = <c2>{}</c2> # {}".format(
k + key, json.dumps(raw_val), value
)
Expand Down
20 changes: 9 additions & 11 deletions poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import os
import re
import sys
import urllib.parse

from pathlib import Path
from typing import Dict
from typing import List
from typing import Tuple
Expand All @@ -15,9 +17,6 @@

from poetry.core.pyproject import PyProjectException
from poetry.core.pyproject.toml import PyProjectTOML
from poetry.utils._compat import OrderedDict
from poetry.utils._compat import Path
from poetry.utils._compat import urlparse

from .command import Command
from .env_command import EnvCommand
Expand Down Expand Up @@ -63,9 +62,10 @@ def __init__(self):
self._pool = None

def handle(self):
from pathlib import Path

from poetry.core.vcs.git import GitConfig
from poetry.layouts import layout
from poetry.utils._compat import Path
from poetry.utils.env import SystemEnv

pyproject = PyProjectTOML(Path.cwd() / "pyproject.toml")
Expand Down Expand Up @@ -390,7 +390,7 @@ def _parse_requirements(
extras = [e.strip() for e in extras_m.group(1).split(",")]
requirement, _ = requirement.split("[")

url_parsed = urlparse.urlparse(requirement)
url_parsed = urllib.parse.urlparse(requirement)
if url_parsed.scheme and url_parsed.netloc:
# Url
if url_parsed.scheme in ["git+https", "git+ssh"]:
Expand All @@ -400,7 +400,7 @@ def _parse_requirements(
parsed = ParsedUrl.parse(requirement)
url = Git.normalize_url(requirement)

pair = OrderedDict([("name", parsed.name), ("git", url.url)])
pair = dict([("name", parsed.name), ("git", url.url)])
if parsed.rev:
pair["rev"] = url.revision

Expand All @@ -417,9 +417,7 @@ def _parse_requirements(
elif url_parsed.scheme in ["http", "https"]:
package = Provider.get_package_from_url(requirement)

pair = OrderedDict(
[("name", package.name), ("url", package.source_url)]
)
pair = dict([("name", package.name), ("url", package.source_url)])
if extras:
pair["extras"] = extras

Expand All @@ -435,7 +433,7 @@ def _parse_requirements(
package = Provider.get_package_from_directory(path)

result.append(
OrderedDict(
dict(
[
("name", package.name),
("path", path.relative_to(cwd).as_posix()),
Expand All @@ -451,7 +449,7 @@ def _parse_requirements(
)
pair = pair.strip()

require = OrderedDict()
require = dict()
if " " in pair:
name, version = pair.split(" ", 2)
extras_m = re.search(r"\[([\w\d,-_]+)\]$", name)
Expand Down
3 changes: 2 additions & 1 deletion poetry/console/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ class NewCommand(Command):
]

def handle(self):
from pathlib import Path

from poetry.core.semver import parse_constraint
from poetry.core.vcs.git import GitConfig
from poetry.layouts import layout
from poetry.utils._compat import Path
from poetry.utils.env import SystemEnv

if self.option("src"):
Expand Down
4 changes: 2 additions & 2 deletions poetry/console/commands/publish.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cleo import option
from pathlib import Path

from poetry.utils._compat import Path
from cleo import option

from .command import Command

Expand Down
4 changes: 2 additions & 2 deletions poetry/console/commands/self/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SelfUpdateCommand(Command):

@property
def home(self):
from poetry.utils._compat import Path
from pathlib import Path

return Path(os.environ.get("POETRY_HOME", "~/.poetry")).expanduser()

Expand Down Expand Up @@ -239,7 +239,7 @@ def process(self, *args):
return subprocess.check_output(list(args), stderr=subprocess.STDOUT)

def _check_recommended_installation(self):
from poetry.utils._compat import Path
from pathlib import Path

current = Path(__file__)
try:
Expand Down
13 changes: 4 additions & 9 deletions poetry/console/config/application_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from poetry.console.commands.installer_command import InstallerCommand
from poetry.console.logging.io_formatter import IOFormatter
from poetry.console.logging.io_handler import IOHandler
from poetry.utils._compat import PY36
from poetry.mixology.solutions.providers import PythonRequirementSolutionProvider


class ApplicationConfig(BaseApplicationConfig):
Expand All @@ -55,14 +55,9 @@ def configure(self):
self.add_event_listener(PRE_HANDLE, self.set_env)
self.add_event_listener(PRE_HANDLE, self.set_installer)

if PY36:
from poetry.mixology.solutions.providers import (
PythonRequirementSolutionProvider,
)

self._solution_provider_repository.register_solution_providers(
[PythonRequirementSolutionProvider]
)
self._solution_provider_repository.register_solution_providers(
[PythonRequirementSolutionProvider]
)

def register_command_loggers(
self, event, event_name, _
Expand Down
2 changes: 1 addition & 1 deletion poetry/factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from pathlib import Path
from typing import Dict
from typing import Optional

Expand All @@ -16,7 +17,6 @@
from .packages.locker import Locker
from .poetry import Poetry
from .repositories.pypi_repository import PyPiRepository
from .utils._compat import Path


class Factory(BaseFactory):
Expand Down
14 changes: 5 additions & 9 deletions poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tarfile
import zipfile

from pathlib import Path
from typing import Dict
from typing import Iterator
from typing import List
Expand All @@ -17,8 +18,6 @@
from poetry.core.packages import ProjectPackage
from poetry.core.packages import dependency_from_pep_508
from poetry.core.pyproject.toml import PyProjectTOML
from poetry.core.utils._compat import PY35
from poetry.core.utils._compat import Path
from poetry.core.utils.helpers import parse_requires
from poetry.core.utils.helpers import temporary_directory
from poetry.core.version.markers import InvalidMarker
Expand Down Expand Up @@ -364,13 +363,10 @@ def _find_dist_info(path): # type: (Path) -> Iterator[Path]
:param path: Path to search.
"""
pattern = "**/*.*-info"
if PY35:
# Sometimes pathlib will fail on recursive symbolic links, so we need to workaround it
# and use the glob module instead. Note that this does not happen with pathlib2
# so it's safe to use it for Python < 3.4.
directories = glob.iglob(path.joinpath(pattern).as_posix(), recursive=True)
else:
directories = path.glob(pattern)
# Sometimes pathlib will fail on recursive symbolic links, so we need to workaround it
# and use the glob module instead. Note that this does not happen with pathlib2
# so it's safe to use it for Python < 3.4.
directories = glob.iglob(path.joinpath(pattern).as_posix(), recursive=True)

for d in directories:
yield Path(d)
Expand Down
8 changes: 4 additions & 4 deletions poetry/installation/authenticator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import time
import urllib.parse

from typing import TYPE_CHECKING

Expand All @@ -8,7 +9,6 @@
import requests.exceptions

from poetry.exceptions import PoetryException
from poetry.utils._compat import urlparse
from poetry.utils.password_manager import PasswordManager


Expand Down Expand Up @@ -107,7 +107,7 @@ def request(
def get_credentials_for_url(
self, url
): # type: (str) -> Tuple[Optional[str], Optional[str]]
parsed_url = urlparse.urlsplit(url)
parsed_url = urllib.parse.urlsplit(url)

netloc = parsed_url.netloc

Expand All @@ -130,7 +130,7 @@ def get_credentials_for_url(
credentials = auth, None

credentials = tuple(
None if x is None else urlparse.unquote(x) for x in credentials
None if x is None else urllib.parse.unquote(x) for x in credentials
)

if credentials[0] is not None or credentials[1] is not None:
Expand All @@ -156,7 +156,7 @@ def _get_credentials_for_netloc_from_config(
if not url:
continue

parsed_url = urlparse.urlsplit(url)
parsed_url = urllib.parse.urlsplit(url)

if netloc == parsed_url.netloc:
auth = self._password_manager.get_http_auth(repository_name)
Expand Down
2 changes: 1 addition & 1 deletion poetry/installation/chef.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import hashlib
import json

from pathlib import Path
from typing import TYPE_CHECKING

from poetry.core.packages.utils.link import Link
from poetry.utils._compat import Path

from .chooser import InvalidWheelName
from .chooser import Wheel
Expand Down
Loading

0 comments on commit bf30ca6

Please sign in to comment.