Commit 395346d1 by Dimitri Merejkowsky Committed by Sébastien Eustace

Fix warnings with Python 3.7 (#489)

* Fix warnings about escape sequences

* Fix typo in CONTRIBUTING

* Enable Python3.7 in travis
parent 07e71abb
...@@ -22,6 +22,8 @@ jobs: ...@@ -22,6 +22,8 @@ jobs:
- python: "3.4" - python: "3.4"
- python: "3.5" - python: "3.5"
- python: "3.6" - python: "3.6"
- python: "3.7"
dist: xenial
- stage: linting - stage: linting
python: "3.6" python: "3.6"
......
...@@ -102,7 +102,7 @@ $ poetry run pytest tests/ ...@@ -102,7 +102,7 @@ $ poetry run pytest tests/
Poetry uses the [black](https://github.com/ambv/black) coding style and you must ensure that your Poetry uses the [black](https://github.com/ambv/black) coding style and you must ensure that your
code follows it. If not, the CI will fail and your Pull Request will not be merged. code follows it. If not, the CI will fail and your Pull Request will not be merged.
To make sure that you don't accidently commit code that does not follow the coding style, you can To make sure that you don't accidentally commit code that does not follow the coding style, you can
install a pre-commit hook that will check that everything is in order: install a pre-commit hook that will check that everything is in order:
```bash ```bash
...@@ -117,4 +117,3 @@ will not be merged. ...@@ -117,4 +117,3 @@ will not be merged.
* Fill in [the required template](https://github.com/sdispater/poetry/blob/master/.github/PULL_REQUEST_TEMPLATE.md) * Fill in [the required template](https://github.com/sdispater/poetry/blob/master/.github/PULL_REQUEST_TEMPLATE.md)
* Be sure that you pull request contains tests that cover the changed or added code. * Be sure that you pull request contains tests that cover the changed or added code.
* If you changes warrant a documentation change, the pull request must also update the documentation. * If you changes warrant a documentation change, the pull request must also update the documentation.
...@@ -153,7 +153,7 @@ class Application(BaseApplication): ...@@ -153,7 +153,7 @@ class Application(BaseApplication):
line[x : x + (width - 4)] for x in range(0, len(line), width - 4) line[x : x + (width - 4)] for x in range(0, len(line), width - 4)
]: ]:
line_length = ( line_length = (
len(re.sub("\[[^m]*m", "", formatter.format(splitline))) + 4 len(re.sub(r"\[[^m]*m", "", formatter.format(splitline))) + 4
) )
lines.append((splitline, line_length)) lines.append((splitline, line_length))
......
...@@ -102,7 +102,7 @@ To remove a repository (repo is a short alias for repositories): ...@@ -102,7 +102,7 @@ To remove a repository (repo is a short alias for repositories):
# show the value if no value is provided # show the value if no value is provided
if not self.argument("value") and not self.option("unset"): if not self.argument("value") and not self.option("unset"):
m = re.match("^repos?(?:itories)?(?:\.(.+))?", self.argument("key")) m = re.match(r"^repos?(?:itories)?(?:\.(.+))?", self.argument("key"))
if m: if m:
if not m.group(1): if not m.group(1):
value = {} value = {}
...@@ -144,7 +144,7 @@ To remove a repository (repo is a short alias for repositories): ...@@ -144,7 +144,7 @@ To remove a repository (repo is a short alias for repositories):
) )
# handle repositories # handle repositories
m = re.match("^repos?(?:itories)?(?:\.(.+))?", self.argument("key")) m = re.match(r"^repos?(?:itories)?(?:\.(.+))?", self.argument("key"))
if m: if m:
if not m.group(1): if not m.group(1):
raise ValueError("You cannot remove the [repositories] section") raise ValueError("You cannot remove the [repositories] section")
...@@ -173,7 +173,7 @@ To remove a repository (repo is a short alias for repositories): ...@@ -173,7 +173,7 @@ To remove a repository (repo is a short alias for repositories):
) )
# handle auth # handle auth
m = re.match("^(http-basic)\.(.+)", self.argument("key")) m = re.match(r"^(http-basic)\.(.+)", self.argument("key"))
if m: if m:
if self.option("unset"): if self.option("unset"):
if not self._auth_config.setting( if not self._auth_config.setting(
...@@ -278,7 +278,7 @@ To remove a repository (repo is a short alias for repositories): ...@@ -278,7 +278,7 @@ To remove a repository (repo is a short alias for repositories):
if k is None: if k is None:
k = "" k = ""
k += re.sub("^config\.", "", key + ".") k += re.sub(r"^config\.", "", key + ".")
if setting and len(setting) > 1: if setting and len(setting) > 1:
setting = ".".join(setting.split(".")[1:]) setting = ".".join(setting.split(".")[1:])
......
...@@ -15,7 +15,7 @@ from ..utils.module import Module ...@@ -15,7 +15,7 @@ from ..utils.module import Module
from ..utils.package_include import PackageInclude from ..utils.package_include import PackageInclude
AUTHOR_REGEX = re.compile("(?u)^(?P<name>[- .,\w\d'’\"()]+) <(?P<email>.+?)>$") AUTHOR_REGEX = re.compile(r"(?u)^(?P<name>[- .,\w\d'’\"()]+) <(?P<email>.+?)>$")
class Builder(object): class Builder(object):
......
...@@ -280,7 +280,7 @@ class SdistBuilder(Builder): ...@@ -280,7 +280,7 @@ class SdistBuilder(Builder):
): ):
main = [] main = []
extras = defaultdict(list) extras = defaultdict(list)
req_regex = re.compile("^(.+) \((.+)\)$") req_regex = re.compile(r"^(.+) \((.+)\)$")
for dependency in dependencies: for dependency in dependencies:
if dependency.is_optional(): if dependency.is_optional():
......
...@@ -179,8 +179,8 @@ class WheelBuilder(Builder): ...@@ -179,8 +179,8 @@ class WheelBuilder(Builder):
@property @property
def wheel_filename(self): # type: () -> str def wheel_filename(self): # type: () -> str
return "{}-{}-{}.whl".format( return "{}-{}-{}.whl".format(
re.sub("[^\w\d.]+", "_", self._package.pretty_name, flags=re.UNICODE), re.sub(r"[^\w\d.]+", "_", self._package.pretty_name, flags=re.UNICODE),
re.sub("[^\w\d.]+", "_", self._meta.version, flags=re.UNICODE), re.sub(r"[^\w\d.]+", "_", self._meta.version, flags=re.UNICODE),
self.tag, self.tag,
) )
...@@ -190,8 +190,8 @@ class WheelBuilder(Builder): ...@@ -190,8 +190,8 @@ class WheelBuilder(Builder):
) )
def dist_info_name(self, distribution, version): # type: (...) -> str def dist_info_name(self, distribution, version): # type: (...) -> str
escaped_name = re.sub("[^\w\d.]+", "_", distribution, flags=re.UNICODE) escaped_name = re.sub(r"[^\w\d.]+", "_", distribution, flags=re.UNICODE)
escaped_version = re.sub("[^\w\d.]+", "_", version, flags=re.UNICODE) escaped_version = re.sub(r"[^\w\d.]+", "_", version, flags=re.UNICODE)
return "{}-{}.dist-info".format(escaped_name, escaped_version) return "{}-{}.dist-info".format(escaped_name, escaped_version)
......
...@@ -60,9 +60,9 @@ class Uploader: ...@@ -60,9 +60,9 @@ class Uploader:
dist.glob( dist.glob(
"{}-{}-*.whl".format( "{}-{}-*.whl".format(
re.sub( re.sub(
"[^\w\d.]+", "_", self._package.pretty_name, flags=re.UNICODE r"[^\w\d.]+", "_", self._package.pretty_name, flags=re.UNICODE
), ),
re.sub("[^\w\d.]+", "_", version, flags=re.UNICODE), re.sub(r"[^\w\d.]+", "_", version, flags=re.UNICODE),
) )
) )
) )
......
...@@ -62,7 +62,7 @@ def dependency_from_pep_508(name): ...@@ -62,7 +62,7 @@ def dependency_from_pep_508(name):
link = Link(path_to_url(os.path.normpath(os.path.abspath(link.path)))) link = Link(path_to_url(os.path.normpath(os.path.abspath(link.path))))
# wheel file # wheel file
if link.is_wheel: if link.is_wheel:
m = re.match("^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))", link.filename) m = re.match(r"^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))", link.filename)
if not m: if not m:
raise ValueError("Invalid wheel name: {}".format(link.filename)) raise ValueError("Invalid wheel name: {}".format(link.filename))
......
...@@ -84,7 +84,7 @@ class GenericConstraint(BaseConstraint): ...@@ -84,7 +84,7 @@ class GenericConstraint(BaseConstraint):
""" """
pretty_constraint = constraints pretty_constraint = constraints
or_constraints = re.split("\s*\|\|?\s*", constraints.strip()) or_constraints = re.split(r"\s*\|\|?\s*", constraints.strip())
or_groups = [] or_groups = []
for constraints in or_constraints: for constraints in or_constraints:
and_constraints = re.split( and_constraints = re.split(
...@@ -116,12 +116,12 @@ class GenericConstraint(BaseConstraint): ...@@ -116,12 +116,12 @@ class GenericConstraint(BaseConstraint):
@classmethod @classmethod
def _parse_constraint(cls, constraint): def _parse_constraint(cls, constraint):
m = re.match("(?i)^v?[xX*](\.[xX*])*$", constraint) m = re.match(r"(?i)^v?[xX*](\.[xX*])*$", constraint)
if m: if m:
return (EmptyConstraint(),) return (EmptyConstraint(),)
# Basic Comparators # Basic Comparators
m = re.match("^(!=|==?)?\s*(.*)", constraint) m = re.match(r"^(!=|==?)?\s*(.*)", constraint)
if m: if m:
return (GenericConstraint(m.group(1) or "=", m.group(2)),) return (GenericConstraint(m.group(1) or "=", m.group(2)),)
......
...@@ -19,7 +19,7 @@ from .directory_dependency import DirectoryDependency ...@@ -19,7 +19,7 @@ from .directory_dependency import DirectoryDependency
from .file_dependency import FileDependency from .file_dependency import FileDependency
from .vcs_dependency import VCSDependency from .vcs_dependency import VCSDependency
AUTHOR_REGEX = re.compile("(?u)^(?P<name>[- .,\w\d'’\"()]+)(?: <(?P<email>.+?)>)?$") AUTHOR_REGEX = re.compile(r"(?u)^(?P<name>[- .,\w\d'’\"()]+)(?: <(?P<email>.+?)>)?$")
class Package(object): class Package(object):
......
...@@ -508,8 +508,8 @@ class Provider: ...@@ -508,8 +508,8 @@ class Provider:
if message.startswith("fact:"): if message.startswith("fact:"):
if "depends on" in message: if "depends on" in message:
m = re.match("fact: (.+?) depends on (.+?) \((.+?)\)", message) m = re.match(r"fact: (.+?) depends on (.+?) \((.+?)\)", message)
m2 = re.match("(.+?) \((.+?)\)", m.group(1)) m2 = re.match(r"(.+?) \((.+?)\)", m.group(1))
if m2: if m2:
name = m2.group(1) name = m2.group(1)
version = " (<comment>{}</comment>)".format(m2.group(2)) version = " (<comment>{}</comment>)".format(m2.group(2))
...@@ -531,19 +531,19 @@ class Provider: ...@@ -531,19 +531,19 @@ class Provider:
) )
else: else:
message = re.sub( message = re.sub(
"(?<=: )(.+?) \((.+?)\)", r"(?<=: )(.+?) \((.+?)\)",
"<info>\\1</info> (<comment>\\2</comment>)", "<info>\\1</info> (<comment>\\2</comment>)",
message, message,
) )
message = "<fg=blue>fact</>: {}".format(message.split("fact: ")[1]) message = "<fg=blue>fact</>: {}".format(message.split("fact: ")[1])
elif message.startswith("selecting "): elif message.startswith("selecting "):
message = re.sub( message = re.sub(
"selecting (.+?) \((.+?)\)", r"selecting (.+?) \((.+?)\)",
"<fg=blue>selecting</> <info>\\1</info> (<comment>\\2</comment>)", "<fg=blue>selecting</> <info>\\1</info> (<comment>\\2</comment>)",
message, message,
) )
elif message.startswith("derived:"): elif message.startswith("derived:"):
m = re.match("derived: (.+?) \((.+?)\)$", message) m = re.match(r"derived: (.+?) \((.+?)\)$", message)
if m: if m:
message = "<fg=blue>derived</>: <info>{}</info> (<comment>{}</comment>)".format( message = "<fg=blue>derived</>: <info>{}</info> (<comment>{}</comment>)".format(
m.group(1), m.group(2) m.group(1), m.group(2)
...@@ -553,9 +553,9 @@ class Provider: ...@@ -553,9 +553,9 @@ class Provider:
message.split("derived: ")[1] message.split("derived: ")[1]
) )
elif message.startswith("conflict:"): elif message.startswith("conflict:"):
m = re.match("conflict: (.+?) depends on (.+?) \((.+?)\)", message) m = re.match(r"conflict: (.+?) depends on (.+?) \((.+?)\)", message)
if m: if m:
m2 = re.match("(.+?) \((.+?)\)", m.group(1)) m2 = re.match(r"(.+?) \((.+?)\)", m.group(1))
if m2: if m2:
name = m2.group(1) name = m2.group(1)
version = " (<comment>{}</comment>)".format(m2.group(2)) version = " (<comment>{}</comment>)".format(m2.group(2))
......
...@@ -46,7 +46,7 @@ from .pypi_repository import PyPiRepository ...@@ -46,7 +46,7 @@ from .pypi_repository import PyPiRepository
class Page: class Page:
VERSION_REGEX = re.compile("(?i)([a-z0-9_\-.]+?)-(?=\d)([a-z0-9_.!+-]+)") VERSION_REGEX = re.compile(r"(?i)([a-z0-9_\-.]+?)-(?=\d)([a-z0-9_.!+-]+)")
def __init__(self, url, content, headers): def __init__(self, url, content, headers):
if not url.endswith("/"): if not url.endswith("/"):
......
...@@ -290,7 +290,7 @@ class PyPiRepository(Repository): ...@@ -290,7 +290,7 @@ class PyPiRepository(Repository):
# If bdist_wheel, check if it's universal # If bdist_wheel, check if it's universal
filename = url["filename"] filename = url["filename"]
if not re.search("-py2\.py3-none-any.whl", filename): if not re.search(r"-py2\.py3-none-any.whl", filename):
continue continue
urls[dist_type] = url["url"] urls[dist_type] = url["url"]
......
...@@ -16,7 +16,7 @@ def parse_constraint(constraints): # type: (str) -> VersionConstraint ...@@ -16,7 +16,7 @@ def parse_constraint(constraints): # type: (str) -> VersionConstraint
if constraints == "*": if constraints == "*":
return VersionRange() return VersionRange()
or_constraints = re.split("\s*\|\|?\s*", constraints.strip()) or_constraints = re.split(r"\s*\|\|?\s*", constraints.strip())
or_groups = [] or_groups = []
for constraints in or_constraints: for constraints in or_constraints:
and_constraints = re.split( and_constraints = re.split(
...@@ -46,7 +46,7 @@ def parse_constraint(constraints): # type: (str) -> VersionConstraint ...@@ -46,7 +46,7 @@ def parse_constraint(constraints): # type: (str) -> VersionConstraint
def parse_single_constraint(constraint): # type: (str) -> VersionConstraint def parse_single_constraint(constraint): # type: (str) -> VersionConstraint
m = re.match("(?i)^v?[xX*](\.[xX*])*$", constraint) m = re.match(r"(?i)^v?[xX*](\.[xX*])*$", constraint)
if m: if m:
return VersionRange() return VersionRange()
......
...@@ -2,20 +2,20 @@ import re ...@@ -2,20 +2,20 @@ import re
MODIFIERS = ( MODIFIERS = (
"[._-]?" "[._-]?"
"((?!post)(?:beta|b|c|pre|RC|alpha|a|patch|pl|p|dev)(?:(?:[.-]?\d+)*)?)?" r"((?!post)(?:beta|b|c|pre|RC|alpha|a|patch|pl|p|dev)(?:(?:[.-]?\d+)*)?)?"
"([+-]?([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?" r"([+-]?([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?"
) )
_COMPLETE_VERSION = "v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?{}(?:\+[^\s]+)?".format( _COMPLETE_VERSION = r"v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?{}(?:\+[^\s]+)?".format(
MODIFIERS MODIFIERS
) )
COMPLETE_VERSION = re.compile("(?i)" + _COMPLETE_VERSION) COMPLETE_VERSION = re.compile("(?i)" + _COMPLETE_VERSION)
CARET_CONSTRAINT = re.compile("(?i)^\^({})$".format(_COMPLETE_VERSION)) CARET_CONSTRAINT = re.compile(r"(?i)^\^({})$".format(_COMPLETE_VERSION))
TILDE_CONSTRAINT = re.compile("(?i)^~(?!=)({})$".format(_COMPLETE_VERSION)) TILDE_CONSTRAINT = re.compile("(?i)^~(?!=)({})$".format(_COMPLETE_VERSION))
TILDE_PEP440_CONSTRAINT = re.compile("(?i)^~=({})$".format(_COMPLETE_VERSION)) TILDE_PEP440_CONSTRAINT = re.compile("(?i)^~=({})$".format(_COMPLETE_VERSION))
X_CONSTRAINT = re.compile("^(!=|==)?\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.[xX*])+$") X_CONSTRAINT = re.compile(r"^(!=|==)?\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.[xX*])+$")
BASIC_CONSTRAINT = re.compile( BASIC_CONSTRAINT = re.compile(
"(?i)^(<>|!=|>=?|<=?|==?)?\s*({}|dev)".format(_COMPLETE_VERSION) r"(?i)^(<>|!=|>=?|<=?|==?)?\s*({}|dev)".format(_COMPLETE_VERSION)
) )
...@@ -280,7 +280,7 @@ class Version(VersionRange): ...@@ -280,7 +280,7 @@ class Version(VersionRange):
if not pre: if not pre:
return return
m = re.match("(?i)^(a|alpha|b|beta|c|pre|rc|dev)[-.]?(\d+)?$", pre) m = re.match(r"(?i)^(a|alpha|b|beta|c|pre|rc|dev)[-.]?(\d+)?$", pre)
if not m: if not m:
return return
......
...@@ -64,7 +64,7 @@ def user_cache_dir(appname): ...@@ -64,7 +64,7 @@ def user_cache_dir(appname):
def user_data_dir(appname, roaming=False): def user_data_dir(appname, roaming=False):
""" r"""
Return full path to the user-specific data dir for this application. Return full path to the user-specific data dir for this application.
"appname" is the name of application. "appname" is the name of application.
...@@ -137,7 +137,7 @@ def user_config_dir(appname, roaming=True): ...@@ -137,7 +137,7 @@ def user_config_dir(appname, roaming=True):
# for the discussion regarding site_config_dirs locations # for the discussion regarding site_config_dirs locations
# see <https://github.com/pypa/pip/issues/1733> # see <https://github.com/pypa/pip/issues/1733>
def site_config_dirs(appname): def site_config_dirs(appname):
"""Return a list of potential user-shared config dirs for this application. r"""Return a list of potential user-shared config dirs for this application.
"appname" is the name of application. "appname" is the name of application.
......
...@@ -12,7 +12,7 @@ _Version = namedtuple("_Version", ["epoch", "release", "dev", "pre", "post", "lo ...@@ -12,7 +12,7 @@ _Version = namedtuple("_Version", ["epoch", "release", "dev", "pre", "post", "lo
VERSION_PATTERN = re.compile( VERSION_PATTERN = re.compile(
""" r"""
^ ^
v? v?
(?: (?:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment