sbNative


NamesbNative JSON
Version 0.0.16 PyPI version JSON
download
home_pagehttps://pypi.org/project/sbNative/
SummaryA package for all things that should be native
upload_time2024-11-14 10:23:07
maintainerNone
docs_urlNone
authorRICHARD_GALFI
requires_pythonNone
licenseNone
keywords example documentation tutorial
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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: 
    ```python
    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:
    ```python
    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)
    <span style="color:red">***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.***</span>

  - `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` <span style="color:red">***NOT IMPLEMENTED COMPLETELY YET.***</span>

  - `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:
    ```python
    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
    
    
    
    
    
    
    
    
    
    
    
    
    

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/sbNative/",
    "name": "sbNative",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "example documentation tutorial",
    "author": "RICHARD_GALFI",
    "author_email": "richardgalfi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5c/e4/9d5351f7ce35ade295fcdda9489cde625fdd26f0acd56bb244ee38053ba2/sbnative-0.0.16.tar.gz",
    "platform": null,
    "description": "# SbNative\r\nAn extention to python for debugging and such. Things that, well `Should Be Native`\r\n\r\n\r\n## SbNative may be used for\r\n  - private projects.\r\n  - public projects (The SbNative repo must be referenced in a Readme in case the source code is available.)\r\n\r\nDO NOT DISTRIBUTE.\r\n\r\nALL NON MENTIONED RIGHTS RESERVED.\r\n\r\n\r\n## Chapter 1: debugging\r\nAll of the necessary dependencies are located or imported in the `debugtools.py` file.\r\n\r\n  - `switchTerminalStacking`. Terminal stacking is a method for compressing logged information into a single line if possible.\r\n    Ex: \r\n    ```python\r\n    from sbNative.debugtools import log\r\n\r\n\r\n    for _ in range(10):\r\n        log(\"this module should be native!\")\r\n    ```\r\n    leads to this result when not using terminal stacking:\r\n    ```\r\n    LOG: this module should be native! --> c:FILEPATH.py:5\r\n    LOG: this module should be native! --> c:FILEPATH.py:5\r\n    LOG: this module should be native! --> c:FILEPATH.py:5\r\n    LOG: this module should be native! --> c:FILEPATH.py:5\r\n    LOG: this module should be native! --> c:FILEPATH.py:5\r\n    LOG: this module should be native! --> c:FILEPATH.py:5\r\n    LOG: this module should be native! --> c:FILEPATH.py:5\r\n    LOG: this module should be native! --> c:FILEPATH.py:5\r\n    LOG: this module should be native! --> c:FILEPATH.py:5\r\n    LOG: this module should be native! --> c:FILEPATH.py:5\r\n    ```\r\n\r\n    which obviously is not very clean...\r\n    Instead, doing this:\r\n    ```python\r\n    from sbNative.debugtools import log,switchTerminalStacking\r\n\r\n\r\n    switchTerminalStacking()\r\n\r\n    for _ in range(10):\r\n        log(\"this module should be native!\")\r\n    ```\r\n\r\n    leads to an arguably cleaner output:\r\n    ```\r\n    LOG: this module should be native! --> c:FILEPATH.py:7 [10x]\r\n    ```\r\n\r\n  - `log`. Prints all the arguments given to\r\n    the console and the file + line of the call.\r\n    Supports more advanced logging when paired with the `cleanRepr` class decorator.\r\n    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.\r\n    Ex: \r\n    ```\r\n    LOG: this module should be native! --> c:/---/Desktop/test1.py:6\r\n    ```\r\n    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.\r\n  \r\n  - `ilog`. \"Info Log\". Behaves mainly like `log`\r\n    Only difference: the first argument will be used to represent what is being logged.\r\n\r\n  - `isFromCall`. Gets if a function with the name `funcName` is in the callstack.\r\n    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.\r\n\r\n  - `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.\r\n\r\n  - `getTerminalOutputs`. Returns the terminal output content recorded while the function was running, and the result from the function in a tuple.\r\n    (TerminalOutput,FunctionResult)\r\n    <span style=\"color:red\">***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.***</span>\r\n\r\n  - `timer`. A simple decorator for timing the\r\n    execution time of a function or method.\r\n    Brags the `ilog` function. (:\r\n  \r\n  - `tPlotArgs` Enums or \"Flags\" to sort after the execution times of the functions or the arguments passed to the function.\r\n\r\n  - `timePlotter` Works the same way as the `timer` decorator, tho it returns an object and the decorator is the function `timePlotter.time`.\r\n  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`.\r\n  The reverse kwarg may only reverse the x axis.\r\n  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.\r\n  Decorate the function to be tracked with the `timer` method, and plot them with the `show` one.\r\n  You may not use the same instance on multiple functions, otherwise, an error will be raised.\r\n\r\n## Chapter 2: runtime utilities\r\nAll of the neccessary dependencies are located or imported in the `runtimetools.py` file.\r\n\r\n  - `getPath` Retrieves the path of the file it has been called in. Returns a `Path` object from the built-in `pathlib` module.\r\n\r\n  - `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.\r\n\r\n  - `execWithExcTb` Extends the built-in `exec` function, tho shows the exceptions when one is raised, with the appropriate format.\r\n\r\n  - `runAndCast` <span style=\"color:red\">***NOT IMPLEMENTED COMPLETELY YET.***</span>\r\n\r\n  - `safeIter` Allows iteration and removal of items inside the iterable simultaneously.\r\n\r\n  - `bidirectionalDict` One may get the original key by the values, like in {\"Richard\":[\"Rick\",\"Dick\"]}\r\n    Using indexing or attribute getter with \"Richard\", \"Rick\" or \"Dick\" here will return \"Richard\"\r\n    When a value is given and whilst not contained in the dict, a KeyError will be risen.\r\n    Full Ex:\r\n    ```python\r\n    d = runtimetools.BiDirectionaldict(\r\n        Richard = [\"Dick\", \"Rick\"],\r\n        Annamarie = [\"Marie\", \"Anna\", \"Ann\"]\r\n    )\r\n\r\n    print(d.Richard, d[\"Richard\"])\r\n    print(d.Rick, d[\"Rick\"])\r\n    print(d.Dick, d[\"Dick\"])\r\n\r\n    print(d.Annamarie, d[\"Annamarie\"])\r\n    print(d.Marie, d[\"Marie\"])\r\n    print(d.Anna, d[\"Anna\"])\r\n    print(d.Ann, d[\"Ann\"])\r\n    ```\r\n\r\n  - `LanguageFormatter` Used to format information from a program readable structure to a more easily human readable format. All of these methods are static.\r\n\r\n    - `enumerateCollection` Takes a collection like a list, tuple or anything else with a join method and converts the contents into a human readable enumeration.\r\n    \r\n    - `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.\r\n    \r\n    - `AbbrNumToFloat` The exact counterpart to ***toAbbrNumber***\r\n        WATCH OUT FOR DIFFERENCES IN THE `abbriviations` VARIABLE\r\n    \r\n    \r\n    \r\n    \r\n    \r\n    \r\n    \r\n    \r\n    \r\n    \r\n    \r\n    \r\n    \r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A package for all things that should be native",
    "version": "0.0.16",
    "project_urls": {
        "Homepage": "https://pypi.org/project/sbNative/"
    },
    "split_keywords": [
        "example",
        "documentation",
        "tutorial"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b378fa1f6d2ae99221dd5b548216227e068c4a28cf92ba2e61f739a071b41481",
                "md5": "4e9c6831f597d7485a63832aa07e6d53",
                "sha256": "3fa6c92e0b3473501ba74d4c39a6ee90dc9ea55606f64c24e60ee06eb9c98fca"
            },
            "downloads": -1,
            "filename": "sbNative-0.0.16-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4e9c6831f597d7485a63832aa07e6d53",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 12662,
            "upload_time": "2024-11-14T10:23:05",
            "upload_time_iso_8601": "2024-11-14T10:23:05.541281Z",
            "url": "https://files.pythonhosted.org/packages/b3/78/fa1f6d2ae99221dd5b548216227e068c4a28cf92ba2e61f739a071b41481/sbNative-0.0.16-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ce49d5351f7ce35ade295fcdda9489cde625fdd26f0acd56bb244ee38053ba2",
                "md5": "d1316b9a6f38f11f7754b399bc799799",
                "sha256": "9ab3bc4f8721ed239da8418c8566d02326a9570acf5c63832ad5d480f78c0e16"
            },
            "downloads": -1,
            "filename": "sbnative-0.0.16.tar.gz",
            "has_sig": false,
            "md5_digest": "d1316b9a6f38f11f7754b399bc799799",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12347,
            "upload_time": "2024-11-14T10:23:07",
            "upload_time_iso_8601": "2024-11-14T10:23:07.343564Z",
            "url": "https://files.pythonhosted.org/packages/5c/e4/9d5351f7ce35ade295fcdda9489cde625fdd26f0acd56bb244ee38053ba2/sbnative-0.0.16.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-14 10:23:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "sbnative"
}
        
Elapsed time: 0.51702s