Skip to content

Commit

Permalink
Merge branch 'scalabel:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
szjozsef authored Jun 15, 2022
2 parents 97a779f + be7d6b9 commit 698b3a5
Show file tree
Hide file tree
Showing 42 changed files with 739 additions and 352 deletions.
23 changes: 13 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
name: lint python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install apt packages
run: |
sudo apt-get install -y libopenmpi-dev
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
Expand Down Expand Up @@ -49,12 +49,12 @@ jobs:
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install apt packages
run: |
sudo apt-get install -y libopenmpi-dev
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -66,7 +66,9 @@ jobs:
- name: Build
run: python3 setup.py sdist bdist_wheel
- name: Test
run: python3 -m pytest --pyargs scalabel
run: |
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
python3 -m pytest --pyargs scalabel
python-mac:
name: test py${{ matrix.python-version }} on mac
Expand All @@ -76,12 +78,12 @@ jobs:
python-version: ["3.9", "3.10"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install brew packages
run: |
brew install openmpi
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -95,6 +97,7 @@ jobs:
- name: Test
env:
MPLBACKEND: TkAgg
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: python
run: python3 -m pytest --pyargs scalabel

nodejs:
Expand All @@ -120,9 +123,9 @@ jobs:
- 6378:6379

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install node packages
Expand All @@ -144,7 +147,7 @@ jobs:
name: build docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and export to Docker
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
Expand All @@ -36,4 +36,4 @@ jobs:
AWS_S3_BUCKET: doc.scalabel.ai
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SOURCE_DIR: "doc/_build/src/html/"
SOURCE_DIR: "doc/_build/src/html/"
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: build and push docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Runs a single command using the runners shell
- name: Run setup script
Expand Down
38 changes: 14 additions & 24 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ persistent=yes

# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=pylint.extensions.docparams
load-plugins=pylint.extensions.docparams,pylint.extensions.bad_builtin,pylint.extensions.no_self_use

# Use multiple processes to speed up Pylint.
jobs=1
Expand All @@ -40,7 +40,7 @@ confidence=
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time. See also the "--disable" option for examples.
enable=use-symbolic-message-instead,useless-supression,fixme
enable=use-symbolic-message-instead,useless-suppression,fixme

# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
Expand All @@ -52,10 +52,8 @@ enable=use-symbolic-message-instead,useless-supression,fixme
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"

# This is a bug in detecting bad continuation. Since black is handling the code
# formatting, we can disable C0330 safely.
# C0413: ignore wrong import order since we use isort for that
disable=C0330, R0801, C0413
disable=R0801, C0413



Expand All @@ -66,11 +64,6 @@ disable=C0330, R0801, C0413
# mypackage.mymodule.MyReporterClass.
output-format=text

# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no

# Tells whether to display a full report or only the messages
reports=no

Expand Down Expand Up @@ -144,9 +137,6 @@ max-line-length=79
# else.
single-line-if-stmt=no

# List of optional constructs for which whitespace checking is disabled
no-space-check=trailing-comma,dict-separator

# Maximum number of lines in a module
max-module-lines=1024

Expand Down Expand Up @@ -183,61 +173,61 @@ include-naming-hint=no
function-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for function names
function-name-hint=[a-z_][a-z0-9_]{2,30}$
function-naming-style=snake_case

# Regular expression matching correct variable names
variable-rgx=[a-z_][a-z0-9_]{0,30}$

# Naming hint for variable names
variable-name-hint=[a-z_][a-z0-9_]{0,30}$
variable-naming-style=snake_case

# Regular expression matching correct constant names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Naming hint for constant names
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
const-naming-style=snake_case

# Regular expression matching correct attribute names
attr-rgx=[a-z_][a-z0-9_]{1,}$

# Naming hint for attribute names
attr-name-hint=[a-z_][a-z0-9_]{1,}$
attr-naming-style=snake_case

# Regular expression matching correct argument names
argument-rgx=[a-z_][a-z0-9_]{1,30}$

# Naming hint for argument names
argument-name-hint=[a-z_][a-z0-9_]{1,30}$
argument-naming-style=snake_case

# Regular expression matching correct class attribute names
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{1,30}|(__.*__))$

# Naming hint for class attribute names
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{1,30}|(__.*__))$
class-attribute-naming-style=snake_case

# Regular expression matching correct inline iteration names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$

# Naming hint for inline iteration names
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
inlinevar-naming-style=snake_case

# Regular expression matching correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$

# Naming hint for class names
class-name-hint=[A-Z_][a-zA-Z0-9]+$
class-naming-style=snake_case

# Regular expression matching correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Naming hint for module names
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
module-naming-style=snake_case

# Regular expression matching correct method names
method-rgx=[a-z_][a-z0-9_]{2,}$

# Naming hint for method names
method-name-hint=[a-z_][a-z0-9_]{2,}$
method-naming-style=snake_case

# Regular expression which should only match function or class names that do
# not require a docstring.
Expand Down Expand Up @@ -369,4 +359,4 @@ int-import-graph=

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
overgeneral-exceptions=Exception
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ docker run -it -v "`pwd`/local-data:/opt/scalabel/local-data" -p \
The Python API can be installed through `pip`:

```bash
python3 -m pip install scalabel
python3 -m pip install -U scalabel
```

For other operating systems or if you wish to use the Docker image, please refer to the [installation guide](https://doc.scalabel.ai/setup.html).
Expand Down
22 changes: 2 additions & 20 deletions app/src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Hub } from "./hub"
import { Listeners } from "./listeners"
import Logger from "./logger"
import auth from "./middleware/cognitoAuth"
import { multipartFormData as formDataMiddleware } from "./middleware/multipart"
import errorHandler from "./middleware/errorHandler"
import { getAbsSrcPath, getRedisConf, HTML_DIRS } from "./path"
import { ProjectStore } from "./project_store"
Expand Down Expand Up @@ -114,29 +115,10 @@ function startHTTPServer(
listeners.deleteProjectHandler.bind(listeners)
)

const maxFileSize = 1000 * 1024 * 1024 // 1G
app.post(
Endpoint.POST_PROJECT,
authMiddleWare,
(req, _, next) => {
/**
* If we need to use formidable at more places, we had better make this a middleware.
*/
const form = new formidable.IncomingForm({ maxFileSize: maxFileSize })
form.parse(req, (err, fields, files) => {
// err is defined as any in formidable types
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (err) {
return next(err)
}

Object.assign(req, {
fields,
files
})
return next()
})
},
formDataMiddleware,
listeners.postProjectHandler.bind(listeners)
)
app.post(
Expand Down
48 changes: 48 additions & 0 deletions app/src/server/middleware/multipart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { IncomingMessage } from "http"
import { NextFunction, Request, Response } from "express"
import formidable, { Fields, Files } from "formidable"

const maxFileSize = 1000 * 1024 * 1024 // 1G

/**
* A middleware to parse multipart/form-data request, after which two
* properties, `fields` and `files`, will be added to the request.
*
* @param req -
* @param _
* @param next
*/
export function multipartFormData(
req: Request,
_: Response,
next: NextFunction
): void {
parseMultipartFormData(req)
.then(({ fields, files }) => {
Object.assign(req, { fields, files })
next()
})
.catch(next)
}

/**
* Parse an incoming multipart/form-data request.
*
* @param req
*/
export async function parseMultipartFormData(
req: IncomingMessage
): Promise<{ fields: Fields; files: Files }> {
return await new Promise((resolve, reject) => {
const form = new formidable.IncomingForm({ maxFileSize: maxFileSize })
form.parse(req, (err, fields, files) => {
// `err` is defined as `any` by formidable.
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (err) {
reject(err)
} else {
resolve({ fields, files })
}
})
})
}
3 changes: 3 additions & 0 deletions app/src/server/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export function getHandlerUrl(itemType: string, labelType: string): string {
if (
labelType === LabelTypeName.BOX_2D ||
labelType === LabelTypeName.POLYGON_2D ||
labelType === LabelTypeName.POLYLINE_2D ||
labelType === LabelTypeName.CUSTOM_2D ||
labelType === LabelTypeName.BOX_3D
) {
Expand Down Expand Up @@ -187,6 +188,8 @@ export function getPolicy(
return [[TrackPolicyType.LINEAR_INTERPOLATION], labelTypes]
case LabelTypeName.POLYGON_2D:
return [[TrackPolicyType.LINEAR_INTERPOLATION], labelTypes]
case LabelTypeName.POLYLINE_2D:
return [[TrackPolicyType.LINEAR_INTERPOLATION], labelTypes]
case LabelTypeName.CUSTOM_2D:
labelTypes[0] = Object.keys(templates2d)[0]
return [[TrackPolicyType.LINEAR_INTERPOLATION], labelTypes]
Expand Down
2 changes: 0 additions & 2 deletions app/test/server/create_project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ afterAll(() => {
fs.removeSync(dataDir)
})

// TODO- test that form is loaded correctly

describe("test project.json creation", () => {
test("image project creation", async () => {
return await testProjectCreation(
Expand Down
Loading

0 comments on commit 698b3a5

Please sign in to comment.