Skip to main content

A package for all things that should be native

Project description

SbNative

An extention to python for debugging and such. Things that, well Should Be Native

SbNative may be used for

  • private projects.
  • public projects (The SbNative repo must be referenced in a Readme in case the source code is available.)

DO NOT DISTRIBUTE.

ALL NON MENTIONED RIGHTS RESERVED.

Chapter 1: debugging

All of the necessary dependencies are located or imported in the debugtools.py file.

  • switchTerminalStacking. Terminal stacking is a method for compressing logged information into a single line if possible. Ex:

    from sbNative.debugtools import log
    
    
    for _ in range(10):
        log("this module should be native!")
    

    leads to this result when not using terminal stacking:

    LOG: this module should be native! --> c:FILEPATH.py:5
    LOG: this module should be native! --> c:FILEPATH.py:5
    LOG: this module should be native! --> c:FILEPATH.py:5
    LOG: this module should be native! --> c:FILEPATH.py:5
    LOG: this module should be native! --> c:FILEPATH.py:5
    LOG: this module should be native! --> c:FILEPATH.py:5
    LOG: this module should be native! --> c:FILEPATH.py:5
    LOG: this module should be native! --> c:FILEPATH.py:5
    LOG: this module should be native! --> c:FILEPATH.py:5
    LOG: this module should be native! --> c:FILEPATH.py:5
    

    which obviously is not very clean... Instead, doing this:

    from sbNative.debugtools import log,switchTerminalStacking
    
    
    switchTerminalStacking()
    
    for _ in range(10):
        log("this module should be native!")
    

    leads to an arguably cleaner output:

    LOG: this module should be native! --> c:FILEPATH.py:7 [10x]
    
  • log. Prints all the arguments given to the console and the file + line of the call. Supports more advanced logging when paired with the cleanRepr class decorator. As shown above, it also claryfies that a value has been logged. Having a line at the end helps finding the log call and editing/removing it quickly. In many editors, (tested in VSCODE) you may CTRL+LEFTCLICK the line and it will redirect you to the file and corresponding line of the call. Ex:

    LOG: this module should be native! --> c:/---/Desktop/test1.py:6
    

    The depth parameter controls how far the lookup goes into the callstack returning the filename and number after the -->. This is a feature for functions written by you, to redirect the user or yourself to the line your function was called at. Incrementing goes further into the callstack. Default: 2.

  • ilog. "Info Log". Behaves mainly like log Only difference: the first argument will be used to represent what is being logged.

  • isFromCall. Gets if a function with the name funcName is in the callstack. Used by __clsRepr to determine if it should add markers in the form of lignSplitSign where newlines can be added if the logging string is too long.

  • cleanRepr. A decorator which makes the representation of your class as clean as possible. If you don't want specific class or instance variables to be included, you may specify their name as arguments for this function.

  • getTerminalOutputs. Returns the terminal output content recorded while the function was running, and the result from the function in a tuple. (TerminalOutput,FunctionResult) WARNING: THIS FUNCTION ALLOCATES THE RESULT TO YOUR DRIVE AND NOT MEMORY. PRINTING MAY BE VERY SLOW, DO NOT EVER USE IN PRODUCTION WITH HIGH WORKLOADS.

  • timer. A simple decorator for timing the execution time of a function or method. Brags the ilog function. (:

  • tPlotArgs Enums or "Flags" to sort after the execution times of the functions or the arguments passed to the function.

  • timePlotter Works the same way as the timer decorator, tho it returns an object and the decorator is the function timePlotter.time. The major difference is the ability to plot the times on a matplotlib graph. You can sort the time or arguments with the Enums from tPlotArgs. The reverse kwarg may only reverse the x axis. The arguments or keyarguments that are supposed to be displayed on the plot have to be passed into the trackArgs/trackKwargs parameters. For args, these have to be the indicies of the argument, for kwargs the name of the keyword-argument. Decorate the function to be tracked with the timer method, and plot them with the show one. You may not use the same instance on multiple functions, otherwise, an error will be raised.

Chapter 2: runtime utilities

All of the neccessary dependencies are located or imported in the runtimetools.py file.

  • getPath Retrieves the path of the file it has been called in. Returns a Path object from the built-in pathlib module.

  • globaliseAllSubitems Adds all the subitems of a module or folder containing a __init__.py file to the global scope, do not ever use this function if you are not desperate, the IDE wont recognise its behaviour.

  • execWithExcTb Extends the built-in exec function, tho shows the exceptions when one is raised, with the appropriate format.

  • runAndCast NOT IMPLEMENTED COMPLETELY YET.

  • safeIter Allows iteration and removal of items inside the iterable simultaneously.

  • bidirectionalDict One may get the original key by the values, like in {"Richard":["Rick","Dick"]} Using indexing or attribute getter with "Richard", "Rick" or "Dick" here will return "Richard" When a value is given and whilst not contained in the dict, a KeyError will be risen. Full Ex:

    d = runtimetools.BiDirectionaldict(
        Richard = ["Dick", "Rick"],
        Annamarie = ["Marie", "Anna", "Ann"]
    )
    
    print(d.Richard, d["Richard"])
    print(d.Rick, d["Rick"])
    print(d.Dick, d["Dick"])
    
    print(d.Annamarie, d["Annamarie"])
    print(d.Marie, d["Marie"])
    print(d.Anna, d["Anna"])
    print(d.Ann, d["Ann"])
    
  • LanguageFormatter Used to format information from a program readable structure to a more easily human readable format. All of these methods are static.

    • enumerateCollection Takes a collection like a list, tuple or anything else with a join method and converts the contents into a human readable enumeration.

    • toAbbrNumber Abbriviates an Integer or float dynamically, using k; m; b; t, by default, which can be changed accordingly to the language unsing the abbriviations kw. The maxPrecisionAmt kw indicates the amount of digits of the output precision.

    • AbbrNumToFloat The exact counterpart to toAbbrNumber WATCH OUT FOR DIFFERENCES IN THE abbriviations VARIABLE

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

sbnative-0.0.17.post2.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sbNative-0.0.17.post2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file sbnative-0.0.17.post2.tar.gz.

File metadata

  • Download URL: sbnative-0.0.17.post2.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for sbnative-0.0.17.post2.tar.gz
Algorithm Hash digest
SHA256 6735979f9dadeead95c73b9547f5d23e256396c9820e30aeed0c68a818e108ef
MD5 e7f8a59384aa20d76f6d77db7f07d09a
BLAKE2b-256 2df8889994718dde86a5f0b8230c5682c52485f3d7a8cd12c3766c1727f040cd

See more details on using hashes here.

File details

Details for the file sbNative-0.0.17.post2-py3-none-any.whl.

File metadata

File hashes

Hashes for sbNative-0.0.17.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 dbd432ca477f4670f9539f11e1897b0bd89f9500a4861fd776814f1e0f059e5f
MD5 516aee7f7a6cfda4345d27c8867e2e6d
BLAKE2b-256 8711e722645a12e011553673a16c8b68451ca3dba43e7c03a076fd0a3a4004cc

See more details on using hashes here.

Supported by

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