bugout-locust


Namebugout-locust JSON
Version 0.2.7 PyPI version JSON
download
home_pagehttps://github.com/simiotics/locust
SummaryLocust: Track changes to Python code across git refs
upload_time2021-02-23 17:52:47
maintainer
docs_urlNone
authorNeeraj Kashyap
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # <img src="./img/locust-black.svg" height="20" width="20"/> locust

"It's `git diff --stat` on steroids!" - [@scottmilliken](https://gitlab.com/scottmilliken)

## What is Locust?

Locust helps you reason about your code base as it evolves over time.

Locust provides a semantic layer on top of `git diff`. It emits metadata describing
[AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree)-level changes to your
code base between git revisions.

This metadata is useful to both humans and computers. For example:

1. (Humans) Locust can generate
   [much more humane summaries of changes](https://github.com/bugout-dev/locust/pull/34) than the
   standard git diff.

2. (Computers) [Bugout.dev](https://alpha.bugout.dev) uses Locust metadata to learn high level
   abstractions about code.

## Installation

Locust requires Python3 (specifically, it was written in Python3.8).

### Install from PyPI

```bash
pip install -U setuptools
pip install bugout-locust
```

### Install from source

Clone this repository and run from the project root:

```bash
python setup.py install
```

### Docker

You can also use the Locust docker image:

```bash
docker pull bugout/locust
```

## Usage

### CLI

Locust is a command line tool, and you can invoke it as:

```bash
locust 22dd7fd6adf392bb29d13d10f10e7dbb1d97bfce c9813bd5871a9919551ccd917712135c40367c5c --format yaml
```

This produces the following output:

```yaml
locust:
  - file: locust/ci_helpers/github.py
    changes:
      - name: generate_argument_parser
        type: function
        line: 11
        changed_lines: 9
        total_lines: 9
        children: []
      - name: helper_push
        type: function
        line: 22
        changed_lines: 13
        total_lines: 13
        children: []
      - name: helper_pr
        type: function
        line: 37
        changed_lines: 14
        total_lines: 14
        children: []
      - name: main
        type: function
        line: 53
        changed_lines: 29
        total_lines: 29
        children: []
refs:
  initial: 22dd7fd
  terminal: c9813bd
```

### Language plugins

To use Locust to process a code base containing Python (>3.5) and Javascript, use the Javascript
plugin (written in Node 14).

If you are running Locust from the root of this project, you would do this as follows:

```
locust -r <path to repo> <initial revision> <terminal revision> --plugins "node js/out/index.js"
```

A Locust language plugin is simply a program that you can invoke from the shell (like
`node js/out/index.js`) which takes two arguments:

- `-i` - an input file containing a `locust.git.RunResponse` object

- `-o` - path to an output file into which it writes a list of tuples consisting of
  `locust.git.PatchInfo` objects and their corresponding list of `locust.parse.RawDefinition`
  objects.

The [Javascript plugin](./js/) provides a rubric for how to build your own plugin.

You can add custom plugins to a Locust invocation like this:

```
locust -r <path to repo> <initial revision> <terminal revision> \
  --plugins "node js/out/index.js" "<custom plugin invocation 1>" "<custom plugin invocation 2>"
```

### CI/CD

Locust is easy to use in CI/CD pipelines:

- [Locust GitHub Action](https://github.com/simiotics/locust-action)

### Bugout App integration

You can use Locust with our [Bugout GitHub Bot](https://github.com/bugout-dev/github-demo).
Locust extension will work after you push `./github/workflows/locust.yml` file in `main` branch:

```yaml
name: Locust summary
on: [pull_request_target]
jobs:
  build:
    runs-on: ubuntu-20.04
    steps:
      - name: PR head repo
        id: head_repo_name
        run: |
          HEAD_REPO_NAME=$(jq -r '.pull_request.head.repo.full_name' "$GITHUB_EVENT_PATH")
          echo "PR head repo: $HEAD_REPO_NAME"
          echo "::set-output name=repo::$HEAD_REPO_NAME"
      - name: Checkout git repo
        uses: actions/checkout@v2
        with:
          repository: ${{ steps.head_repo_name.outputs.repo }}
          fetch-depth: 0
      - name: Install python
        uses: actions/setup-python@v2
        with:
          python-version: "3.8"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip setuptools
          pip install bugout-locust
      - name: Generate and send Locust summary
        env:
          BUGOUT_SECRET: ${{ secrets.BUGOUT_SECRET }}
        run: |
          locust.github publish
```

BUGOUT_SECRET should be setted up in repository/organization secrets. Value you can take from Bugout Account token page. Also `BUGOUT_API_URL: ${{ secrets.BUGOUT_API_URL }}` could be specified if you want to setup your personal server for processing locust summaries.

### Docker

To run Locust using docker:

```bash
docker run -v $ABSOLUTE_PATH_TO_GIT_REPO:/usr/src/app bugout/locust -r /usr/src/app \
    $INITIAL_REVISION \
    $TERMINAL_REVISION \
    --format yaml
```

## Output formats

Locust can produce output in many formats. The currently supported formats are:

1. JSON (`--format json`)

2. YAML (`--format yaml`)

3. HTML (`--format html`)

4. GitHub-flavored HTML, meant to be used with GitHub styles (`--format html-github`)

## Contributing

### Running tests

Make sure to clone [simiotics/locust-test-cases](https://github.com/simiotics/locust-test-cases)
repo to your machine.

Run:

```bash
git -c <path to locust-test-cases repo> fetch origin
```

Then, from the root of this repo:

```bash
LOCUST_TESTCASES_DIR=<path to locust-test-cases repo> ./test.sh
```

## Similar projects

### Kythe

[Kythe](https://kythe.io) is a Google open source project. It grew out of the need to semantically
link different parts of Google's code base.

The goals of Locust are different from those of Kythe. Locust is specifically about generating
metadata describing _changes_ to code.

Kythe on GitHub: https://github.com/kythe/kythe



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/simiotics/locust",
    "name": "bugout-locust",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Neeraj Kashyap",
    "author_email": "neeraj@bugout.dev",
    "download_url": "https://files.pythonhosted.org/packages/41/6f/b7ce71449525f42df7f20af47d016ec7c3ec13ef53bed40c2e72e1368f42/bugout-locust-0.2.7.tar.gz",
    "platform": "",
    "description": "# <img src=\"./img/locust-black.svg\" height=\"20\" width=\"20\"/> locust\n\n\"It's `git diff --stat` on steroids!\" - [@scottmilliken](https://gitlab.com/scottmilliken)\n\n## What is Locust?\n\nLocust helps you reason about your code base as it evolves over time.\n\nLocust provides a semantic layer on top of `git diff`. It emits metadata describing\n[AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree)-level changes to your\ncode base between git revisions.\n\nThis metadata is useful to both humans and computers. For example:\n\n1. (Humans) Locust can generate\n   [much more humane summaries of changes](https://github.com/bugout-dev/locust/pull/34) than the\n   standard git diff.\n\n2. (Computers) [Bugout.dev](https://alpha.bugout.dev) uses Locust metadata to learn high level\n   abstractions about code.\n\n## Installation\n\nLocust requires Python3 (specifically, it was written in Python3.8).\n\n### Install from PyPI\n\n```bash\npip install -U setuptools\npip install bugout-locust\n```\n\n### Install from source\n\nClone this repository and run from the project root:\n\n```bash\npython setup.py install\n```\n\n### Docker\n\nYou can also use the Locust docker image:\n\n```bash\ndocker pull bugout/locust\n```\n\n## Usage\n\n### CLI\n\nLocust is a command line tool, and you can invoke it as:\n\n```bash\nlocust 22dd7fd6adf392bb29d13d10f10e7dbb1d97bfce c9813bd5871a9919551ccd917712135c40367c5c --format yaml\n```\n\nThis produces the following output:\n\n```yaml\nlocust:\n  - file: locust/ci_helpers/github.py\n    changes:\n      - name: generate_argument_parser\n        type: function\n        line: 11\n        changed_lines: 9\n        total_lines: 9\n        children: []\n      - name: helper_push\n        type: function\n        line: 22\n        changed_lines: 13\n        total_lines: 13\n        children: []\n      - name: helper_pr\n        type: function\n        line: 37\n        changed_lines: 14\n        total_lines: 14\n        children: []\n      - name: main\n        type: function\n        line: 53\n        changed_lines: 29\n        total_lines: 29\n        children: []\nrefs:\n  initial: 22dd7fd\n  terminal: c9813bd\n```\n\n### Language plugins\n\nTo use Locust to process a code base containing Python (>3.5) and Javascript, use the Javascript\nplugin (written in Node 14).\n\nIf you are running Locust from the root of this project, you would do this as follows:\n\n```\nlocust -r <path to repo> <initial revision> <terminal revision> --plugins \"node js/out/index.js\"\n```\n\nA Locust language plugin is simply a program that you can invoke from the shell (like\n`node js/out/index.js`) which takes two arguments:\n\n- `-i` - an input file containing a `locust.git.RunResponse` object\n\n- `-o` - path to an output file into which it writes a list of tuples consisting of\n  `locust.git.PatchInfo` objects and their corresponding list of `locust.parse.RawDefinition`\n  objects.\n\nThe [Javascript plugin](./js/) provides a rubric for how to build your own plugin.\n\nYou can add custom plugins to a Locust invocation like this:\n\n```\nlocust -r <path to repo> <initial revision> <terminal revision> \\\n  --plugins \"node js/out/index.js\" \"<custom plugin invocation 1>\" \"<custom plugin invocation 2>\"\n```\n\n### CI/CD\n\nLocust is easy to use in CI/CD pipelines:\n\n- [Locust GitHub Action](https://github.com/simiotics/locust-action)\n\n### Bugout App integration\n\nYou can use Locust with our [Bugout GitHub Bot](https://github.com/bugout-dev/github-demo).\nLocust extension will work after you push `./github/workflows/locust.yml` file in `main` branch:\n\n```yaml\nname: Locust summary\non: [pull_request_target]\njobs:\n  build:\n    runs-on: ubuntu-20.04\n    steps:\n      - name: PR head repo\n        id: head_repo_name\n        run: |\n          HEAD_REPO_NAME=$(jq -r '.pull_request.head.repo.full_name' \"$GITHUB_EVENT_PATH\")\n          echo \"PR head repo: $HEAD_REPO_NAME\"\n          echo \"::set-output name=repo::$HEAD_REPO_NAME\"\n      - name: Checkout git repo\n        uses: actions/checkout@v2\n        with:\n          repository: ${{ steps.head_repo_name.outputs.repo }}\n          fetch-depth: 0\n      - name: Install python\n        uses: actions/setup-python@v2\n        with:\n          python-version: \"3.8\"\n      - name: Install dependencies\n        run: |\n          python -m pip install --upgrade pip setuptools\n          pip install bugout-locust\n      - name: Generate and send Locust summary\n        env:\n          BUGOUT_SECRET: ${{ secrets.BUGOUT_SECRET }}\n        run: |\n          locust.github publish\n```\n\nBUGOUT_SECRET should be setted up in repository/organization secrets. Value you can take from Bugout Account token page. Also `BUGOUT_API_URL: ${{ secrets.BUGOUT_API_URL }}` could be specified if you want to setup your personal server for processing locust summaries.\n\n### Docker\n\nTo run Locust using docker:\n\n```bash\ndocker run -v $ABSOLUTE_PATH_TO_GIT_REPO:/usr/src/app bugout/locust -r /usr/src/app \\\n    $INITIAL_REVISION \\\n    $TERMINAL_REVISION \\\n    --format yaml\n```\n\n## Output formats\n\nLocust can produce output in many formats. The currently supported formats are:\n\n1. JSON (`--format json`)\n\n2. YAML (`--format yaml`)\n\n3. HTML (`--format html`)\n\n4. GitHub-flavored HTML, meant to be used with GitHub styles (`--format html-github`)\n\n## Contributing\n\n### Running tests\n\nMake sure to clone [simiotics/locust-test-cases](https://github.com/simiotics/locust-test-cases)\nrepo to your machine.\n\nRun:\n\n```bash\ngit -c <path to locust-test-cases repo> fetch origin\n```\n\nThen, from the root of this repo:\n\n```bash\nLOCUST_TESTCASES_DIR=<path to locust-test-cases repo> ./test.sh\n```\n\n## Similar projects\n\n### Kythe\n\n[Kythe](https://kythe.io) is a Google open source project. It grew out of the need to semantically\nlink different parts of Google's code base.\n\nThe goals of Locust are different from those of Kythe. Locust is specifically about generating\nmetadata describing _changes_ to code.\n\nKythe on GitHub: https://github.com/kythe/kythe\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Locust: Track changes to Python code across git refs",
    "version": "0.2.7",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "0af153e51d00756c756362ba914d633e",
                "sha256": "6b760c9e4f1f7aa159a479776c9b6216981015c5720959b88a4a381be7500215"
            },
            "downloads": -1,
            "filename": "bugout_locust-0.2.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0af153e51d00756c756362ba914d633e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 26074,
            "upload_time": "2021-02-23T17:52:46",
            "upload_time_iso_8601": "2021-02-23T17:52:46.669367Z",
            "url": "https://files.pythonhosted.org/packages/14/78/3281765ca7d66a056072a4c598ecddc0674026aefc2528b4bc0b12a248c5/bugout_locust-0.2.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "b662be28e8e68ccb9bf7dd25d66cb75c",
                "sha256": "656b403d8eef665136d306f57621c73bd0371ede6fa0957734747174fa0c1642"
            },
            "downloads": -1,
            "filename": "bugout-locust-0.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "b662be28e8e68ccb9bf7dd25d66cb75c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 20597,
            "upload_time": "2021-02-23T17:52:47",
            "upload_time_iso_8601": "2021-02-23T17:52:47.968056Z",
            "url": "https://files.pythonhosted.org/packages/41/6f/b7ce71449525f42df7f20af47d016ec7c3ec13ef53bed40c2e72e1368f42/bugout-locust-0.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-02-23 17:52:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "simiotics",
    "error": "Could not fetch GitHub repository",
    "lcname": "bugout-locust"
}
        
Elapsed time: 0.24741s