Skip to main content

Identify unwanted function calls in your code

Project description

Pyaphid

PyPI version GitHub license GitHub issues PyPI - Downloads Tests Codecov

Description

Pyaphid is a static analysis tool for detecting unwanted function calls in Python code.

Installation and usage

Installation: pip install pyaphid

Usage: python -m pyaphid <files and/or directories to analyze> or pyaphid <files and/or directories to analyze>

Configuration

Forbidden function calls can be configured via the pyproject.toml:

[tool.pyaphid]
forbidden = [
    "print", # forbid print(...)
    "pdb.run", # forbid pdb.run(...)
    "werkzeug.debug.*", # forbid werkzeug.debug.DebuggedApplication(...), werkzeug.debug.get_machine_id(...), ...
    "datetime.datetime.now" # forbid datetime.now()
]

With datetime.now for example you usually want to ignore one call to it for implementing a project-wide default function. You can use # pyaphid: ignore to ignore a line:

from dateutil.tz import tzlocal
from datetime import datetime

def get_now():
  # allowed
  return datetime.now(tzlocal()) # pyaphid: ignore

datetime.now() # forbidden

CLI Options

  • -n / --names: Look-up all func calls and print their identifier

As a pre-commit hook

- repo: https://github.com/jvllmr/pyaphid
  rev: v0.3.0
  hooks:
    - id: pyaphid

Limitations

# Pyaphid cannot work with star imports
from os.path import *
dirname(".") # undetected

# Pyaphid ignores relative imports
from . import something
something() # undetected

# Pyaphid doesn't track assignments
my_print = print
my_print("Hello world") # undetected

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

pyaphid-0.3.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

pyaphid-0.3.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pyaphid-0.3.0.tar.gz.

File metadata

  • Download URL: pyaphid-0.3.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for pyaphid-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a3405a44d3d6148eae3fea6934c1d0b85e5eea9ab745354b6171ad1809553aad
MD5 dcb1f40afbe464aed5ba1182bd754b9c
BLAKE2b-256 b9cdf5c8da7c8b816b4bf9ced919132d0db178283d5aee910d5c175ccff2860e

See more details on using hashes here.

File details

Details for the file pyaphid-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyaphid-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for pyaphid-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6875fc44f38dd9f4b21588c5bf5fe8ddc4b3bce566e7dd4965fe1bd2365aa77
MD5 f414de04f445a8305637182a0d299148
BLAKE2b-256 9f66fbba5da70142a6435713546ef77cf0627eb8c6fef2867ebdbde3a5eb37be

See more details on using hashes here.

Supported by

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