Skip to main content

python package for code searching through whole code library

Project description

Overview

code_searcher is a simple Python module with the main purpose is to help support changes in any function signature inside your project

(Currently, fully supported file types only are .py and .ipynb nonetheless, search functional can be applied to any file extensions which can be read as plain text in utf-8 encoding).

It’s becoming quite useful when your project outgrows 1k lines of code and manual replacement becomes too annoying (Too easy to overlook replacement somewhere).

Also, this package allows you get some statistics about your project for more info check section: Typical examples of Usage

Installation

  • Install via setup.py:

git clone git@github.com:stas-prokopiev/code_searcher.git
cd code_searcher
python setup.py install
  • Install via pip:

pip install code_searcher

Typical examples of Usage

In any case, the first thing you need to do is to import the necessary module and initialize class obj.

To do so you need to replace “path_to_folder_1” from the code below on most parent folder of all files you want to analyze.

If you have a code of all your projects structured that there is the main folder for all .py files and there is the main folder for all .ipynb files then use them.

from code_searcher import code_searcher_class
list_str_file_extensions = ["path_to_folder_1", "path_to_folder_2", ...]
code_searcher_obj = code_searcher_class(
        list_str_folders_where_to_look,
        list_str_file_extensions=[".py", "ipynb"],
)

1) To find all occurrences of some code.

You’ve changed a function signature and want to do necessary changes in the library.

To find all the places where this function was used use the code below

code_searcher_obj.search_all_occurrences_of_the_code_in_the_library(
    str_code_to_search="previous_function_name(",
    bool_is_to_search_case_sensitive=True,
)

2) To see some statistics about your library.

print(code_searcher_obj)

3) To reload files to up to date versions before searching.

You’ve changed something inside code of your library and want update code for code_searcher

code_searcher_obj.update_files()
... Code from point 1 ...

4) To get the number of not empty code lines in the library

It can be used to measure your everyday performance

code_searcher_obj.get_number_of_lines_in_the_library()

5) To check which functions were defined but never used. (NOT STABLE)

It can be used in order to have your library as short as possible.

code_searcher_obj.get_names_of_all_functions_defined_but_never_used()

6) To check which OUTER modules were imported in the library. (NOT STABLE)

It can be used in order to have only used packages in the virtual environment

code_searcher_obj.get_list_of_all_outer_modules_used_in_the_library()

Full elaboration on code_searcher_obj

code_searcher_obj attributes

list_str_folders_where_to_look: list

list most parent folders where to look for code files

list_str_file_extensionslist

list strings file extensions which files to explore

dict_dict_str_file_by_filename_by_folderdict

{folder_path: {relative_file_path: string_whole_file, …}, …}

code_searcher_obj Methods

search_all_occurrences_of_the_code_in_the_library

Searching some code inside whole library and print all occurrences in a formatted way

update_files

Redownloading all files if something was changed inside them

get_file_stats_of_the_code_library

Getting string statistic about files in the library

get_dict_times_functions_used

Getting {function_name: times_function_used, …}

get_names_of_all_functions_defined_but_never_used

Getting the list of functions defined inside code but never used

get_number_of_lines_in_the_library

Getting number of not empty lines in the whole library

get_list_of_all_outer_modules_used_in_library

Getting list of all OUTER modules imported in the library

Releases

See CHANGELOG.

Contributing

  • Fork it (<https://github.com/stas-prokopiev/code_searcher/fork>)

  • Create your feature branch (git checkout -b feature/fooBar)

  • Commit your changes (git commit -am ‘Add some fooBar’)

  • Push to the branch (git push origin feature/fooBar)

  • Create a new Pull Request

Contacts

License

This project is licensed under the MIT License.

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

code_searcher-0.1.2.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

code_searcher-0.1.2-py2.py3-none-any.whl (12.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file code_searcher-0.1.2.tar.gz.

File metadata

  • Download URL: code_searcher-0.1.2.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for code_searcher-0.1.2.tar.gz
Algorithm Hash digest
SHA256 194b3cd4d4f82d7355fb2972ac2af80238b6f3899a608950eb05242f05f584b4
MD5 c1ccb4f6cb90a3d41a1f3620a0903fbc
BLAKE2b-256 c97bae4a51d527c2436dbc7b95c2ba7035a2bbfabe29b2521e3527804f59d214

See more details on using hashes here.

File details

Details for the file code_searcher-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: code_searcher-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for code_searcher-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 22cca01e7d4bbad4908ae0de2992c20ea68ed2a9ddcdaf2d8843e3870bb591b4
MD5 8b66fd61840e3754beaa9d4a1fa9065a
BLAKE2b-256 f4b0a8bfe25452cc793def340db24502528039002c1e313dfe1d5e9640e03ecb

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