pydise


Namepydise JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/Hwoahwoa/pydise
SummaryDetection of file that generate side effects when imported.
upload_time2023-11-27 11:43:32
maintainer
docs_urlNone
authorHwoahwoa
requires_python>=3.9
license
keywords python import side-effect
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pydise
***This script is designed to detect Python scripts that generate side effects when imported into another code.***

Side effects refer to unintended changes to the global state of the system, such as writing files, or displaying undesired outputs when a script is imported without being directly executed.

**Example of side effects** : 
```python
# my_lib.py
print("42")
class MyLib(object):
    pass

# my_script.py
>>> import my_lib
42
```

That's what we want to avoid.

# How it works

The script analyzes the content of Python files specified in the source directory to identify elements which may indicate side effects, eg :

    * print("hello")
    * open("myfile", "rw")
    * exit()
    * if True:
         exit()
    ...

We used AST, so no code are executed.

The script then provides a report of the files that potentially contain side effects so that you can identify and correct them if necessary.

# Usage

```
$ pip install pydise
$ pydise
```

Example :

``` python
# my_lib.py
print("42")
class MyLib(object):
    pass
```

``` python
$ pydise
ERROR:root:.\my_lib.py:1 -> Side effects detected : print
```

# Arguments

## Positional arguments:
  **filename** : `file to check (wildcard)`

*Example* : 

```
$ pydise mylib.py
$ pydise *.py
$ pydise .
```

## Options:


  **--list-only** : `list the detected files without checking errors.`

*Example* : 

```
$ pydise --list-only
Detected files : 
* .\my_lib.py
* .\my_lib2.py
```

  **--pattern-ignored** : `ignore line containing the pattern, multiple patterns can be setted, the pattern is added to the default patterns.`

*default patterns* : `# no-pydise` or `# no_pydise`

``` python
# my_lib.py
print("42")  # ignoredthisline
class MyLib(object):
    pass
```

``` python
$ pydise --pattern-ignored ignoredthisline --pattern-ignored anotherpattern
```

# Contributions

I am a self-taught developer, it's highly possible that my code could be buggy / optimizable, so any contributions to improving this script are welcome! 
If you find issues or want to add new features, feel free to create a pull request.

# Disclaimer

Make sure you understand the implications of using this script as it may generate false positives or fail to detect certain side effects, depending on the complexity of the analyzed code. It is recommended to manually review the report results before making critical decisions regarding your code.

# License

This project is licensed under the MIT License - you can use, modify, and distribute it freely while retaining the original license notice.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Hwoahwoa/pydise",
    "name": "pydise",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "python,import,side-effect",
    "author": "Hwoahwoa",
    "author_email": "hwoahwoa@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0a/06/fb3965f82cdaf37fbf60f3d4d9df1a82206dacfaf7151955bd93e4db9b7b/pydise-0.0.5.tar.gz",
    "platform": null,
    "description": "# pydise\n***This script is designed to detect Python scripts that generate side effects when imported into another code.***\n\nSide effects refer to unintended changes to the global state of the system, such as writing files, or displaying undesired outputs when a script is imported without being directly executed.\n\n**Example of side effects** : \n```python\n# my_lib.py\nprint(\"42\")\nclass MyLib(object):\n    pass\n\n# my_script.py\n>>> import my_lib\n42\n```\n\nThat's what we want to avoid.\n\n# How it works\n\nThe script analyzes the content of Python files specified in the source directory to identify elements which may indicate side effects, eg :\n\n    * print(\"hello\")\n    * open(\"myfile\", \"rw\")\n    * exit()\n    * if True:\n         exit()\n    ...\n\nWe used AST, so no code are executed.\n\nThe script then provides a report of the files that potentially contain side effects so that you can identify and correct them if necessary.\n\n# Usage\n\n```\n$ pip install pydise\n$ pydise\n```\n\nExample :\n\n``` python\n# my_lib.py\nprint(\"42\")\nclass MyLib(object):\n    pass\n```\n\n``` python\n$ pydise\nERROR:root:.\\my_lib.py:1 -> Side effects detected : print\n```\n\n# Arguments\n\n## Positional arguments:\n  **filename** : `file to check (wildcard)`\n\n*Example* : \n\n```\n$ pydise mylib.py\n$ pydise *.py\n$ pydise .\n```\n\n## Options:\n\n\n  **--list-only** : `list the detected files without checking errors.`\n\n*Example* : \n\n```\n$ pydise --list-only\nDetected files : \n* .\\my_lib.py\n* .\\my_lib2.py\n```\n\n  **--pattern-ignored** : `ignore line containing the pattern, multiple patterns can be setted, the pattern is added to the default patterns.`\n\n*default patterns* : `# no-pydise` or `# no_pydise`\n\n``` python\n# my_lib.py\nprint(\"42\")  # ignoredthisline\nclass MyLib(object):\n    pass\n```\n\n``` python\n$ pydise --pattern-ignored ignoredthisline --pattern-ignored anotherpattern\n```\n\n# Contributions\n\nI am a self-taught developer, it's highly possible that my code could be buggy / optimizable, so any contributions to improving this script are welcome! \nIf you find issues or want to add new features, feel free to create a pull request.\n\n# Disclaimer\n\nMake sure you understand the implications of using this script as it may generate false positives or fail to detect certain side effects, depending on the complexity of the analyzed code. It is recommended to manually review the report results before making critical decisions regarding your code.\n\n# License\n\nThis project is licensed under the MIT License - you can use, modify, and distribute it freely while retaining the original license notice.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Detection of file that generate side effects when imported.",
    "version": "0.0.5",
    "project_urls": {
        "Homepage": "https://github.com/Hwoahwoa/pydise"
    },
    "split_keywords": [
        "python",
        "import",
        "side-effect"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a1914fecc850fc78e1ca564eddd1958e0f8b15831bd82b262fa852b4c3d2ab9b",
                "md5": "a45cea321cdb5f1874fa54fb6fa33ba5",
                "sha256": "864964d813d405540bc3ade5a31aee6facaafdbb474091a58410ebf19a03cdc4"
            },
            "downloads": -1,
            "filename": "pydise-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a45cea321cdb5f1874fa54fb6fa33ba5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9453,
            "upload_time": "2023-11-27T11:43:30",
            "upload_time_iso_8601": "2023-11-27T11:43:30.334392Z",
            "url": "https://files.pythonhosted.org/packages/a1/91/4fecc850fc78e1ca564eddd1958e0f8b15831bd82b262fa852b4c3d2ab9b/pydise-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0a06fb3965f82cdaf37fbf60f3d4d9df1a82206dacfaf7151955bd93e4db9b7b",
                "md5": "ce9b6d7f79d870126570fb6256d2c6d7",
                "sha256": "96f7aa70d3cab829741623ab92fa757d86b6a4c826c571eb421f2575fc19c9c8"
            },
            "downloads": -1,
            "filename": "pydise-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "ce9b6d7f79d870126570fb6256d2c6d7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 10472,
            "upload_time": "2023-11-27T11:43:32",
            "upload_time_iso_8601": "2023-11-27T11:43:32.687908Z",
            "url": "https://files.pythonhosted.org/packages/0a/06/fb3965f82cdaf37fbf60f3d4d9df1a82206dacfaf7151955bd93e4db9b7b/pydise-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-27 11:43:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Hwoahwoa",
    "github_project": "pydise",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pydise"
}
        
Elapsed time: 0.14289s