Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: github action lint #24

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ end
define hook-run
refresh
end

34 changes: 34 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pre-commit
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

- name: Pre-commit checks
run: |
pre-commit run --all-files
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
repos:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-json
- id: check-added-large-files
# - id: check-yaml
- id: debug-statements
# - id: name-tests-test
- id: double-quote-string-fixer
- id: requirements-txt-fixer
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
args: [--max-line-length=131]
additional_dependencies:
- flake8-typing-imports==1.12.0
- flake8-bugbear
- flake8-comprehensions
- flake8-simplify
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.6.0
hooks:
- id: autopep8
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.6.0
hooks:
- id: reorder-python-imports
args: [--py37-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.2.1
hooks:
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.0
hooks:
- id: setup-cfg-fmt
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributing

Contributions welcome.

## Lint

This project uses [pre-commit](https://pre-commit.com/).

```bash
python3 -m pip install -U pre-commit
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pvetere FYI you'll want to run through these steps on your local machine


pre-commit install
```

```bash
pre-commit run --all-files
```
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a CLI tool that, given a WIT specification, will correctly interpret and

When no WIT file is provided, the arguments will be interpreted as basic types the same way `wasmtime --invoke` works

To facilitate expression of complex types, this tool accepts JSON notation as input, and produces JSON notation as output. For more information, please see the [examples](#examples) section below.
To facilitate expression of complex types, this tool accepts JSON notation as input, and produces JSON notation as output. For more information, please see the [examples](#examples) section below.

# Usage
You may use this tool locally, or via a [Docker](#building-and-running-the-docker-image) container.
Expand Down Expand Up @@ -36,7 +36,7 @@ Specifies 0 or more arguments to pass into the Wasm function. Complex arguments
*Options:*
`-b, --batch BATCHFILE`
* Specifies a path to a file containing one or more JSON-formatted inputs to use in place of in-line arguments (see [Batch File Format](batch-file-format), below).

`-d, --debug`
* Starts the Wasm program in GDB. See [Debugging](debugging), below.

Expand Down Expand Up @@ -108,7 +108,7 @@ Specifies 0 or more arguments to pass into the Wasm function. Complex arguments

`-c, --cache CACHEDIR`
* Specifies a directory to use for the binding cache. To help save time on repeated runs, `writ` can cache its generated bindings in a directory and re-use them again later. You can specify the location of this directory with this option.

`-e, --expect EXPECTSTR`
* Specifies an expected result to JSON form. If not matched, the program exits with the error code 2. May not be used with -b.

Expand Down Expand Up @@ -162,11 +162,11 @@ Each entry in the outer-most list represents the arguments for a single call int

When a batch file is in use, output will be formatted in a similar way, with each outer list entry corresponding to one record of input.

# Examples
# Examples
All of the examples below apply equally to both `writ` and `writ-docker`.

## Simple numeric arguments
This example passes simple numerics as arguments. Due to the simplicity of the
This example passes simple numerics as arguments. Due to the simplicity of the
parameter types (all numeric), a WIT file is optional.
```sh
bin/writ --wit examples/int/power.wit examples/int/power.wasm power-of 2 3
Expand Down Expand Up @@ -253,7 +253,7 @@ Here, we'll test splitting some strings. We use the `--batch` option for this.
e
```sh
cat<<EOF > /tmp/writ-test.json
[
[
["first_string_to_test", "_"],
["second-string-to-test", "_"],
["third-string_to__test", "_"],
Expand Down Expand Up @@ -323,4 +323,3 @@ For this, you will need [Docker](https://docs.docker.com/engine/install/) instal
```bash
docker build -f docker/Dockerfile -t ghcr.io/singlestore-labs/writ .
```

1 change: 0 additions & 1 deletion bin/writ
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ if [ ${PY_SUBVER} -lt 9 ] ; then
fi

exec ${PYTHON3} ${MYDIR}/../src/writ "$@"

11 changes: 5 additions & 6 deletions bin/writ-docker
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Arguments:
WASMFILE Specifies the path to the Wasm module (.wasm file)
FUNCNAME Specifies the Wasm function name to run
ARG... Specifies 0 or more arguments to pass into the Wasm function.
Complex arguments may be expressed in JSON format. May not be
Complex arguments may be expressed in JSON format. May not be
used with the -b option

Options:
-a, --debug-args <ARGS> Passes the given string as additional arguments into
GDB (only valid with -d)
-b, --batch <BATCHFILE> Specifies a path to a file containing one or more
JSON-formatted inputs to use in place of in-line
-b, --batch <BATCHFILE> Specifies a path to a file containing one or more
JSON-formatted inputs to use in place of in-line
arguments (see "Batch File Format", below)
-d, --debug Runs the Wasm module in GDB
-e, --expect <EXPECTSTR> Specifies an expected result in JSON form. If not
Expand All @@ -37,9 +37,9 @@ Options:

Batch File Format:
A JSON-formatted file may be passed in lieu of in-line arguments. This file
must consist of either a list of lists or a list of single values. For
must consist of either a list of lists or a list of single values. For
example, either of the following forms will work:

[ [
"John Lennon", OR [ "John Lennon", "Guitar", 1940 ],
"Paul McCartney", [ "Paul McCartney", "Bass", 1942 ],
Expand Down Expand Up @@ -205,4 +205,3 @@ fi
"/wasm-dir/${WASM_NAME}" \
"${WASM_FUNC}" \
"$@"

1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ RUN cd wasmtime-py && python3 download-wasmtime.py && python3 setup.py install &
RUN cd writ && python3 setup.py install

ENTRYPOINT ["/writ/bin/writ"]

1 change: 0 additions & 1 deletion docker/docker-run-gdb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ eval `resize`

cd /writ
gdb "$@"

6 changes: 3 additions & 3 deletions examples/expected/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
extern "C"
{
#endif

#include <stdint.h>
#include <stdbool.h>

typedef struct {
char *ptr;
size_t len;
} power_string_t;

void power_string_set(power_string_t *ret, const char *s);
void power_string_dup(power_string_t *ret, const char *s);
void power_string_free(power_string_t *ret);
Expand Down
2 changes: 1 addition & 1 deletion examples/float/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern "C"
{
#endif

#include <stdint.h>
#include <stdbool.h>
float power_power_of(float a, float b);
Expand Down
1 change: 0 additions & 1 deletion examples/hilbert/hilbert.wit
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ hilbert-encode: func(input: hilbert-input, ) -> list<hilbert-output>
wit-source-get: func() -> string

wit-source-print: func()

1 change: 0 additions & 1 deletion examples/int/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ int32_t power_power_of(int32_t base, int32_t exp) {
}
return res;
}

2 changes: 1 addition & 1 deletion examples/int/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern "C"
{
#endif

#include <stdint.h>
#include <stdbool.h>
int32_t power_power_of(int32_t base, int32_t exp);
Expand Down
2 changes: 1 addition & 1 deletion examples/list_int/sum.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern "C"
{
#endif

#include <stdint.h>
#include <stdbool.h>
typedef struct {
Expand Down
2 changes: 0 additions & 2 deletions examples/list_string/sum.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,3 @@ int32_t sum_sum_length(sum_list_string_t *a) {
}
return res;
}


6 changes: 3 additions & 3 deletions examples/list_string/sum.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
extern "C"
{
#endif

#include <stdint.h>
#include <stdbool.h>

typedef struct {
char *ptr;
size_t len;
} sum_string_t;

void sum_string_set(sum_string_t *ret, const char *s);
void sum_string_dup(sum_string_t *ret, const char *s);
void sum_string_free(sum_string_t *ret);
Expand Down
2 changes: 1 addition & 1 deletion examples/record/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ impl record::Record for Record {
b: a.b,
}
}
}
}
1 change: 0 additions & 1 deletion examples/sentiment/sentiment.wit
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ sentiment: func(input: string, ) -> polarity-scores
wit-source-get: func() -> string

wit-source-print: func()

5 changes: 2 additions & 3 deletions examples/string/split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void split_split_str(split_string_t *phrase, split_string_t *delim, split_list_s
}
}
subs.push_back(std::pair<std::string, size_t>(phr.substr(start), start));

// Populate the result.
bool err = false;
auto res = (split_subphrase_t *) malloc(phr.size() * sizeof(split_subphrase_t));
Expand Down Expand Up @@ -118,10 +118,9 @@ void split_split_str(split_string_t *phrase, split_string_t *delim, split_list_s
free(res[i].str.ptr);
free(res);
}
}
}

// Per the Canonical ABI contract, free the input pointers.
free(phrase->ptr);
free(delim->ptr);
}

6 changes: 3 additions & 3 deletions examples/string/split.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
extern "C"
{
#endif

#include <stdint.h>
#include <stdbool.h>

typedef struct {
char *ptr;
size_t len;
} split_string_t;

void split_string_set(split_string_t *ret, const char *s);
void split_string_dup(split_string_t *ret, const char *s);
void split_string_free(split_string_t *ret);
Expand Down
Loading