Skip to main content

Detection of file that generate side effects when imported.

Project description

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 :

# 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 :

# my_lib.py
print("42")
class MyLib(object):
    pass
$ 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

# my_lib.py
print("42")  # ignoredthisline
class MyLib(object):
    pass
$ 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.

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

pydise-0.0.5.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

pydise-0.0.5-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file pydise-0.0.5.tar.gz.

File metadata

  • Download URL: pydise-0.0.5.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for pydise-0.0.5.tar.gz
Algorithm Hash digest
SHA256 96f7aa70d3cab829741623ab92fa757d86b6a4c826c571eb421f2575fc19c9c8
MD5 ce9b6d7f79d870126570fb6256d2c6d7
BLAKE2b-256 0a06fb3965f82cdaf37fbf60f3d4d9df1a82206dacfaf7151955bd93e4db9b7b

See more details on using hashes here.

File details

Details for the file pydise-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pydise-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for pydise-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 864964d813d405540bc3ade5a31aee6facaafdbb474091a58410ebf19a03cdc4
MD5 a45cea321cdb5f1874fa54fb6fa33ba5
BLAKE2b-256 a1914fecc850fc78e1ca564eddd1958e0f8b15831bd82b262fa852b4c3d2ab9b

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