Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor stringcase library #1727

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frictionless/helpers/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, TypeVar, Union
from urllib.parse import parse_qs, urlparse

import stringcase # type: ignore
from ..vendors import stringcase

# General

Expand Down
13 changes: 10 additions & 3 deletions frictionless/metadata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
Union,
)

import stringcase # type: ignore
from typing_extensions import Self

from .. import helpers
from ..exception import FrictionlessException
from ..platform import platform
from ..vendors import stringcase

if TYPE_CHECKING:
from .. import types
Expand Down Expand Up @@ -136,7 +136,10 @@ def set_not_defined(self, name: str, value: Any, *, distinct: bool = False) -> N

@classmethod
def validate_descriptor(
cls, descriptor: Union[types.IDescriptor, str], *, basepath: Optional[str] = None
cls,
descriptor: Union[types.IDescriptor, str],
*,
basepath: Optional[str] = None,
) -> Report:
errors = []
timer = helpers.Timer()
Expand Down Expand Up @@ -391,7 +394,11 @@ def metadata_validate(

@classmethod
def metadata_import(
cls, descriptor: types.IDescriptor, *, with_basepath: bool = False, **options: Any
cls,
descriptor: types.IDescriptor,
*,
with_basepath: bool = False,
**options: Any,
) -> Self:
merged_options = {}
profile = cls.metadata_ensure_profile()
Expand Down
101 changes: 101 additions & 0 deletions frictionless/vendors/stringcase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""
String convert functions

The MIT License (MIT)

Copyright (c) 2015 Taka Okunishi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

# The "stringcase" package appears to unmaintained
# https://github.com/okunishinishi/python-stringcase/issues/42
# Relevant parts have been vendored here so we can fix warnings
# that will eventually become errors
# Code here was copied from the 1.2.0 version uploaded to PyPI
# https://pypi.org/project/stringcase/1.2.0/

import re


def camelcase(string: str):
"""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 lowercase(string: str):
"""Convert string into lower case.

Args:
string: String to convert.

Returns:
string: Lowercase case string.

"""

return str(string).lower()


def snakecase(string: str):
"""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 uppercase(string: str):
"""Convert string into upper case.

Args:
string: String to convert.

Returns:
string: Uppercase case string.

"""

return str(string).upper()
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ dependencies = [
"tabulate>=0.8.10",
"jsonschema>=4.20",
"simpleeval>=0.9.11",
"stringcase>=1.2",
"typer>=0.12",
"validators>=0.18",
"python-slugify>=1.2",
Expand Down
Loading