Skip to main content

Python decorator and command to automate deprecating components

Project description

Auto deprecator

https://img.shields.io/pypi/v/auto_deprecator.svg https://travis-ci.org/gavincyi/auto-deprecator.svg Documentation Status

Python decorator and command to automate deprecating components

How does it work?

We believe that deprecating a component in your library should work in the following ways

  1. Alert the users the deprecation time

When the user calls the methods or initializes the objects which will be deprecated in the next version or on an expected date, the user should receive the warning of the future deprecation but get the return in success.

from auto_deprecator import deprecate

@deprecate(expiry='2.0.0')
def old_hello_world():
    return print("Hello world!")
>>> old_hello_world()
Hello world!
DeprecationWarning: The function "old_hello_world" will be deprecated in version 2.0.0
  1. Test as if deprecated

Before the component is deprecated, unit / integration testing should be run to ensure the deprecation does not break the existing flow. Pass in the environment variables in the testing to simulate that the version is deployed.

(bash) hello-world-app
Hello world!
DeprecationWarning: The function "old_hello_world" will be deprecated in version 2.0.0
(bash) DEPRECATED_VERSION=2.0.0 hello-world-app
Traceback (most recent call last):
 ...
RuntimeError: The function "old_hello_world" is deprecated in version 2.0.0
  1. Automatic deprecation before release

Deprecating the functions is no longer a manual work. Every time before release, run the command auto-deprecate to remove the functions deprecated in the coming version.

(bash) auto-deprecate hello_world.py --version 2.0.0
(bash) git diff

diff --git a/hello_world.py b/hello_world.py
index 201e546..ec41365 100644
--- a/hello_world.py
+++ b/hello_world.py
@@ -1,8 +1,2 @@
-from auto_deprecator import deprecate
-
 def hello_world():
     return print("Hello world!")
-
-@deprecate(expiry='2.0.0')
-def old_hello_world():
-    return print("Hello world!")

History

0.1.0 (2019-12-26)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auto_deprecator-2020.1.2.tar.gz (14.5 kB view hashes)

Uploaded Source

Built Distribution

auto_deprecator-2020.1.2-py2.py3-none-any.whl (6.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page