Skip to main content

A small utility for searching your source files for specific imports

Project description

py-import-search
================

Utility to search Python source files for imports matching given patterns.

Installation
------------

```
pip install py-import-search
```

Usage
-----

```
usage: py-import-search [-h] [-p --pattern PATTERN] [-d --dir DIR]
[-r --recursive] [-e --exclude-module MODULE]

Search Python source files for imports

optional arguments:
-h, --help show this help message and exit
-p --pattern PATTERN pattern for matching imports (multiple allowed).
-d --dir DIR path of directory containing Python source files.
-r --recursive read all source files under each directory,
recursively.
-e --exclude-module MODULE
exclude module (multiple allowed).
```

Examples
--------
Print all imports for source files in a directory:
```
$ py-import-search -d .
.../src/py-import-search/setup.py: from setuptools import find_packages
.../src/py-import-search/setup.py: from setuptools import setup
.../src/py-import-search/setup.py: import os
```

Print all imports for source files in a directory all subdirectories:
```
$ py-import-search -d . -r
.../src/py-import-search/setup.py: from setuptools import find_packages
.../src/py-import-search/setup.py: from setuptools import setup
.../src/py-import-search/setup.py: import os
.../src/py-import-search/src/pyimportsearch/__init__.py: import argparse
.../src/py-import-search/src/pyimportsearch/__init__.py: import ast
.../src/py-import-search/src/pyimportsearch/__init__.py: import os
.../src/py-import-search/src/pyimportsearch/__init__.py: import re
```

Print imports matching 'setup':
```
$ py-import-search -d . -p setup
.../src/py-import-search/setup.py: from setuptools import find_packages
.../src/py-import-search/setup.py: from setuptools import setup
```

Print imports matching 'setup$':
```
$ py-import-search -d . -p 'setup$'
.../src/py-import-search/setup.py: from setuptools import setup
```

Print imports matching 'setup$':
```
$ py-import-search -d . -p 'setup$'
.../src/py-import-search/setup.py: from setuptools import setup
```

Print all imports for source files in a directory excluding os module:
```
$ py-import-search -d . -e os
.../src/py-import-search/setup.py: from setuptools import find_packages
.../src/py-import-search/setup.py: from setuptools import setup
```

Project details


Release history Release notifications

This version
History Node

0.3

History Node

0.2

History Node

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
py-import-search-0.3.tar.gz (10.6 kB) Copy SHA256 hash SHA256 Source None Apr 11, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page