|
| 1 | +<div align="center"> |
| 2 | + |
| 3 | +<h1>CodeSurvey</h1> |
| 4 | + |
| 5 | +<a href="https://pypi.org/project/codesurvey"> |
| 6 | + <img alt="PyPI" src="https://img.shields.io/pypi/v/codesurvey"> |
| 7 | +</a> |
| 8 | + |
| 9 | +<p> |
| 10 | + <a href="https://github.com/when-of-python/codesurvey">GitHub</a> - <a href="https://when-of-python.github.io/codesurvey">Documentation</a> |
| 11 | +</p> |
| 12 | + |
| 13 | +</div> |
| 14 | + |
| 15 | +CodeSurvey is a framework and tool to survey code repositories for |
| 16 | +language feature usage, library usage, and more: |
| 17 | + |
| 18 | +* Survey a specific set of repositories, or randomly sample |
| 19 | + repositories from services like GitHub |
| 20 | +* Built-in support for analyzing Python code; extensible to support |
| 21 | + any language |
| 22 | +* Write simple Python functions to define the code features you want |
| 23 | + to survey; record arbitrary details of feature occurrences |
| 24 | +* Supports parallelizization of repository downloading and analysis |
| 25 | + across multiple processes |
| 26 | +* Logging and progress tracking to monitor your survey as it runs |
| 27 | +* Inspect the results as Python objects, or in an sqlite database |
| 28 | + |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +``` |
| 33 | +pip install codesurvey |
| 34 | +``` |
| 35 | + |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +The `CodeSurvey` class can easily be configured to run a survey, such |
| 40 | +as to measure how often the `math` module is used in a random set of |
| 41 | +recently updated Python repositories from GitHub: |
| 42 | + |
| 43 | +```python |
| 44 | +from codesurvey import CodeSurvey |
| 45 | +from codesurvey.sources import GithubSampleSource |
| 46 | +from codesurvey.analyzers.python import PythonAstAnalyzer |
| 47 | +from codesurvey.analyzers.python.features import py_module_feature_finder |
| 48 | + |
| 49 | +# Define a FeatureFinder to look for the `math` module in Python code |
| 50 | +has_math = py_module_feature_finder('math', modules=['math']) |
| 51 | + |
| 52 | +# Configure the survey |
| 53 | +survey = CodeSurvey( |
| 54 | + db_filepath='math_survey.sqlite3', |
| 55 | + sources=[ |
| 56 | + GithubSampleSource(language='python'), |
| 57 | + ], |
| 58 | + analyzers=[ |
| 59 | + PythonAstAnalyzer( |
| 60 | + feature_finders=[ |
| 61 | + has_math, |
| 62 | + ], |
| 63 | + ), |
| 64 | + ], |
| 65 | + max_workers=5, |
| 66 | +) |
| 67 | + |
| 68 | +# Run the survey on 10 repositories |
| 69 | +survey.run(max_repos=10) |
| 70 | + |
| 71 | +# Report on the results |
| 72 | +repo_features = survey.get_repo_features(feature_names=['math']) |
| 73 | +repo_count_with_math = sum([ |
| 74 | + 1 for repo_feature in repo_features if |
| 75 | + repo_feature.occurrence_count > 0 |
| 76 | +]) |
| 77 | +print(f'{repo_count_with_math} out of {len(repo_features)} repos use math') |
| 78 | +``` |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +* For more Sources of repositories, see [Source |
| 83 | + docs](https://when-of-python.github.io/codesurvey/sources/core) |
| 84 | +* For more Analyzers and FeatureFinders, see [Analyzer |
| 85 | + docs](https://when-of-python.github.io/codesurvey/analyzers/core) |
| 86 | +* For more options and methods for inspecting results, see |
| 87 | + [`CodeSurvey` docs](https://when-of-python.github.io/codesurvey/core) |
| 88 | +* For details on directly inspecting the sqlite database of survey |
| 89 | + results see [Database docs](https://when-of-python.github.io/codesurvey/database) |
| 90 | +* More examples can be found in |
| 91 | + [examples](https://github.com/when-of-python/codesurvey/tree/main/examples) |
| 92 | + |
| 93 | + |
| 94 | +## Contributing |
| 95 | + |
| 96 | +* Install Poetry dependencies with `make deps` |
| 97 | +* Documentation: |
| 98 | + * Run local server: `make docs-serve` |
| 99 | + * Build docs: `make docs-build` |
| 100 | + * Deploy docs to GitHub Pages: `make docs-github` |
| 101 | + * Docstring style follows the [Google style guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) |
| 102 | + |
| 103 | + |
| 104 | +## TODO |
| 105 | + |
| 106 | +* Add unit tests |
0 commit comments