Skip to content

Commit

Permalink
CLI package (cvat-ai#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max authored Jun 18, 2022
1 parent bc9fc45 commit fd4a130
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ branch = true

source =
cvat/apps/
utils/cli/
cvat-cli/
utils/dataset_manifest

omit =
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
CONTAINER_COVERAGE_DATA_DIR: "/coverage_data"
run: |
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
-c 'coverage run -a manage.py test cvat/apps utils/cli -k 'tasks_id' -k 'lambda' -k 'share' && mv .coverage ${CONTAINER_COVERAGE_DATA_DIR}'
-c 'coverage run -a manage.py test cvat/apps cvat-cli -k 'tasks_id' -k 'lambda' -k 'share' && mv .coverage ${CONTAINER_COVERAGE_DATA_DIR}'
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
-c 'cd cvat-data && npm ci --ignore-scripts && cd ../cvat-core && npm ci --ignore-scripts && npm run test && mv ./reports/coverage/lcov.info ${CONTAINER_COVERAGE_DATA_DIR} && chmod a+rwx ${CONTAINER_COVERAGE_DATA_DIR}/lcov.info'
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"--settings",
"cvat.settings.testing",
"cvat/apps",
"utils/cli"
"cvat-cli/"
],
"django": true,
"cwd": "${workspaceFolder}",
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Project/task backups uploading via chunk uploads (<https://github.com/cvat-ai/cvat/pull/9>)
- Fixed UX bug when jobs pagination is reset after changing a job (<https://github.com/cvat-ai/cvat/pull/42>)
- Progressbars in CLI for file uploading and downloading (<https://github.com/cvat-ai/cvat/pull/46>)
- `utils/cli` changed to `cvat-cli` package (<https://github.com/cvat-ai/cvat/pull/59>)

### Changed
- Bumped nuclio version to 1.8.14 (<https://github.com/cvat-ai/cvat/pull/29>)
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ COPY --chown=${USER} ssh ${HOME}/.ssh
COPY --chown=${USER} supervisord.conf mod_wsgi.conf wait-for-it.sh manage.py ${HOME}/
COPY --chown=${USER} cvat/ ${HOME}/cvat
COPY --chown=${USER} utils/ ${HOME}/utils
COPY --chown=${USER} tests/ ${HOME}/tests

# RUN all commands below as 'django' user
USER ${USER}
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*;

COPY cvat/requirements/ /tmp/cvat/requirements/
COPY utils/cli/requirements/ /tmp/utils/cli/requirements/
COPY cvat-cli ${HOME}/cvat-cli

RUN DATUMARO_HEADLESS=1 python3 -m pip install --no-cache-dir -r /tmp/cvat/requirements/${DJANGO_CONFIGURATION}.txt && \
python3 -m pip install --no-cache-dir -r /tmp/utils/cli/requirements/testing.txt && \
python3 -m pip install --no-cache-dir -r ${HOME}/cvat-cli/requirements/testing.txt && \
python3 -m pip install --no-cache-dir ${HOME}/cvat-cli && \
python3 -m pip install --no-cache-dir coveralls
RUN gem install coveralls-lcov

COPY utils ${HOME}/utils
COPY cvat-core ${HOME}/cvat-core
COPY cvat-data ${HOME}/cvat-data
COPY package*.json ${HOME}/
Expand Down
2 changes: 2 additions & 0 deletions cvat-cli/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.md
include requirements/base.txt
11 changes: 11 additions & 0 deletions cvat-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Command-line client for CVAT

## Installation

`pip install cvat-cli/`

## Usage

```bash
$ cvat-cli --help
```
19 changes: 19 additions & 0 deletions cvat-cli/developer_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Developer guide

Install testing requirements:

```bash
pip install -r requirements/testing.txt
```

Run unit tests:
```
cd cvat/
python manage.py test --settings cvat.settings.testing cvat-cli/
```

Install package in the editable mode:

```bash
pip install -e .
```
4 changes: 4 additions & 0 deletions cvat-cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

File renamed without changes.
4 changes: 4 additions & 0 deletions cvat-cli/requirements/testing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r base.txt

# We depend on the server in the tests
-r ../../cvat/requirements/testing.txt
67 changes: 67 additions & 0 deletions cvat-cli/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (C) 2022 Intel Corporation
#
# SPDX-License-Identifier: MIT

import os.path as osp
import re

import setuptools


def find_version(project_dir=None):
if not project_dir:
project_dir = osp.dirname(osp.abspath(__file__))

file_path = osp.join(project_dir, "version.py")

with open(file_path, "r") as version_file:
version_text = version_file.read()

# PEP440:
# https://www.python.org/dev/peps/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions
pep_regex = r"([1-9]\d*!)?(0|[1-9]\d*)(\.(0|[1-9]\d*))*((a|b|rc)(0|[1-9]\d*))?(\.post(0|[1-9]\d*))?(\.dev(0|[1-9]\d*))?"
version_regex = r"VERSION\s*=\s*.(" + pep_regex + ")."
match = re.match(version_regex, version_text)
if not match:
raise RuntimeError("Failed to find version string in '%s'" % file_path)

version = version_text[match.start(1) : match.end(1)]
return version


BASE_REQUIREMENTS_FILE = "requirements/base.txt"


def parse_requirements(filename=BASE_REQUIREMENTS_FILE):
with open(filename) as fh:
return fh.readlines()


BASE_REQUIREMENTS = parse_requirements(BASE_REQUIREMENTS_FILE)

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="cvat-cli",
version=find_version(project_dir="src/cvat_cli"),
description="Command-line client for CVAT",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/openvinotoolkit/cvat/",
package_dir={"": "src"},
packages=setuptools.find_packages(where='src'),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires=">=3.7",
install_requires=BASE_REQUIREMENTS,
entry_points={
"console_scripts": [
"cvat-cli=cvat_cli.__main__:main",
],
},
include_package_data=True,
)
3 changes: 3 additions & 0 deletions cvat-cli/src/cvat_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (C) 2020-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
11 changes: 7 additions & 4 deletions utils/cli/cli.py → cvat-cli/src/cvat_cli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python3
# Copyright (C) 2020-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT

import logging
import requests
import sys
from http.client import HTTPConnection
from core.core import CLI, CVAT_API_V2
from core.definition import parser
from cvat_cli.core.core import CLI, CVAT_API_V2
from cvat_cli.core.definition import parser
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -45,6 +46,8 @@ def main():
requests.exceptions.RequestException) as e:
log.critical(e)

return 0


if __name__ == '__main__':
main()
sys.exit(main())
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2020-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT

from .definition import parser, ResourceType # noqa
from .core import CLI, CVAT_API_V2 # noqa
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2021 Intel Corporation
# Copyright (C) 2021-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
import argparse
Expand All @@ -7,6 +7,7 @@
import logging
import os
from enum import Enum
from ..version import VERSION


def get_auth(s):
Expand Down Expand Up @@ -53,6 +54,8 @@ def argparse(s):
parser = argparse.ArgumentParser(
description='Perform common operations related to CVAT tasks.\n\n'
)
parser.add_argument("--version", action="version", version=VERSION)

task_subparser = parser.add_subparsers(dest='action')

#######################################################################
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions cvat-cli/src/cvat_cli/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = "0.1"
3 changes: 3 additions & 0 deletions cvat-cli/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (C) 2020-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
6 changes: 3 additions & 3 deletions utils/cli/tests/test_cli.py → cvat-cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
import cvat.apps.engine.log as log
from cvat.apps.engine.tests.test_rest_api import (create_db_users,
generate_image_file)
from utils.cli.core import CLI, CVAT_API_V2, ResourceType
from cvat_cli.core import CLI, CVAT_API_V2, ResourceType
from tqdm import tqdm


class TestCLI(APITestCase):
def setUp(self):
self._stdout_handler = redirect_stdout(io.StringIO())
mock_stdout = self._stdout_handler.__enter__()
log = logging.getLogger("utils.cli")
log = logging.getLogger("cvat_cli")
log.propagate = False
log.setLevel(logging.INFO)
log.handlers.clear()
Expand Down Expand Up @@ -75,7 +75,7 @@ class TestTaskOperations(APITestCase):
def setUp(self):
self._stdout_handler = redirect_stdout(io.StringIO())
mock_stdout = self._stdout_handler.__enter__()
log = logging.getLogger("utils.cli")
log = logging.getLogger("cvat_cli")
log.propagate = False
log.setLevel(logging.INFO)
log.handlers.clear()
Expand Down
Loading

0 comments on commit fd4a130

Please sign in to comment.