Skip to main content

Convert GitHub Repo Into Graph

Project description

Sourcegraph Python Library

This Python library provides an interface to analyze and visualize code dependencies in GitHub repositories.

⚠️ Warning: Currently only supports Python repositories

Please note that this library is currently designed to work only with Python repositories. Analysis of repositories in other programming languages is not supported at this time.

Installation

You can install the Sourcegraph Python library using pip:

pip install sourcegraph

Usage

Here's how you can use the Sourcegraph library to analyze a GitHub repository:

from sourcegraph import Sourcegraph

# Initialize the Sourcegraph object with a repository URL
repo = Sourcegraph(repository_url='https://github.com/Ransaka/sinlib.git')

# Generate a dependency graph
repo.run()

# Plot the dependency graph
repo.plot()  # Supports different networkx compatible layouts when plotting

# Get properties of a specific node (function or class)
node_properties = repo.get_node_property('process_text')
print(node_properties)

# Get the total number of nodes in the repository
print(repo.n_nodes)

# Get all functions and classes in the repository
functions_and_classes = repo.get_functions_and_classes
print(functions_and_classes)

# Get dependencies of a specific class or function
tokenizer_dependencies = repo.get_dependencies("Tokenizer")
print(tokenizer_dependencies)

Features

  • Dependency Analysis: Analyze and visualize the dependencies between functions and classes in a GitHub repository.
  • Code Inspection: Retrieve detailed information about specific functions or classes, including their definitions and docstrings.
  • Visualization: Plot dependency graphs using networkx-compatible layouts.

Main Methods

  • run(): Generates the dependency graph for the specified repository.
  • plot(): Visualizes the dependency graph.
  • get_node_property(node_name): Retrieves properties of a specific node (function or class).
  • get_functions_and_classes: Returns a list of all functions and classes in the repository.
  • get_dependencies(node_name): Returns the dependencies of a specific function or class.

Example Output

Getting node properties:

repo.get_node_property('process_text')
# Output:
# {'type': 'function',
#  'name': 'process_text',
#  'definition': "def process_text(t):\n    ...",
#  'file_name': 'preprocessing.py',
#  'docstring': ''}

Getting all functions and classes:

repo.get_functions_and_classes
# Output:
# ['Romanizer', 'Tokenizer', 'Transliterator', 'load_tokenizer', ...]

Getting dependencies:

repo.get_dependencies("Tokenizer")
# Output:
# {'load_default_vocab_map', 'process_text'}

Limitations

  • Currently, this library only supports analysis of Python repositories. Repositories in other programming languages cannot be processed at this time.
  • The library assumes that the repository structure follows common Python project conventions.

Contributing

Contributions to improve the Sourcegraph Python library are welcome. Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For any queries or suggestions, please open an issue on the GitHub repository.

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

sourcegraph-0.0.7.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

sourcegraph-0.0.7-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file sourcegraph-0.0.7.tar.gz.

File metadata

  • Download URL: sourcegraph-0.0.7.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for sourcegraph-0.0.7.tar.gz
Algorithm Hash digest
SHA256 e62d7e1392a046df1965feefee0aa6125a7b4f431db57c245693dc2e60f45c5d
MD5 dde933fc1a65b07ed51ff7fdd8f45001
BLAKE2b-256 d68d41f90f8ab52e956a31376ba40460c0fb345f9ff0fd821fbaaf2bb7351e6c

See more details on using hashes here.

File details

Details for the file sourcegraph-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: sourcegraph-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for sourcegraph-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 48b90548fb6337a8a5accafa2bb3a78b87a1c19bb50b0a58c0353eae7707baf4
MD5 e9f5787332e48378ca1f65852dcbc14e
BLAKE2b-256 1e75e02b7b367335bead609d9e44f78d12ae72079e26f846444c1fd11631d0b5

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