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

Update version number and attribution in __init__.py #17

Merged
merged 6 commits into from
Jul 23, 2024
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
6 changes: 3 additions & 3 deletions deprecat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

"""

__version__ = "2.1.1"
__author__ = u"Meenal Jhajharia <[email protected]>"
__credits__ = "(c) Meenal Jhajharia"
__version__ = "2.1.2"
__author__ = u"Meenal Jhajharia <[email protected]> and contributors"
__credits__ = "(c) Meenal Jhajharia and contributors"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to add your name there as a co-maintainer!


from deprecat.classic import deprecat
2 changes: 1 addition & 1 deletion deprecat/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_deprecated_msg(self, wrapped, instance, kwargs):
rv=''
if self.deprecated_args[arg].get('reason') is not None:
r = self.deprecated_args[arg]['reason']
fmt += " {reason}"
fmt += " ({reason})"
if self.deprecated_args[arg].get('version') is not None:
v = self.deprecated_args[arg]['version']
fmt += "\n-- Deprecated since v{version}."
Expand Down
6 changes: 3 additions & 3 deletions deprecat/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ def __call__(self, wrapped):
docstring = "\n"

width = self.line_length - 3 if self.line_length > 3 else 2 ** 16
reason=self.reason
reason = self.reason
if self.remove_version!="":
reason += f'\n\n Warning: This deprecated feature will be removed in version {self.remove_version}'
reason += f'\n\nWarning: This deprecated feature will be removed in version {self.remove_version}'
reason = textwrap.dedent(reason).strip()

if self.deprecated_args is None:
Expand Down Expand Up @@ -211,7 +211,7 @@ def __call__(self, wrapped):
div_lines = [fmt.format(version=self.deprecated_args[arg]['version'],arg=arg)]
width = 2**16
if self.remove_version!="":
self.reason += f'\n\n Warning: This deprecated feature will be removed in version {self.remove_version}'
self.reason += f'\n\nWarning: This deprecated feature will be removed in version {self.remove_version}'
reason = textwrap.dedent(self.reason).strip()
#formatting for docstring
for paragraph in reason.splitlines():
Expand Down
8 changes: 4 additions & 4 deletions tests/test_deprecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def foo(a,b):
with warnings.catch_warnings(record=True) as warns:
foo(a=2,b=3)
warn = warns[0]
assert "Call to deprecated Parameter a. nothing\n-- Deprecated since v4.0." in str(warn.message)
assert "Call to deprecated Parameter a. (nothing)\n-- Deprecated since v4.0." in str(warn.message)

def test_deprecated_arg_warn_function_remove_version():
@deprecat.classic.deprecat(deprecated_args={'a':{'version': '1.5', 'remove_version':'4.0', 'reason':'nothing'}})
Expand All @@ -290,7 +290,7 @@ def foo(a,b):
foo(a=2,b=3)
warn = warns[0]
print(warn.message)
assert "Call to deprecated Parameter a. nothing\n-- Deprecated since v1.5.\n-- Will be removed in version 4.0." in str(warn.message)
assert "Call to deprecated Parameter a. (nothing)\n-- Deprecated since v1.5.\n-- Will be removed in version 4.0." in str(warn.message)


def test_deprecated_arg_warn_class_method():
Expand All @@ -305,7 +305,7 @@ def foo5(cls, a, b):
Foo5.foo5(a=3, b=4)

warn = warns[0]
assert 'Call to deprecated Parameter a. nothing\n-- Deprecated since v4.0.' in str(warn.message)
assert 'Call to deprecated Parameter a. (nothing)\n-- Deprecated since v4.0.' in str(warn.message)

def test_deprecated_arg_warn_class_init():

Expand All @@ -320,4 +320,4 @@ def __init__(self,a,b):
foo_cls(a=3,b=4)

warn = warns[0]
assert 'Call to deprecated Parameter a. nothing\n-- Deprecated since v4.0.' in str(warn.message)
assert 'Call to deprecated Parameter a. (nothing)\n-- Deprecated since v4.0.' in str(warn.message)
41 changes: 28 additions & 13 deletions tests/test_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def sphinx_directive(directive):
return mapping[directive]



# noinspection PyShadowingNames
@pytest.mark.parametrize(
"reason, version, remove_version, expected",
Expand All @@ -48,13 +47,13 @@ def sphinx_directive(directive):
'1.2.0',
'1.3.0',
textwrap.dedent(
"\n.. {directive}:: {version}\n {reason}\n\n Warning: This deprecated feature will be removed in version\n {remove_version}\n"
".. {directive}:: {version}\n {reason}\n\n Warning: This deprecated feature will be removed in version\n {remove_version}\n"
),
),
(
None,
'',
'1.2.0',
None,
"",
textwrap.dedent(
"""\
.. {directive}:: {version}
Expand All @@ -74,11 +73,18 @@ def foo(x, y):

# is decorated with:
decorator_factory = getattr(deprecat.sphinx, directive)
decorator = decorator_factory(reason=reason, version=version)
if directive in ("versionadded", "versionchanged") and remove_version is not None:
return

if directive in ("versionadded", "versionchanged"):
decorator = decorator_factory(reason=reason, version=version)
expected = expected.format(directive=sphinx_directive, version=version, reason=reason, remove_version=None)
else:
decorator = decorator_factory(reason=reason, version=version, remove_version=remove_version)
expected = expected.format(directive=sphinx_directive, version=version, reason=reason, remove_version=remove_version)
foo = decorator(foo)

# The function must contain this Sphinx docstring:
expected = expected.format(directive=sphinx_directive, version=version, reason=reason, remove_version=remove_version)

current = textwrap.dedent(foo.__doc__)
assert current.endswith(expected)
Expand Down Expand Up @@ -116,16 +122,16 @@ def foo(x, y):
textwrap.dedent(
"""\
.. {directive}:: {version}
{reason}
{reason}

Warning: This deprecated feature will be removed in version {remove_version}
Warning: This deprecated feature will be removed in version {remove_version}
"""
),
),
(
None,
"",
'1.2.0',
None,
"",
textwrap.dedent(
"""\
.. {directive}:: {version}
Expand All @@ -136,6 +142,8 @@ def foo(x, y):
ids=["reason&version", "version"],
)
def test_cls_has_sphinx_docstring(docstring, directive, sphinx_directive, reason, version, remove_version, expected):
if directive in ("versionadded", "versionchanged") and remove_version is not None:
return
# The class:
class Foo(object):
pass
Expand All @@ -145,9 +153,16 @@ class Foo(object):

# is decorated with:
decorator_factory = getattr(deprecat.sphinx, directive)
decorator = decorator_factory(reason=reason, version=version)

if directive in ("versionadded", "versionchanged"):
decorator = decorator_factory(reason=reason, version=version, line_length=85)
expected = expected.format(directive=sphinx_directive, version=version, reason=reason, remove_version=None, line_length=85)
else:
decorator = decorator_factory(reason=reason, version=version, remove_version=remove_version, line_length=85)
expected = expected.format(directive=sphinx_directive, version=version, reason=reason, remove_version=remove_version, line_length=85)
Foo = decorator(Foo)


# The class must contain this Sphinx docstring:
expected = expected.format(directive=sphinx_directive, version=version, remove_version=remove_version, reason=reason)

Expand Down Expand Up @@ -357,7 +372,7 @@ def foo5(cls, a, b):

assert len(warns) == 1
warn = warns[0]
assert 'Call to deprecated Parameter a. (nothing) -- Deprecated since v4.0.' in str(warn.message)
assert 'Call to deprecated Parameter a. (nothing)\n-- Deprecated since v4.0.' in str(warn.message)

def test_deprecated_arg_warn_class_init():

Expand All @@ -372,7 +387,7 @@ def __init__(self,a,b):
foo_cls(a=3,b=4)

warn = warns[0]
assert 'Call to deprecated Parameter a. (nothing) -- Deprecated since v4.0.' in str(warn.message)
assert 'Call to deprecated Parameter a. (nothing)\n-- Deprecated since v4.0.' in str(warn.message)

def test_deprecated_arg_warn_function_docstring():
@deprecat.sphinx.deprecat(deprecated_args={'a':{'version':'4.0','reason':'nothing', 'remove_version': '5.0'}})
Expand Down
Loading