├── .coveragerc ├── .github └── workflows │ └── main.yml ├── .gitignore ├── CONTRIBUTING.rst ├── LICENSE ├── README.rst ├── beagle ├── __init__.py ├── app.py ├── grep_formatter.py ├── hound.py ├── openstack.py └── search.py ├── doc ├── requirements.txt └── source │ ├── cli │ └── index.rst │ ├── conf.py │ ├── history.rst │ ├── index.rst │ ├── install │ └── index.rst │ └── user │ └── index.rst ├── requirements.txt ├── setup.cfg ├── setup.py └── tox.ini /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = beagle/tests/* -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Test & Checks 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | tests: 7 | name: Tests & Checks 8 | runs-on: ubuntu-latest 9 | strategy: 10 | matrix: 11 | python: ["3.9", "3.10", "3.11", "3.12"] 12 | 13 | steps: 14 | - uses: actions/checkout@v4 15 | - name: Set up Python 16 | uses: actions/setup-python@v3 17 | with: 18 | python-version: ${{matrix.python}} 19 | - name: Install dependencies 20 | run: | 21 | python -m pip install --upgrade pip 22 | pip install tox pbr 23 | pip install -r doc/requirements.txt .[test] 24 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 25 | - name: Check doc 26 | run: tox -e docs 27 | - name: Check with linters 28 | run: tox -e pep8 29 | - name: Check covering 30 | run: tox -e cover 31 | - name: Test with tox 32 | run: tox 33 | 34 | build-and-publish: 35 | name: Build a new package and publish it to pypi if necessary 36 | runs-on: ubuntu-latest 37 | needs: tests 38 | permissions: 39 | id-token: write 40 | 41 | steps: 42 | - uses: actions/checkout@v4 43 | - uses: actions/setup-python@v4 44 | with: 45 | python-version: "3.x" 46 | - name: Install dependencies 47 | run: | 48 | python -m pip install --upgrade pip 49 | pip install build 50 | - name: Build package 51 | run: python -m build 52 | - name: upload windows dists 53 | uses: actions/upload-artifact@v3 54 | with: 55 | name: release-dists 56 | path: dist/ 57 | - name: Publish release distributions to PyPI 58 | # deploy only when a new tag is pushed to github 59 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 60 | uses: pypa/gh-action-pypi-publish@release/v1 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .tox 2 | *.egg-info 3 | /AUTHORS 4 | /ChangeLog 5 | dist/ 6 | doc/build 7 | .coverage 8 | build/ 9 | .venv/ 10 | */__pycache__/ 11 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | Beagle uses the Apache 2.0 license. 2 | 3 | The source is hosted on github https://github.com/beaglecli/beagle 4 | 5 | Please fork the repository and propose pull requests with clean 6 | patches. 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ======================================= 2 | Beagle: Command-line Client for Hound 3 | ======================================= 4 | 5 | Beagle is a command line client for Hound_, the code search tool. 6 | 7 | .. _Hound: https://github.com/etsy/hound 8 | 9 | The source code is available from https://github.com/beaglecli/beagle. 10 | 11 | The documentation is available from http://beagle-hound.readthedocs.io/en/latest/ 12 | -------------------------------------------------------------------------------- /beagle/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beaglecli/beagle/5bc8e07365a185a553a60b1f978e07cc9d69394e/beagle/__init__.py -------------------------------------------------------------------------------- /beagle/app.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 2 | # not use this file except in compliance with the License. You may obtain 3 | # a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 | # License for the specific language governing permissions and limitations 11 | # under the License. 12 | 13 | import logging 14 | import sys 15 | 16 | import pkg_resources 17 | 18 | from cliff.app import App 19 | from cliff.commandmanager import CommandManager 20 | 21 | from beagle import openstack 22 | 23 | 24 | class Beagle(App): 25 | 26 | log = logging.getLogger(__name__) 27 | 28 | def __init__(self): 29 | dist = pkg_resources.get_distribution('beagle') 30 | super(Beagle, self).__init__( 31 | description='Hound command line', 32 | version=dist.version, 33 | command_manager=CommandManager('beagle.cli'), 34 | ) 35 | 36 | def build_option_parser(self, description, version, 37 | argparse_kwargs=None): 38 | parser = super(Beagle, self).build_option_parser( 39 | description, 40 | version, 41 | argparse_kwargs, 42 | ) 43 | parser.add_argument( 44 | '--server-url', '-s', 45 | dest='server_url', 46 | help='the server URL', 47 | default=openstack.DEFAULT_URL, 48 | ) 49 | return parser 50 | 51 | def initialize_app(self, argv): 52 | pass 53 | 54 | 55 | def main(argv=sys.argv[1:]): 56 | myapp = Beagle() 57 | return myapp.run(argv) 58 | 59 | 60 | if __name__ == '__main__': 61 | sys.exit(main(sys.argv[1:])) 62 | -------------------------------------------------------------------------------- /beagle/grep_formatter.py: -------------------------------------------------------------------------------- 1 | # All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Format output like grep 16 | 17 | """ 18 | 19 | from cliff.formatters import base 20 | 21 | 22 | def write_lines_with_offset(fmt, row_d, lines, offset_start, stdout): 23 | for offset, text in enumerate(lines, offset_start): 24 | d = {} 25 | d.update(row_d) 26 | d['Text'] = text 27 | d['Line'] += offset 28 | stdout.write(fmt.format(**d)) 29 | 30 | 31 | class GrepFormatter(base.ListFormatter): 32 | 33 | def add_argument_group(self, parser): 34 | pass 35 | 36 | def emit_list(self, column_names, data, stdout, parsed_args): 37 | fmt = ':'.join( 38 | '{' + c + '}' 39 | for c in column_names 40 | if c not in ('Before', 'After') 41 | ) + '\n' 42 | 43 | for row in data: 44 | row_d = { 45 | c: r 46 | for c, r in zip(column_names, row) 47 | } 48 | 49 | if parsed_args.context_lines: 50 | before = row_d['Before'].machine_readable() 51 | write_lines_with_offset( 52 | fmt, 53 | row_d, 54 | before, 55 | -1 * len(before), 56 | stdout, 57 | ) 58 | 59 | stdout.write(fmt.format(**row_d)) 60 | 61 | if parsed_args.context_lines: 62 | write_lines_with_offset( 63 | fmt, 64 | row_d, 65 | row_d['After'].machine_readable(), 66 | 1, 67 | stdout, 68 | ) 69 | -------------------------------------------------------------------------------- /beagle/hound.py: -------------------------------------------------------------------------------- 1 | # All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Query a hound server 16 | 17 | """ 18 | 19 | import requests 20 | 21 | 22 | def query(server_url, q, 23 | repos='*', 24 | ignore_case=False, 25 | context_lines=0, 26 | files=None): 27 | params = { 28 | 'repos': repos, # which repositories to search 29 | 'i': 'fosho' if ignore_case else 'nope', 30 | 'ctx': context_lines, 31 | } 32 | if files: 33 | params['files'] = files 34 | params['q'] = q 35 | 36 | headers = { 37 | 'Content-Type': 'application/json', 38 | } 39 | url = server_url.rstrip('/') + '/api/v1/search' 40 | response = requests.get(url, params=params, headers=headers) 41 | return response.json()['Results'] 42 | -------------------------------------------------------------------------------- /beagle/openstack.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 2 | # not use this file except in compliance with the License. You may obtain 3 | # a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 | # License for the specific language governing permissions and limitations 11 | # under the License. 12 | 13 | from cliff.formatters import base 14 | 15 | from beagle import grep_formatter 16 | 17 | 18 | DEFAULT_URL = 'http://codesearch.openstack.org' 19 | 20 | 21 | class OSLinkFormatter(base.ListFormatter): 22 | "OpenStack cgit link formatter" 23 | 24 | def add_argument_group(self, parser): 25 | pass 26 | 27 | def emit_list(self, column_names, data, stdout, parsed_args): 28 | fmt = '{base_url}/{repo}'.format( 29 | base_url='https://opendev.org', 30 | repo='{Repository}/src/branch/master/{Filename}#n{Line} : ' 31 | '{Text}\n' 32 | ) 33 | 34 | for row in data: 35 | row_d = { 36 | c: r 37 | for c, r in zip(column_names, row) 38 | } 39 | 40 | if parsed_args.context_lines: 41 | before = row_d['Before'].machine_readable() 42 | grep_formatter.write_lines_with_offset( 43 | fmt, 44 | row_d, 45 | before, 46 | -1 * len(before), 47 | stdout, 48 | ) 49 | 50 | stdout.write(fmt.format(**row_d)) 51 | 52 | if parsed_args.context_lines: 53 | grep_formatter.write_lines_with_offset( 54 | fmt, 55 | row_d, 56 | row_d['After'].machine_readable(), 57 | 1, 58 | stdout, 59 | ) 60 | -------------------------------------------------------------------------------- /beagle/search.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 2 | # not use this file except in compliance with the License. You may obtain 3 | # a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 | # License for the specific language governing permissions and limitations 11 | # under the License. 12 | 13 | import fnmatch 14 | import logging 15 | 16 | from cliff import columns 17 | from cliff import lister 18 | 19 | from beagle import hound 20 | from beagle import openstack 21 | 22 | 23 | class MultiLineText(columns.FormattableColumn): 24 | 25 | def human_readable(self): 26 | return '\n'.join(self._value) 27 | 28 | 29 | class Search(lister.Lister): 30 | """Search for a pattern and show the results. 31 | 32 | """ 33 | 34 | log = logging.getLogger(__name__) 35 | 36 | # Set the command so that when we run through 37 | # python-openstackclient we do not require authentication. 38 | auth_required = False 39 | 40 | def get_parser(self, prog_name): 41 | parser = super().get_parser(prog_name) 42 | parser.add_argument( 43 | '--ignore-comments', 44 | default=False, 45 | action='store_true', 46 | help='ignore comment lines', 47 | ) 48 | parser.add_argument( 49 | '--comment-marker', 50 | default='#', 51 | help='start of a comment line', 52 | ) 53 | parser.add_argument( 54 | '--file', '--file-pattern', 55 | dest='file_pattern', 56 | help='file name pattern', 57 | ) 58 | parser.add_argument( 59 | '--ignore-case', 60 | default=False, 61 | action='store_true', 62 | help='ignore case in search string', 63 | ) 64 | parser.add_argument( 65 | '--repo', 66 | dest='repos', 67 | default=[], 68 | action='append', 69 | help='limit search to named repositories (option can be repeated)', 70 | ) 71 | parser.add_argument( 72 | '--repo-pattern', 73 | dest='repo_pattern', 74 | default='', 75 | help=('glob pattern to match repository names ' 76 | '(filtered on client side)'), 77 | ) 78 | parser.add_argument( 79 | '--context-lines', 80 | default=0, 81 | type=int, 82 | help='number of context lines', 83 | ) 84 | parser.add_argument( 85 | 'query', 86 | help='the text pattern', 87 | ) 88 | return parser 89 | 90 | def _flatten_results(self, results, parsed_args): 91 | interesting_repos = results.items() 92 | if parsed_args.repo_pattern: 93 | def check_repo(repo): 94 | return fnmatch.fnmatch(repo[0], parsed_args.repo_pattern) 95 | interesting_repos = filter(check_repo, results.items()) 96 | 97 | for repo, repo_matches in sorted(interesting_repos): 98 | for repo_match in repo_matches['Matches']: 99 | for file_match in repo_match['Matches']: 100 | if (parsed_args.ignore_comments and 101 | file_match['Line'].lstrip().startswith( 102 | parsed_args.comment_marker)): 103 | continue 104 | if parsed_args.context_lines: 105 | yield (repo, 106 | repo_match['Filename'], 107 | file_match['LineNumber'], 108 | file_match['Line'].strip(), 109 | MultiLineText(file_match['Before']), 110 | MultiLineText(file_match['After'])) 111 | else: 112 | yield (repo, 113 | repo_match['Filename'], 114 | file_match['LineNumber'], 115 | file_match['Line'].strip()) 116 | 117 | def take_action(self, parsed_args): 118 | if parsed_args.repos: 119 | repos = ','.join(n.strip() for n in parsed_args.repos) 120 | else: 121 | repos = '*' 122 | 123 | try: 124 | server_url = self.app.options.server_url 125 | except AttributeError: 126 | # running via the openstack CLI 127 | server_url = openstack.DEFAULT_URL 128 | 129 | results = hound.query( 130 | server_url=server_url, 131 | q=parsed_args.query, 132 | files=parsed_args.file_pattern, 133 | ignore_case=parsed_args.ignore_case, 134 | repos=repos, 135 | context_lines=parsed_args.context_lines, 136 | ) 137 | columns = ('Repository', 'Filename', 'Line', 'Text') 138 | if parsed_args.context_lines: 139 | columns = columns + ('Before', 'After') 140 | return ( 141 | columns, 142 | self._flatten_results(results, parsed_args), 143 | ) 144 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | setuptools 2 | Sphinx 3 | cliff 4 | -------------------------------------------------------------------------------- /doc/source/cli/index.rst: -------------------------------------------------------------------------------- 1 | ================================ 2 | Command line interface reference 3 | ================================ 4 | 5 | .. autoprogram-cliff:: beagle.cli 6 | -------------------------------------------------------------------------------- /doc/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 11 | # implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import os 16 | import sys 17 | 18 | sys.path.insert(0, os.path.abspath('../..')) 19 | # -- General configuration ---------------------------------------------------- 20 | 21 | # Add any Sphinx extension module names here, as strings. They can be 22 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 23 | extensions = [ 24 | 'sphinx.ext.autodoc', 25 | 'cliff.sphinxext', 26 | #'sphinx.ext.intersphinx', 27 | ] 28 | 29 | autoprogram_cliff_application = 'beagle' 30 | autoprogram_cliff_ignored = ['--help'] 31 | 32 | # autodoc generation is a bit aggressive and a nuisance when doing heavy 33 | # text edit cycles. 34 | # execute "export SPHINX_DEBUG=1" in your terminal to disable 35 | 36 | # The suffix of source filenames. 37 | source_suffix = '.rst' 38 | 39 | # The master toctree document. 40 | master_doc = 'index' 41 | 42 | # General information about the project. 43 | project = u'beagle' 44 | copyright = u'2018, Doug Hellmann' 45 | 46 | # If true, '()' will be appended to :func: etc. cross-reference text. 47 | add_function_parentheses = True 48 | 49 | # If true, the current module name will be prepended to all description 50 | # unit titles (such as .. function::). 51 | add_module_names = True 52 | 53 | # The name of the Pygments (syntax highlighting) style to use. 54 | pygments_style = 'sphinx' 55 | 56 | # -- Options for HTML output -------------------------------------------------- 57 | 58 | # The theme to use for HTML and HTML Help pages. Major themes that come with 59 | # Sphinx are currently 'default' and 'sphinxdoc'. 60 | # html_theme_path = ["."] 61 | # html_theme = '_theme' 62 | # html_static_path = ['static'] 63 | 64 | html_last_updated_fmt = '%Y-%m-%d %H:%M' 65 | 66 | # Output file base name for HTML help builder. 67 | htmlhelp_basename = '%sdoc' % project 68 | 69 | # Grouping the document tree into LaTeX files. List of tuples 70 | # (source start file, target name, title, author, documentclass 71 | # [howto/manual]). 72 | latex_documents = [ 73 | ('index', 74 | '%s.tex' % project, 75 | u'%s Documentation' % project, 76 | u'Doug Hellmann', 'manual'), 77 | ] 78 | 79 | # Example configuration for intersphinx: refer to the Python standard library. 80 | #intersphinx_mapping = {'http://docs.python.org/': None} 81 | -------------------------------------------------------------------------------- /doc/source/history.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../ChangeLog 2 | -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. whereto documentation master file, created by 2 | sphinx-quickstart on Tue Jul 9 22:26:36 2013. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | ======================================= 7 | Beagle: Command-line Client for Hound 8 | ======================================= 9 | 10 | Beagle is a command line client for Hound_, the code search tool. 11 | 12 | .. _Hound: https://github.com/etsy/hound 13 | 14 | :Source: https://github.com/beaglecli/beagle 15 | :Bugs: https://github.com/beaglecli/beagle/issues 16 | 17 | .. toctree:: 18 | :maxdepth: 2 19 | 20 | install/index 21 | cli/index 22 | user/index 23 | history 24 | 25 | Indices and tables 26 | ================== 27 | 28 | * :ref:`genindex` 29 | * :ref:`modindex` 30 | * :ref:`search` 31 | -------------------------------------------------------------------------------- /doc/source/install/index.rst: -------------------------------------------------------------------------------- 1 | ============================ 2 | beagle installation guide 3 | ============================ 4 | 5 | The beagle package should be installed via ``pip``: 6 | 7 | .. code-block:: console 8 | 9 | $ pip install beagle 10 | -------------------------------------------------------------------------------- /doc/source/user/index.rst: -------------------------------------------------------------------------------- 1 | =========== 2 | Users guide 3 | =========== 4 | 5 | Examples 6 | ======== 7 | 8 | To find requirements or constraints specifications for ``cliff``: 9 | 10 | .. code-block:: console 11 | 12 | $ beagle search --file '(.*requirement.*|.*constraint.*|setup.cfg|tox.ini)' 'cliff[><=]' 13 | 14 | +-----------------------+------------------------------------------------------------+------+------------------------------------+ 15 | | Repository | Filename | Line | Text | 16 | +-----------------------+------------------------------------------------------------+------+------------------------------------+ 17 | | group-based-policy | test-requirements.txt | 20 | cliff>=2.3.0 # Apache-2.0 | 18 | | kolla-kubernetes | requirements.txt | 6 | cliff>=2.8.0 # Apache-2.0 | 19 | | networking-bigswitch | test-requirements.txt | 8 | cliff>=1.7.0 # Apache-2.0 | 20 | | networking-brocade | test-requirements.txt | 6 | cliff>=1.14.0 # Apache-2.0 | 21 | | networking-mlnx | test-requirements.txt | 6 | cliff>=1.15.0 # Apache-2.0 | 22 | | networking-plumgrid | test-requirements.txt | 3 | cliff>=2.2.0 # Apache-2.0 | 23 | | osops-tools-contrib | ansible_requirements.txt | 5 | cliff==2.2.0 | 24 | | paunch | requirements.txt | 7 | cliff>=2.6.0 # Apache-2.0 | 25 | | rally | upper-constraints.txt | 68 | cliff===2.11.0 | 26 | | requirements | global-requirements.txt | 21 | cliff>=2.8.0,!=2.9.0 # Apache-2.0 | 27 | | requirements | openstack_requirements/tests/files/gr-base.txt | 9 | cliff>=1.4 | 28 | | requirements | openstack_requirements/tests/files/upper-constraints.txt | 192 | cliff===2.4.0 | 29 | | requirements | upper-constraints.txt | 216 | cliff===2.11.0 | 30 | | rpm-packaging | requirements.txt | 21 | cliff>=2.8.0,!=2.9.0 # Apache-2.0 | 31 | +-----------------------+------------------------------------------------------------+------+------------------------------------+ 32 | 33 | To show the 5 lines before and after the location of the class 34 | definition for ``ConfigOpts`` in ``oslo.config`` using the ``grep`` 35 | output formatter. 36 | 37 | .. code-block:: console 38 | 39 | $ beagle search -f grep --context-lines 5 --repo openstack/oslo.config 'class ConfigOpts' 40 | openstack/oslo.config:doc/source/reference/configuration-files.rst:5:The config manager has two CLI options defined by default, ``--config-file`` 41 | openstack/oslo.config:doc/source/reference/configuration-files.rst:6:and ``--config-dir``: 42 | openstack/oslo.config:doc/source/reference/configuration-files.rst:7: 43 | openstack/oslo.config:doc/source/reference/configuration-files.rst:8:.. code-block:: python 44 | openstack/oslo.config:doc/source/reference/configuration-files.rst:9: 45 | openstack/oslo.config:doc/source/reference/configuration-files.rst:10:class ConfigOpts(object): 46 | openstack/oslo.config:doc/source/reference/configuration-files.rst:11: 47 | openstack/oslo.config:doc/source/reference/configuration-files.rst:12: def __call__(self, ...): 48 | openstack/oslo.config:doc/source/reference/configuration-files.rst:13: 49 | openstack/oslo.config:doc/source/reference/configuration-files.rst:14: opts = [ 50 | openstack/oslo.config:doc/source/reference/configuration-files.rst:15: MultiStrOpt('config-file', 51 | openstack/oslo.config:oslo_config/cfg.py:1920: def print_usage(self, file=None): 52 | openstack/oslo.config:oslo_config/cfg.py:1921: self.initialize_parser_arguments() 53 | openstack/oslo.config:oslo_config/cfg.py:1922: super(_CachedArgumentParser, self).print_usage(file) 54 | openstack/oslo.config:oslo_config/cfg.py:1923: 55 | openstack/oslo.config:oslo_config/cfg.py:1924: 56 | openstack/oslo.config:oslo_config/cfg.py:1925:class ConfigOpts(abc.Mapping): 57 | openstack/oslo.config:oslo_config/cfg.py:1926: 58 | openstack/oslo.config:oslo_config/cfg.py:1927: """Config options which may be set on the command line or in config files. 59 | openstack/oslo.config:oslo_config/cfg.py:1928: 60 | openstack/oslo.config:oslo_config/cfg.py:1929: ConfigOpts is a configuration option manager with APIs for registering 61 | openstack/oslo.config:oslo_config/cfg.py:1930: option schemas, grouping options, parsing option values and retrieving 62 | 63 | 64 | To produce links to the source on the OpenStack git server, use the 65 | ``link`` formatter: 66 | 67 | .. code-block:: console 68 | 69 | $ beagle --debug search -f link --repo openstack/oslo.config 'class ConfigOpts' 70 | https://opendev.org/openstack/oslo.config/src/branch/master/doc/source/reference/configuration-files.rst#n10 : class ConfigOpts(object): 71 | https://opendev.org/openstack/oslo.config/src/branch/master/oslo_config/cfg.py#n1925 : class ConfigOpts(abc.Mapping): 72 | 73 | To filter repositories in search results, use the ``--repo-pattern`` option. 74 | 75 | Example to show which openstack oslo project call the ``ssl.wrap_socket`` 76 | function: 77 | 78 | .. code-block:: console 79 | 80 | $ beagle search --ignore-comments -f link --repo-pattern "openstack/oslo.*" 'ssl.wrap_socket' 81 | https://opendev.org/openstack/oslo.service/src/branch/master/oslo_service/sslutils.py#n104 : return ssl.wrap_socket(sock, **ssl_kwargs) # nosec 82 | https://opendev.org/openstack/oslo.service/src/branch/master/oslo_service/tests/test_sslutils.py#n81 : @mock.patch("ssl.wrap_socket") 83 | 84 | Same research only in the whole openstack projects 85 | (will ignore starlingx, etc): 86 | 87 | .. code-block:: console 88 | 89 | $ beagle search --ignore-comments -f link --repo-pattern "openstack/*" 'ssl.wrap_socket' 90 | https://opendev.org/openstack/glance/src/branch/master/glance/common/client.py#n124 : ssl.wrap_socket(), which forces SSL to check server certificate against 91 | https://opendev.org/openstack/glance/src/branch/master/glance/common/client.py#n133 : self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, 92 | https://opendev.org/openstack/glance/src/branch/master/glance/common/client.py#n136 : self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, 93 | https://opendev.org/openstack/heat/src/branch/master/heat/common/wsgi.py#n239 : ssl.wrap_socket if conf specifies cert_file 94 | https://opendev.org/openstack/heat/src/branch/master/heat/common/wsgi.py#n414 : self.sock = ssl.wrap_socket(self._sock, 95 | 96 | OpenStack Client Integration 97 | ============================ 98 | 99 | When the ``python-openstackclient`` package and ``beagle`` are both 100 | installed, it is possible to search the OpenStack source code directly 101 | from the ``openstack`` command line tool. 102 | 103 | .. code-block:: console 104 | 105 | $ openstack code search --file '(.*requirement.*|.*constraint.*|setup.cfg|tox.ini)' 'cliff[><=]' 106 | 107 | +-----------------------+------------------------------------------------------------+------+------------------------------------+ 108 | | Repository | Filename | Line | Text | 109 | +-----------------------+------------------------------------------------------------+------+------------------------------------+ 110 | | group-based-policy | test-requirements.txt | 20 | cliff>=2.3.0 # Apache-2.0 | 111 | | kolla-kubernetes | requirements.txt | 6 | cliff>=2.8.0 # Apache-2.0 | 112 | | networking-bigswitch | test-requirements.txt | 8 | cliff>=1.7.0 # Apache-2.0 | 113 | | networking-brocade | test-requirements.txt | 6 | cliff>=1.14.0 # Apache-2.0 | 114 | | networking-mlnx | test-requirements.txt | 6 | cliff>=1.15.0 # Apache-2.0 | 115 | | networking-plumgrid | test-requirements.txt | 3 | cliff>=2.2.0 # Apache-2.0 | 116 | | osops-tools-contrib | ansible_requirements.txt | 5 | cliff==2.2.0 | 117 | | paunch | requirements.txt | 7 | cliff>=2.6.0 # Apache-2.0 | 118 | | rally | upper-constraints.txt | 68 | cliff===2.11.0 | 119 | | requirements | global-requirements.txt | 21 | cliff>=2.8.0,!=2.9.0 # Apache-2.0 | 120 | | requirements | openstack_requirements/tests/files/gr-base.txt | 9 | cliff>=1.4 | 121 | | requirements | openstack_requirements/tests/files/upper-constraints.txt | 192 | cliff===2.4.0 | 122 | | requirements | upper-constraints.txt | 216 | cliff===2.11.0 | 123 | | rpm-packaging | requirements.txt | 21 | cliff>=2.8.0,!=2.9.0 # Apache-2.0 | 124 | +-----------------------+------------------------------------------------------------+------+------------------------------------+ 125 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pbr>=2.0 2 | cliff>=2.11.0 3 | requests>=2.18.4 4 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = beagle 3 | summary = Command line client for Hound 4 | description-file = 5 | README.rst 6 | author = Doug Hellmann 7 | author-email = doug@doughellmann.com 8 | home-page = https://github.com/beaglecli/beagle/ 9 | python-requires = >=3.9 10 | classifier = 11 | Intended Audience :: Developers 12 | Intended Audience :: Information Technology 13 | Intended Audience :: System Administrators 14 | License :: OSI Approved :: Apache Software License 15 | Programming Language :: Python 16 | Programming Language :: Python :: 3 17 | Programming Language :: Python :: 3.9 18 | Programming Language :: Python :: 3.10 19 | Programming Language :: Python :: 3.11 20 | Programming Language :: Python :: 3.12 21 | install_requires = 22 | setuptools 23 | 24 | [files] 25 | packages = 26 | beagle 27 | 28 | [extras] 29 | test = 30 | coverage 31 | pytest 32 | pytest-cov 33 | testtools 34 | fixtures 35 | flake8 36 | 37 | [entry_points] 38 | console_scripts = 39 | beagle = beagle.app:main 40 | beagle.cli = 41 | search = beagle.search:Search 42 | cliff.formatter.list = 43 | grep = beagle.grep_formatter:GrepFormatter 44 | link = beagle.openstack:OSLinkFormatter 45 | openstack.cli = 46 | code_search = beagle.search:Search 47 | 48 | [build_sphinx] 49 | all-files = 1 50 | warning-is-error = 1 51 | source-dir = doc/source 52 | build-dir = doc/build 53 | 54 | [upload_sphinx] 55 | upload-dir = doc/build/html 56 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Hewlett-Packard Development Company, L.P. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | # implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | import setuptools 17 | 18 | # In python < 2.7.4, a lazy loading of package `pbr` will break 19 | # setuptools if some other modules registered functions in `atexit`. 20 | # solution from: http://bugs.python.org/issue15881#msg170215 21 | try: 22 | import multiprocessing # noqa 23 | except ImportError: 24 | pass 25 | 26 | setuptools.setup( 27 | setup_requires=['pbr'], 28 | pbr=True) 29 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | minversion = 3.2.0 3 | envlist = py38,pep8 4 | 5 | [testenv] 6 | usedevelop = True 7 | setenv = 8 | VIRTUAL_ENV={envdir} 9 | deps = .[test] 10 | 11 | [testenv:venv] 12 | commands = {posargs} 13 | 14 | [testenv:pep8] 15 | commands = flake8 {posargs} 16 | 17 | [testenv:cover] 18 | ignore_error=true 19 | ignore_outcome=true 20 | commands = 21 | coverage erase 22 | pytest -v \ 23 | --cov=beagle \ 24 | --cov-report term-missing \ 25 | --cov-config {toxinidir}/.coveragerc 26 | 27 | [testenv:docs] 28 | deps = -r{toxinidir}/doc/requirements.txt 29 | commands = 30 | python setup.py sdist 31 | sphinx-build -a -E -W -b html doc/source doc/build/html;; 32 | 33 | [flake8] 34 | # E123, E125 skipped as they are invalid PEP-8. 35 | # W504 skipped to give priority to W503 36 | # W503 = Line breaks should occur after the binary operator 37 | show-source = True 38 | ignore = E123,E125,W504 39 | builtins = _ 40 | exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build 41 | 42 | [travis] 43 | python = 3.6: py36, pep8 44 | --------------------------------------------------------------------------------