Skip to main content

dev-tool-for-python

a small tool for python development

Build Status

Introduction

Recently, I have wrote a lot of python codes but always like this.

devtool-example

wtf

I think i am a bad programmer. o( ̄ヘ ̄o#)

I will forget where can i find the proper function or method even with a doc-string.(But i seldom write doc-string when coding alone.)

So i want to develop a tool to record informations when coding by using python decorators.

HOW TO USE.

1. Download this repo. run

pip install -r requestments.txt

2. Copy the "devtool" folder into your project.

3. Details.

3.1 For logs filter.

from devtool.devTool import DevTool
DevTool.logFilter(*kwds, **params)

kws are the keywords to be searched,params include path,since and until under this version.

To record log file easily,try this.

from devtool import logit

@logit()
def test4():
    x = 1 / 0

test4()

then DevLog/devlog.log will be created and log information will be added.

2021-01-09 09:49:00,143 - DevTool - ERROR - __main__.test4 Traceback (most recent call last):
File "D:\dev-tool-for-python\devtool\__init__.py", line 112, in execute
    func(*args, **kwargs)
File ".\testWrap.py", line 35, in test4
    x = 1 / 0
ZeroDivisionError: division by zero

@logit can add three params: save,load,ignore

@save ,to record the function ,params and result to DevLog/devCache.dump

@load, load result from DevLog/devCache.dump if the function costs much time. if the params are same to the stored params, then return the result. Otherwise, excute again.

@ignore, force to execute the function

@logit(save=True,load=True,ignore=False)
def test8(a=1,b=2):
    import time
    rs = 'aaaaab'
    t1 = time.time()
    time.sleep(5)
    print(time.time()-t1)
    return rs

if __name__ == "__main__":
    a = test8(a=3,b=4)
    print(a)

first time:

(base) PS D:\dev-tool-for-python> python .\testWrap.py
5.01481556892395
aaaaab

second time:

(base) PS D:\dev-tool-for-python> python .\testWrap.py
aaaaab

linux

3.2 init a new python project

from devtool.devTool import DevTool

if __name__ == "__main__":
    DevTool.initProject('Test')

initproject

If 'DevTool.initProject' got a param 'tree=True', then

This script needs a parameter "path",but got "",using D:\testALg\mask2json\devTool\dev-tool-for-python\Test instead.
Init finishes.
.
|-- main.py
|-- static
|-- tests
|-- utils
|   |-- __init__.py

The structure of project is stored in style.yaml.

MINE:
    scripts:
        main : root/main.py
        utils_init : root/utils/__init__.py
    folders:
        static : root/static
        utils : root/utils
        tests : root/tests

And "MINE" is my style. :)

Change log

2021.1.26

  1. merge some usage from 'show-and-search'

  2. add function plot

To use this decorator, try testPlot.py, effect:

@traceplot(False)
def add1(a, b):
    c = 3
    d = 4
    e = c + d
    return a + b + e

@traceplot()
def add2(a, b):
    c = 3
    d = 4
    e = c + d
    return a + b + e

if __name__ == "__main__":
    add1(3,4)
    add2(3,4)


(base) PS D:\testALg\mask2json\devTool\dev-tool-for-python> & D:/anaconda/python.exe d:/testALg/mask2json/devTool/dev-tool-for-python/testPlot.py
call __main__.add1:35 {'a': 3, 'b': 4} None
line __main__.add1:37 {'a': 3, 'b': 4} None
line __main__.add1:38 {'a': 3, 'b': 4, 'c': 3} None
line __main__.add1:39 {'a': 3, 'b': 4, 'c': 3, 'd': 4} None
line __main__.add1:40 {'a': 3, 'b': 4, 'c': 3, 'd': 4, 'e': 7} None
return __main__.add1:40 {'a': 3, 'b': 4, 'c': 3, 'd': 4, 'e': 7} 14

        section1
 _____________________
|        call         |
|      __main__       |
|       add2:42       |
|        None         |
|_____________________|

            |
            |
            |
            |
            V

        section2
 _____________________
|        line         |
|      __main__       |
|       add2:44       |
|        None         |
|_____________________|

            |
            |
            |
            |
            V

        section3
 _____________________
|        line         |
|      __main__       |
|       add2:45       |
|        None         |
|_____________________|

            |
            |
            |
            |
            V

        section4
 _____________________
|        line         |
|      __main__       |
|       add2:46       |
|        None         |
|_____________________|

            |
            |
            |
            |
            V

        section5
 _____________________
|        line         |
|      __main__       |
|       add2:47       |
|        None         |
|_____________________|

            |
            |
            |
            |
            V

        section6
 _____________________
|       return        |
|      __main__       |
|       add2:47       |
|         14          |
|_____________________|

            |
            |
            O
  1. running function with a int number as the memory threshold.

     @running(mThres=5)
     def test11():
         i = 0
         while i <= 2:
             print(test11.__name__ + ' running')
             time.sleep(1.5)
             i += 1
    

    test11 running memory : 21MB, memory_persent : 0.261%, cpu_percent : 0.0

    This function out of memory with threshold 5 MB, but got 21 MB during runtime.

2021.1.25

  1. add decorator "running", see here

To use this decorator, try testWrap.test10, effect:

(base) PS D:\testALg\mask2json\devTool\dev-tool-for-python> python .\testWrap.py
test10 running
memory : 21MB, memory_persent : 0.264%, cpu_percent : 0.0
memory : 21MB, memory_persent : 0.264%, cpu_percent : 0.0
memory : 21MB, memory_persent : 0.264%, cpu_percent : 0.0
test10 running
memory : 21MB, memory_persent : 0.264%, cpu_percent : 0.0
memory : 21MB, memory_persent : 0.264%, cpu_percent : 0.0
memory : 21MB, memory_persent : 0.264%, cpu_percent : 0.0
test10 running
memory : 21MB, memory_persent : 0.264%, cpu_percent : 0.0
memory : 21MB, memory_persent : 0.264%, cpu_percent : 0.0
memory : 21MB, memory_persent : 0.264%, cpu_percent : 0.0

                                        Total
            =============================================================
            Used time:                 9.000941753387451 s,
            Average memory:            21.0 MB,
            Average memory percent:    0.264 %,
            Average cpu percent:       0.0 % ,
            Average used gpu:          0.0 MB.
            =============================================================

Metadata

Release files for DevTool 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for DevTool 0.0.2
File Size Uploaded Provenance Actions
DevTool-0.0.2.tar.gz 14.2 kB Without provenance Details for DevTool-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for DevTool 0.0.2
File Interpreter ABI Platform Actions
DevTool-0.0.2-py3-none-any.whl Python 3 none any Details for DevTool-0.0.2-py3-none-any.whl

Total release size: 33.4 kB

Release files / DevTool-0.0.2.tar.gz

Download URL DevTool-0.0.2.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b0d4427f5a32551f2adcecb62132060acb7947b73e448f2e7d072a26b6a4c0d9
BLAKE2b-256 checksum
How to use checksums
d44f9a0188810abf8c31a32d009c207026222e42d67f29842ca4c46bf3977d95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.32.1 CPython/3.7.3

Release files / DevTool-0.0.2-py3-none-any.whl

Download URL DevTool-0.0.2-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88fd43ca188b815d39fc8a274d5171928a09e7146fe9b66d000c8dde5c173152
BLAKE2b-256 checksum
How to use checksums
76321b7aa88a1939e6ac1dc837fb014fda9179227fcd2df77b255e72bfc00450
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.32.1 CPython/3.7.3

Security for DevTool 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page