• Stars
    star
    127
  • Rank 281,349 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A CLI tool to search for Python code in a path using jQuery-like selectors.

pyq

A command-line tool to search for Python code using jQuery-like selectors

PyPI version

Installation

pip install pyqtool

Notice: As the tool is still under heavy development, you may see that some features are not yet available in the version distributed over PyPI. If you want to have a fresh taste, you can get it directly from source:

pip install https://github.com/caioariede/pyq/archive/master.zip -U

Please report any possible issues, we expect the master branch to be stable.

Usage

Usage: pyq3 [OPTIONS] SELECTOR [PATH]...

Options:
-l / --files       Only print filenames containing matches.
--ignore-dir TEXT  Ignore directory.
-n / --no-recurse  No descending into subdirectories.
-e / --expand      Show multiple matches in the same line.
--help             Show this message and exit.

The executable name will vary depending on the Python version: pyq2 pyq3

Available selectors

Type selectors
Name Attributes Additional notes
class class name
def def name
import import name
import name as name
from from import name
It's also possible to match the full import using
the special attribute full
assign name [, name ...] = value
call name(arg, arg, ..., kwarg=, kwarg=, ...)
attr foo.name.name
ID/Name selector
Syntax Applied to
#name class, def, assign, call, attr

Attribute selectors

Syntax Description
[name=value] Attribute name is equal to value
[name!=value] Attribute name is not equal to value
[name*=value] Attribute name contains value
[name^=value] Attribute name starts with value
[name$=value] Attribute name endswith value

Pseudo selectors

Syntax Applies to Description
:extends(selector) class Selects classes that its bases matches selector
:has(selector) all Selects everything that its body match selector
:not(selector) all Selects everything that do not match selector

Combinators

Syntax Description
parent > child Select direct child from parent
parent descendant Selects all descendant from parent

Examples

Search for classes that extends the IntegerField class:

pyq3 'class:extends(#IntegerField)' django/forms
django/forms/fields.py:278 class FloatField(IntegerField):
django/forms/fields.py:315 class DecimalField(IntegerField):

Search for classes with the name FloatField:

pyq3 'class[name=FloatField]' django/forms
django/forms/fields.py:278 class FloatField(IntegerField):

Search for methods under the FloatField class:

pyq3 'class[name=FloatField] > def' django/forms
django/forms/fields.py:283     def to_python(self, value):
django/forms/fields.py:299     def validate(self, value):
django/forms/fields.py:308     def widget_attrs(self, widget):

Search for methods whose name starts with to under the FloatField class:

pyq3 'class[name=FloatField] > def[name^=to]' django/forms
django/forms/fields.py:283     def to_python(self, value):

Search for import statements importing Counter:

pyq3 'import[from=collections][name=Counter]' django/
django/apps/registry.py:5 from collections import Counter, OrderedDict, defaultdict
django/template/utils.py:3 from collections import Counter, OrderedDict
django/test/testcases.py:14 from collections import Counter
...

Search for classes without methods:

pyq3 'class:not(:has(> def))' django/core
django/core/exceptions.py:8 class FieldDoesNotExist(Exception):
django/core/exceptions.py:13 class DjangoRuntimeWarning(RuntimeWarning):
django/core/exceptions.py:17 class AppRegistryNotReady(Exception):
...

More Repositories

1

django-location-field

Location field and widget for Django. It supports Google Maps, OpenStreetMap and Mapbox
JavaScript
544
star
2

uber-react

Uber-like project in React Native
JavaScript
152
star
3

django-input-mask

A collection of widgets for displaying masks to input elements using JavaScript.
Python
52
star
4

pyintercept

Intercept function calls from Python scripts
Python
33
star
5

dpv

dpv is an alternative to pyenv-virtualenv and virtualenvwrapper
Shell
21
star
6

django-polymer-sample-app

This is a sample application that demonstrates how Django can interact with Polymer
HTML
19
star
7

detect-django-version

Demonstrates a simple approach to detect which version of Django a website is running
Python
15
star
8

swfk-ptbr

Tradução do livro "Snake Wrangling for Kids" - Domando Serpentes para Crianças
Python
11
star
9

pum

Pum is a fast and light-weight URL shortener service
Nim
8
star
10

erlang-programming-book

Erlang Programming Book Exercises
Erlang
6
star
11

rice

A functional programming language based on Python and Ruby that runs on the Erlang VM
Erlang
6
star
12

openimob

An open-source CMS solution for Real Estate websites on top of Wagtail
CSS
5
star
13

python-simpleauth

A very simple authentication system using Python
Python
2
star
14

go-framereader

A simple API to Iterate over video frames sent over STDIN using MJPEG or PPM formats
Go
2
star
15

erlang-euler

Some Euler problems solved in Erlang Programming Language
Erlang
2
star
16

django-paralleltests

A Test Runner for Django that runs tests in parallel (needs Docker for isolation)
Python
2
star
17

django-oscar-cielo

Cielo (brazilian payment gateway) module for django-oscar
Python
2
star
18

tpll

HTML Template Engine for Haskell inspired by Django Template Language
Haskell
2
star
19

cliapi

Dead simple way to create Web APIs for command-line tools
Python
1
star
20

django-pikaday

A simple app that provides easy integration with the Pikaday Datepicker
JavaScript
1
star
21

.vimrc

Vim Script
1
star