Skip to content

Commit 73403e9

Browse files
committed
Fixing the project to be compatible with pylib release, making the first working release of recodex CLI tool (new version).
1 parent 40936b3 commit 73403e9

File tree

14 files changed

+93
-71
lines changed

14 files changed

+93
-71
lines changed

.github/workflows/python-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
chmod +x ./tests/tests.sh
2727
python3 -m pip install --upgrade pip
2828
python3 -m pip install -r requirements.txt
29-
PIP_EXTRA_INDEX_URL="https://test.pypi.org/simple/" python3 -m pip install -e .
29+
python3 -m pip install -e .
3030
3131
- name: Install Bats
3232
run: |

README.md

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,81 @@
1-
# ReCodEx Client
1+
# ReCodEx CLI Client
22

3-
A command-line interface for the [ReCodEx](https://recodex.mff.cuni.cz/) system. This tool allows users to interact with ReCodEx from their terminal, streamlining workflows and enabling scripting possibilities.
3+
A command-line interface for the [ReCodEx](https://github.com/ReCodEx) system. This tool allows users to interact with ReCodEx from their terminal, streamlining workflows and enabling scripting possibilities. The aim is not to create a terminal-based replacement for web application, but rather an intermediate layer for bash scripts or other automation tools.
44

5-
## What is ReCodEx?
5+
This tool is built on top of the [recodex-pylib](https://github.com/ReCodEx/pylib) Python library, which provides a wrapper for ReCodEx API generated from OpenAPI (swagger) specification.
66

7-
ReCodEx is a system for dynamic analysis and evaluation of programming exercises. It allows supervisors to assign programming problems to students, who can then submit their solutions through a web interface. ReCodEx automatically evaluates these solutions by compiling and executing them in a safe environment, providing quick feedback to students.
87

98
## Key Features
109

11-
* **Authentication:** Securely log in to your ReCodEx account. The CLI will securely store your access token for future sessions.
12-
* **Execute Requests:** Send requests and view responses from the command line.
10+
* **Authentication:** Securely log in to your ReCodEx account. The CLI will securely store your access token for future sessions. The session is shared with the `recodex-pylib` library, so you can use it in conjunction with your Python scripts.
11+
* **Execute Requests:** Send API requests and view responses from the command line.
1312
* **Interactive Mode:** You can use the interactive mode to browse and use existing endpoints.
1413
* **Plugins:** Use existing plugins or write your own to streamline your work.
1514

15+
1616
## Installation
1717

1818
The recommended way to install the ReCodEx CLI is via `pip`. Python 3.11 is recommended, but other versions may also work:
1919

2020
```bash
21-
PIP_EXTRA_INDEX_URL="https://test.pypi.org/simple/" pip install recodex_cli_eceltov
21+
pip install recodex-cli
2222
```
2323

24-
### Installation from Source
24+
Note that this also installs the `recodex-pylib` library as a dependency.
25+
26+
27+
### Installation from source code
28+
29+
For developers or those who prefer to install directly from the source code into local venv, follow these steps:
30+
31+
```bash
32+
./bin/init.sh
33+
source ./venv/bin/activate
34+
```
2535

26-
For developers or those who prefer to install directly from the source code, follow these steps:
36+
Or you can install it globally (not recommended):
2737

2838
```bash
29-
# make sure to run these commands from the root of the repository
30-
./commands/initRepo.sh
31-
source venv/bin/activate
39+
pip install -r requirements.txt
40+
pip install -e .
3241
```
3342

43+
3444
## Getting Started
3545

46+
The CLI is invoked via either
47+
```bash
48+
python3 -m recodex_cli <command> [options]
49+
```
50+
or using the deployed script wrapper
51+
```bash
52+
recodex <command> [options]
53+
```
54+
55+
Let us review basic operations:
56+
3657
- **Login:** You can login with your credentials or an API token.
3758

3859
```bash
3960
# login with credentials
40-
python3 -m recodex_cli login --username [email protected] --password test --api-url http://localhost:4000
41-
42-
# login with an API token
43-
python3 -m recodex_cli login --api-url http://localhost:4000 --token eyJ...
61+
recodex login --username [email protected] --password test --api-url http://your.recodex.domain/api
62+
63+
# login with an API token (can be generated in webapp in user settings)
64+
recodex login --api-url http://your.recodex.domain/api --token eyJ...
4465

4566
# login via an interactive prompt
46-
python3 -m recodex_cli login --prompt-credentials
47-
python3 -m recodex_cli login --prompt-token
67+
recodex login --prompt-credentials
68+
recodex login --prompt-token
4869

4970
# logout
50-
python3 -m recodex_cli logout
71+
recodex logout
5172
```
73+
Let us note that the JWT token (either provided or obtained after credentials verification) is stored in a configuration file in your home directory (usually `~/.local/share/recodex/context.yaml`).
5274

5375
- **Explore Commands:** You can view the full list of available commands and options by running:
5476

5577
```bash
56-
python3 -m recodex_cli --help
78+
recodex --help
5779
```
5880

5981
## Usage
@@ -66,32 +88,35 @@ The client defines the `call` command, which can be used to call any endpoint.
6688

6789

6890
```bash
69-
python3 -m recodex_cli call
91+
recodex call
7092
```
7193

7294
- **Calling an Endpoint:** To call an endpoint, add an argument in the `presenter.action` format, followed by any request parameters.
7395

7496
```bash
7597
# use QUERY parameters in <name=value> format
76-
python3 -m recodex_cli call groups.default --query search=Demo
98+
recodex call groups.default --query search=Demo
99+
100+
# beware that some parameters must be encoded in JSON (the quotes must be backslashed so the bash won't remove them)
101+
recodex call users.default --filters={\"search\":\"Kloda\"}
77102
78103
# you can pass a JSON or YAML file as a request body
79-
python3 -m recodex_cli call registration.create_invitation --body-path invite.yaml
104+
recodex call registration.create_invitation --body-path invite.yaml
80105
81106
# PATH parameters are used in order of declaration (the first one is usually the ID)
82-
python3 -m recodex_cli call groups.set_organizational 10000000-2000-4000-8000-160000000000 --body '{"value":true}'
107+
recodex call groups.set_organizational 10000000-2000-4000-8000-160000000000 --body '{"value":true}'
83108
```
84109

85110
- **Help:** To print a detailed description on how to use the command, use:
86111

87112
```bash
88-
python3 -m recodex_cli call --help
113+
recodex call --help
89114
```
90115

91116
You can also view all parameters of a specific command.
92117

93118
```bash
94-
python3 -m recodex_cli call groups.default --help
119+
recodex call groups.default --help
95120
```
96121

97122
### Plugins
@@ -101,20 +126,20 @@ The client can also be extended with plugins that can streamline common request
101126
- **File Upload:** Files can be uploaded simply by providing a path. Larger files will automatically be fragmented into chunks.
102127

103128
```bash
104-
python3 -m recodex_cli file upload test.csv
129+
recodex file upload test.csv
105130
> File sent successfully
106131
> File ID: 73aac159-b2e2-402b-9e19-096f3ec0ae7c
107132
```
108133

109134
- **File Download:**
110135
```bash
111-
python3 -m recodex_cli file download 73aac159-b2e2-402b-9e19-096f3ec0ae7c --out-path test.csv
136+
recodex file download 73aac159-b2e2-402b-9e19-096f3ec0ae7c --out-path test.csv
112137
```
113138

114139
- **Get Swagger:** This command returns the Swagger document (OpenAPI Specification) currently used by the client.
115140

116141
```bash
117-
python3 -m recodex_cli info swagger
142+
recodex info swagger
118143
```
119144

120145
## Development
@@ -138,7 +163,7 @@ The following skeleton implementation can be used as the basis for new commands:
138163
```python
139164
import typer
140165
# import the DefaultApi class that holds all request functions
141-
from recodex_cli_lib.generated.swagger_client.api.default_api import DefaultApi
166+
from recodex.generated.swagger_client.api.default_api import DefaultApi
142167
143168
from ..utils import client_factory
144169
from ..utils import cmd_utils as cmd_utils
@@ -170,8 +195,3 @@ def new_command(
170195
171196
print(response)
172197
```
173-
174-
### Publishing
175-
176-
Use the `commands/uploadPackage.sh` script to upload a new version of the client.
177-
Note that this will require a PyPI account and upload privileges.

bin/init.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# switch to the repository root
4+
cd `dirname "$0"`/..
5+
6+
if ! test -d ./venv; then
7+
echo "Initializing Python venv"
8+
python3 -m venv venv
9+
./venv/bin/pip install -r requirements.txt
10+
./venv/bin/pip install -e .
11+
fi
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Runs the CI/CD tests locally.
22

3-
./commands/initRepo.sh
3+
# switch to the repository root
4+
cd `dirname "$0"`/..
5+
6+
./bin/init.sh
47

58
source venv/bin/activate
69
rm ~/.local/share/recodex/context.yaml

commands/initRepo.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

commands/uploadPackage.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

pyproject.toml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ requires = [
44
"certifi>=14.05.14",
55
"typer>=0.16",
66
"inquirer>=3.4.0",
7-
"recodex_cli_lib_eceltov>=0.0.66"
7+
"recodex-pylib>=0.2.0"
88
]
99
build-backend = "setuptools.build_meta"
1010

1111
[project]
12-
name = "recodex_cli_eceltov"
13-
version = "0.0.21"
12+
name = "recodex-cli"
13+
version = "0.2.0"
1414
authors = [
1515
{ name="Vojtech Kloda", email="[email protected]" },
16+
{ name="Martin Kruliš", email="[email protected]"},
1617
]
17-
description = "A module for ReCodEx API calls."
18+
description = "CLI client for ReCodEx API implemented in Python based on recodex-pylib."
1819
readme = "README.md"
1920
requires-python = ">=3.11"
2021
classifiers = [
@@ -27,9 +28,13 @@ dependencies = [
2728
"certifi>=14.05.14",
2829
"typer>=0.16",
2930
"inquirer>=3.4.0",
30-
"recodex_cli_lib_eceltov>=0.0.66"
31+
"recodex-pylib>=0.2.0"
3132
]
3233

34+
[project.scripts]
35+
recodex = "recodex_cli.console:app"
36+
3337
[project.urls]
34-
Homepage = "https://github.com/ReCodEx"
35-
Issues = "https://github.com/ReCodEx"
38+
Homepage = "https://github.com/ReCodEx/cli"
39+
Issues = "https://github.com/ReCodEx/cli/issues"
40+

requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
--index-url https://test.pypi.org/simple/
2-
--extra-index-url https://pypi.org/simple/
31
typer >= 0.16
42
inquirer >= 3.4.0
53
twine >= 6.1.0
64
build >= 1.2.2
7-
recodex-cli-lib-eceltov==0.0.66
5+
recodex-pylib==0.2.0
86
flask >= 3.1.1
97
flake8 >= 7.3.0

src/recodex_cli/call_command/command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import click
44
from typing import Any
55
from collections.abc import Callable
6-
from recodex_cli_lib.client import Client
7-
from recodex_cli_lib.client_components.endpoint_resolver import EndpointResolver
6+
from recodex.client import Client
7+
from recodex.client_components.endpoint_resolver import EndpointResolver
88

99
from .response_printer import print_response
1010
from ..utils import cmd_utils as cmd_utils

src/recodex_cli/call_command/help_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import click
22
from rich.console import Console
33
from rich.panel import Panel
4-
from recodex_cli_lib.client_components.endpoint_resolver import EndpointResolver
4+
from recodex.client_components.endpoint_resolver import EndpointResolver
55

66
from ..utils import cmd_utils as cmd_utils
77

0 commit comments

Comments
 (0)