mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
vendor stringcase
It's a tiny library that has not been updated in years, and it was leading to a warning on startup: DeprecationWarning: invalid escape sequence \W return re.sub("\W+", "", string)
This commit is contained in:
parent
a1b2bfb355
commit
048a9a2b60
12 changed files with 288 additions and 14 deletions
|
@ -24,7 +24,7 @@ _py_srcs = glob(
|
||||||
exclude = [
|
exclude = [
|
||||||
"hooks_gen.py",
|
"hooks_gen.py",
|
||||||
],
|
],
|
||||||
)
|
) + ["//pylib/anki/_vendor"]
|
||||||
|
|
||||||
py_library(
|
py_library(
|
||||||
name = "anki",
|
name = "anki",
|
||||||
|
@ -49,7 +49,7 @@ py_library(
|
||||||
requirement("flask"),
|
requirement("flask"),
|
||||||
requirement("waitress"),
|
requirement("waitress"),
|
||||||
requirement("markdown"),
|
requirement("markdown"),
|
||||||
requirement("stringcase"),
|
"//pylib/anki/_vendor:stringcase",
|
||||||
] + orjson_if_available(),
|
] + orjson_if_available(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ py_binary(
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
requirement("black"),
|
requirement("black"),
|
||||||
requirement("stringcase"),
|
"//pylib/anki/_vendor:stringcase",
|
||||||
requirement("protobuf"),
|
requirement("protobuf"),
|
||||||
"//pylib/anki:proto",
|
"//pylib/anki:proto",
|
||||||
],
|
],
|
||||||
|
@ -30,7 +30,7 @@ py_binary(
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
requirement("black"),
|
requirement("black"),
|
||||||
requirement("stringcase"),
|
"//pylib/anki/_vendor:stringcase",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import pathlib
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Any, Callable, Union, no_type_check
|
from typing import Any, Callable, Union, no_type_check
|
||||||
|
|
||||||
import stringcase
|
from anki._vendor import stringcase
|
||||||
|
|
||||||
VariableTarget = tuple[Any, str]
|
VariableTarget = tuple[Any, str]
|
||||||
DeprecatedAliasTarget = Union[Callable, VariableTarget]
|
DeprecatedAliasTarget = Union[Callable, VariableTarget]
|
||||||
|
|
18
pylib/anki/_vendor/BUILD.bazel
Normal file
18
pylib/anki/_vendor/BUILD.bazel
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# export stringcase as a separate python library as well, as our build tools need it
|
||||||
|
py_library(
|
||||||
|
name = "stringcase",
|
||||||
|
srcs = ["stringcase.py"],
|
||||||
|
imports = [
|
||||||
|
".",
|
||||||
|
],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "_vendor",
|
||||||
|
srcs = [
|
||||||
|
"__init__.py",
|
||||||
|
"stringcase.py",
|
||||||
|
],
|
||||||
|
visibility = ["//pylib:__subpackages__"],
|
||||||
|
)
|
0
pylib/anki/_vendor/__init__.py
Normal file
0
pylib/anki/_vendor/__init__.py
Normal file
257
pylib/anki/_vendor/stringcase.py
Normal file
257
pylib/anki/_vendor/stringcase.py
Normal file
|
@ -0,0 +1,257 @@
|
||||||
|
# stringcase 1.2.0 with python warning fix applied
|
||||||
|
# MIT: https://github.com/okunishinishi/python-stringcase
|
||||||
|
|
||||||
|
# type: ignore
|
||||||
|
|
||||||
|
"""
|
||||||
|
String convert functions
|
||||||
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def camelcase(string):
|
||||||
|
"""Convert string into camel case.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Camel case string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
string = re.sub(r"\w[\s\W]+\w", "", str(string))
|
||||||
|
if not string:
|
||||||
|
return string
|
||||||
|
return lowercase(string[0]) + re.sub(
|
||||||
|
r"[\-_\.\s]([a-z])", lambda matched: uppercase(matched.group(1)), string[1:]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def capitalcase(string):
|
||||||
|
"""Convert string into capital case.
|
||||||
|
First letters will be uppercase.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Capital case string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
string = str(string)
|
||||||
|
if not string:
|
||||||
|
return string
|
||||||
|
return uppercase(string[0]) + string[1:]
|
||||||
|
|
||||||
|
|
||||||
|
def constcase(string):
|
||||||
|
"""Convert string into upper snake case.
|
||||||
|
Join punctuation with underscore and convert letters into uppercase.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Const cased string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
return uppercase(snakecase(string))
|
||||||
|
|
||||||
|
|
||||||
|
def lowercase(string):
|
||||||
|
"""Convert string into lower case.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Lowercase case string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
return str(string).lower()
|
||||||
|
|
||||||
|
|
||||||
|
def pascalcase(string):
|
||||||
|
"""Convert string into pascal case.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Pascal case string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
return capitalcase(camelcase(string))
|
||||||
|
|
||||||
|
|
||||||
|
def pathcase(string):
|
||||||
|
"""Convert string into path case.
|
||||||
|
Join punctuation with slash.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Path cased string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
string = snakecase(string)
|
||||||
|
if not string:
|
||||||
|
return string
|
||||||
|
return re.sub(r"_", "/", string)
|
||||||
|
|
||||||
|
|
||||||
|
def backslashcase(string):
|
||||||
|
"""Convert string into spinal case.
|
||||||
|
Join punctuation with backslash.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Spinal cased string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
str1 = re.sub(r"_", r"\\", snakecase(string))
|
||||||
|
|
||||||
|
return str1
|
||||||
|
# return re.sub(r"\\n", "", str1)) # TODO: make regex fot \t ...
|
||||||
|
|
||||||
|
|
||||||
|
def sentencecase(string):
|
||||||
|
"""Convert string into sentence case.
|
||||||
|
First letter capped and each punctuations are joined with space.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Sentence cased string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
joiner = " "
|
||||||
|
string = re.sub(r"[\-_\.\s]", joiner, str(string))
|
||||||
|
if not string:
|
||||||
|
return string
|
||||||
|
return capitalcase(
|
||||||
|
trimcase(
|
||||||
|
re.sub(
|
||||||
|
r"[A-Z]", lambda matched: joiner + lowercase(matched.group(0)), string
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def snakecase(string):
|
||||||
|
"""Convert string into snake case.
|
||||||
|
Join punctuation with underscore
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Snake cased string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
string = re.sub(r"[\-\.\s]", "_", str(string))
|
||||||
|
if not string:
|
||||||
|
return string
|
||||||
|
return lowercase(string[0]) + re.sub(
|
||||||
|
r"[A-Z]", lambda matched: "_" + lowercase(matched.group(0)), string[1:]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def spinalcase(string):
|
||||||
|
"""Convert string into spinal case.
|
||||||
|
Join punctuation with hyphen.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Spinal cased string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
return re.sub(r"_", "-", snakecase(string))
|
||||||
|
|
||||||
|
|
||||||
|
def dotcase(string):
|
||||||
|
|
||||||
|
"""Convert string into dot case.
|
||||||
|
Join punctuation with dot.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Dot cased string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
return re.sub(r"_", ".", snakecase(string))
|
||||||
|
|
||||||
|
|
||||||
|
def titlecase(string):
|
||||||
|
"""Convert string into sentence case.
|
||||||
|
First letter capped while each punctuations is capitalsed
|
||||||
|
and joined with space.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Title cased string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
return " ".join([capitalcase(word) for word in snakecase(string).split("_")])
|
||||||
|
|
||||||
|
|
||||||
|
def trimcase(string):
|
||||||
|
"""Convert string into trimmed string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Trimmed case string
|
||||||
|
"""
|
||||||
|
|
||||||
|
return str(string).strip()
|
||||||
|
|
||||||
|
|
||||||
|
def uppercase(string):
|
||||||
|
"""Convert string into upper case.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: Uppercase case string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
return str(string).upper()
|
||||||
|
|
||||||
|
|
||||||
|
def alphanumcase(string):
|
||||||
|
"""Cuts all non-alphanumeric symbols,
|
||||||
|
i.e. cuts all expect except 0-9, a-z and A-Z.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
string: String to convert.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: String with cutted non-alphanumeric symbols.
|
||||||
|
|
||||||
|
"""
|
||||||
|
# return filter(str.isalnum, str(string))
|
||||||
|
return re.sub(r"\W+", "", string)
|
|
@ -42,7 +42,7 @@ py_binary(
|
||||||
visibility = ["//pylib:__subpackages__"],
|
visibility = ["//pylib:__subpackages__"],
|
||||||
deps = [
|
deps = [
|
||||||
requirement("black"),
|
requirement("black"),
|
||||||
requirement("stringcase"),
|
"//pylib/anki/_vendor:stringcase",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ py_binary(
|
||||||
],
|
],
|
||||||
tags = ["manual"],
|
tags = ["manual"],
|
||||||
deps = [
|
deps = [
|
||||||
requirement("stringcase"),
|
"//pylib/anki/_vendor:stringcase",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ pytest
|
||||||
requests[socks]
|
requests[socks]
|
||||||
send2trash
|
send2trash
|
||||||
snakeviz
|
snakeviz
|
||||||
stringcase
|
|
||||||
waitress>=2.0.0
|
waitress>=2.0.0
|
||||||
fluent.syntax
|
fluent.syntax
|
||||||
types-decorator
|
types-decorator
|
||||||
|
|
|
@ -129,8 +129,6 @@ snakeviz==2.1.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
soupsieve==2.2.1
|
soupsieve==2.2.1
|
||||||
# via beautifulsoup4
|
# via beautifulsoup4
|
||||||
stringcase==1.2.0
|
|
||||||
# via -r requirements.in
|
|
||||||
toml==0.10.2
|
toml==0.10.2
|
||||||
# via
|
# via
|
||||||
# mypy
|
# mypy
|
||||||
|
|
|
@ -11,7 +11,7 @@ py_binary(
|
||||||
deps = [
|
deps = [
|
||||||
"//pylib/tools:hookslib",
|
"//pylib/tools:hookslib",
|
||||||
requirement("black"),
|
requirement("black"),
|
||||||
requirement("stringcase"),
|
"//pylib/anki/_vendor:stringcase",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,13 @@ import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
nonstandard_header = {
|
nonstandard_header = {
|
||||||
"python/pyqt5/install_pyqt5.py",
|
"pylib/anki/_vendor/stringcase.py",
|
||||||
"python/pyqt6/install_pyqt6.py",
|
|
||||||
"pylib/anki/importing/pauker.py",
|
"pylib/anki/importing/pauker.py",
|
||||||
"pylib/anki/importing/supermemo_xml.py",
|
"pylib/anki/importing/supermemo_xml.py",
|
||||||
"pylib/anki/statsbg.py",
|
"pylib/anki/statsbg.py",
|
||||||
"pylib/tools/protoc-gen-mypy.py",
|
"pylib/tools/protoc-gen-mypy.py",
|
||||||
|
"python/pyqt5/install_pyqt5.py",
|
||||||
|
"python/pyqt6/install_pyqt6.py",
|
||||||
"qt/aqt/mpv.py",
|
"qt/aqt/mpv.py",
|
||||||
"qt/aqt/winpaths.py",
|
"qt/aqt/winpaths.py",
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,10 @@ py_binary(
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
requirement("black"),
|
requirement("black"),
|
||||||
requirement("stringcase"),
|
"//pylib/anki/_vendor:stringcase",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
_i18n_generated = [
|
_i18n_generated = [
|
||||||
"ftl.ts",
|
"ftl.ts",
|
||||||
"i18n/modules.ts",
|
"i18n/modules.ts",
|
||||||
|
|
Loading…
Reference in a new issue