Skip to content

Commit

Permalink
Chore(api-client): update to new API structure (#58)
Browse files Browse the repository at this point in the history
* chore(api-client): update to new API structure

* chore(api-client): readme updates

* chore(api-aclient): improved test login conf

* chore(api-client): more test fixes
  • Loading branch information
juanneilson authored Oct 24, 2024
1 parent 2b23c3d commit d0019a6
Show file tree
Hide file tree
Showing 23 changed files with 4,272 additions and 2,235 deletions.
5 changes: 2 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
"debug.terminal.clearBeforeReusing": true,
"editor.bracketPairColorization.enabled": true,
"editor.codeActionsOnSave": {
"source.sortImports": true,
"source.organizeImports": true,
// "source.fixAll.shellcheck": true,
"source.sortImports": "explicit",
"source.organizeImports": "explicit"
},
// "editor.hover.delay": 300,
// "editor.quickSuggestionsDelay": 10,
Expand Down
215 changes: 37 additions & 178 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ To install it locally with pip:
pip3 install teselagen
```

## Use and login
## Use and login

Import the `teselagen` library:

```python
from teselagen.api import TeselaGenClient
```
Expand All @@ -27,7 +28,7 @@ Create an instance of the client:
client = TeselaGenClient(host_url="https://<INSTANCE NAME>.teselagen.com/")
```

Then, login by using your user email and One Time Password (OTP). You can get one from `Settings`-> `API Password`
Then, login by using your user email and One Time Password (OTP). You can get one from `Settings`-> `API Password`
within the application. Alternatively ,you can use your application password.

```python
Expand All @@ -50,28 +51,14 @@ to run them:

1. Open any notebook in the `examples` folder with Jupyter Notebook

## Use the provided environment

You can use the provided docker environment that contains a ready to use installation of all required packages to run
the notebooks. Here are the instructions according to your OS

### Linux/MacOS

1. After clone/download, run the build script with `bash build.sh`
## Development

1. Run the container with `bash run.sh`
### Poetry virtual environment

1. Open your browser and set the address: `http://localhost:8888`. From there you can explore all example notebooks
For development you can just use the virtual environment created by poetry. To install the project within a virtual
environment, use at the project's root folder:

## Development (Linux/MacOS)

### Docker environment

1. Build the docker environment with command `bash build.sh`

1. Run the container as a developer with the command `bash run_dev.sh`.
With this command the `teselagen` library will be installed in
[editable](https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs) mode.
`poetry install`

### Dependencies

Expand All @@ -95,47 +82,48 @@ It is the equivalent to make an install after deleting the `lock` file.

1. Add your credentials

To run the tests, you must create a `.credentials` file containing the test _username_ and _password_, in the
_root_ folder.
To run the tests, you must create a `.credentials` file containing the test _username_ and _password_, in the
_root_ folder.

The content of `.credentials` file should look similar to the following:
The content of `.credentials` file should look similar to the following:

```JSON
{
"username" : "ReplaceWithYourUsername",
"password" : "ReplaceWithYourPassword"
}
````
```JSON
{
"username" : "ReplaceWithYourUsername",
"password" : "ReplaceWithYourPassword"
}
```

- **NOTE**: It should be a valid `JSON` file. `JSON with Comments` (`JSONC` ) format is not supported.
- **NOTE 1**: It should be a valid `JSON` file. `JSON with Comments` (`JSONC` ) format is not supported.
- **NOTE 2**: You may also add a `host` field. It's value will be used as default host name.

```diff
- DO NOT COMMIT THIS FILE : .credentials
```
```diff
- DO NOT COMMIT THIS FILE : .credentials
```

1. Modify configuration

You may modify some test configuration parameters by creating a `.test_configuration` file.
This is a `JSON` formatted file, where you can edit the server name used for tests.
This file must be stored next to `.credentials` file. Here is an example
You may modify some test configuration parameters by creating a `.test_configuration` file.
This is a `JSON` formatted file, where you can edit the server name used for tests.
This file must be stored next to `.credentials` file. Here is an example

```JSON
{
"host_url" : "https://platform.teselagen.com"
}
```
```JSON
{
"host_url" : "https://platform.teselagen.com"
}
```

- **NOTE**: It should be a valid `JSON` file. `JSON with Comments` (`JSONC` ) format is not supported.
- **NOTE**: It should be a valid `JSON` file. `JSON with Comments` (`JSONC` ) format is not supported.

1. Run the tests

```bash
cd /home && python3 setup.py test
```
```bash
cd /home && python3 setup.py test
```

You may use the docker environment for testing. For that, first build the environment with `bash build.sh`.
Then just run the container with `bash run_dev.sh`.
Once inside (`docker exec -ti tgclient bash`), go to `home/` and you are ready to run the test command shown above.
You may use the docker environment for testing. For that, first build the environment with `bash build.sh`.
Then just run the container with `bash run_dev.sh`.
Once inside (`docker exec -ti tgclient bash`), go to `home/` and you are ready to run the test command shown above.

### Publishing

Expand Down Expand Up @@ -191,132 +179,3 @@ Or, as follows:
```

---

<!--
# apply end-of-line normalization
git add --renormalize .
# attach to the container
docker exec --tty --interactive tgclient bash
# go to the lib folder
cd /home
# validates the structure of the pyproject.toml file
poetry check
# list all available packages in the container
poetry show
# poetry show --tree
# poetry show --outdated
# poetry show --latest
# run docstrings formatter
python3 -m docformatter --recursive --wrap-summaries 119 --wrap-descriptions 119 --in-place .
# remove unused imports
python3 -m autoflake --verbose --remove-all-unused-imports --ignore-init-module-imports --recursive --in-place .
# fix exceptions
# python3 -m tryceratops --experimental --autofix .
# autopep8
python3 -m autopep8 \
--jobs=$(nproc) \
--diff \
--aggressive \
--aggressive \
--aggressive \
--aggressive \
--aggressive \
--experimental \
--max-line-length=119 \
--select=E26,E265,E266,E731,E711 \
--recursive \
.
python3 -m autopep8 \
--jobs=$(nproc) \
--in-place \
--aggressive \
--aggressive \
--aggressive \
--aggressive \
--aggressive \
--experimental \
--max-line-length=119 \
--select=E26,E265,E266,E731,E711 \
--recursive \
.
# fixit
python3 -m fixit.cli.run_rules \
--rules CollapseIsinstanceChecksRule \
NoInheritFromObjectRule \
NoRedundantLambdaRule \
NoRedundantListComprehensionRule \
ReplaceUnionWithOptionalRule \
RewriteToComprehensionRule \
UseIsNoneOnOptionalRule \
RewriteToLiteralRule \
NoRedundantArgumentsSuperRule \
NoRedundantFStringRule \
UseClsInClassmethodRule \
UseFstringRule
python3 -m fixit.cli.apply_fix \
--skip-autoformatter \
--rules CollapseIsinstanceChecksRule \
NoInheritFromObjectRule \
NoRedundantLambdaRule \
NoRedundantListComprehensionRule \
ReplaceUnionWithOptionalRule \
RewriteToComprehensionRule \
UseIsNoneOnOptionalRule \
RewriteToLiteralRule \
NoRedundantArgumentsSuperRule \
NoRedundantFStringRule \
UseClsInClassmethodRule \
UseFstringRule
# sort imports
python3 -m isort --jobs=8 --color .
# run code formatter
python3 -m yapf --in-place --recursive --parallel .
# run flake8
flake8
# run mypy
mypy -p teselagen
# run radon
radon cc teselagen
# run tests
python3 setup.py test
# run coverage
pytest --cov="teselagen" --cov-report term:skip-covered
# run pyclean
cd /home
python3 -m pyclean --verbose --dry-run .
cd /home
cd /home
python3 -m pyclean --verbose .
cd /home
# run cleanpy
cd /home
python3 -m cleanpy --include-builds --include-envs --include-testing --include-metadata --verbose --dry-run .
cd /home
cd /home
python3 -m cleanpy --include-builds --include-envs --include-testing --include-metadata --verbose .
cd /home
-->
15 changes: 8 additions & 7 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pytest

from teselagen.api.client import TeselaGenClient
from teselagen.utils import get_test_configuration_path
from teselagen.utils import get_test_configuration_path, get_default_host_name
from teselagen.utils import load_from_json

TEST_API_TOKEN_EXPIRATION_TIME = '30m'
Expand Down Expand Up @@ -70,14 +70,14 @@ def get_test_configuration() -> dict[str, str]:
```json
{
"host_url": "http://host.docker.internal:3000",
"api_token_name": "x-tg-cli-token"
"api_token_name": "x-tg-api-token"
}
```
```json
{
"host_url": "http://platform.teselagen.com",
"api_token_name": "x-tg-cli-token"
"api_token_name": "x-tg-api-token"
}
```
Expand All @@ -88,8 +88,8 @@ def get_test_configuration() -> dict[str, str]:
```
"""
DEFAULT_CONFIGURATION: dict[str, str] = {
'host_url': 'http://host.docker.internal:3000',
'api_token_name': 'x-tg-cli-token',
'host_url': get_default_host_name(),
'api_token_name': 'x-tg-api-token',
}
DEFAULT_CONFIGURATION['host_url'] = DEFAULT_CONFIGURATION['host_url'].strip('/')

Expand All @@ -103,8 +103,8 @@ def get_test_configuration() -> dict[str, str]:
assert isinstance(file_conf, dict), 'Configuration file should be a JSON file.'

# Check keys are ok
assert all(
key in configuration for key in file_conf), f'One or more of these keys are wrong: {file_conf.keys()}'
for key in file_conf:
assert key in configuration, f'The key {key} should not be in the test configuration file.'

# Update values
configuration.update(file_conf)
Expand Down Expand Up @@ -218,6 +218,7 @@ def clean_test_module_used_for_testing() -> None:
expiration_time=TEST_API_TOKEN_EXPIRATION_TIME)

LAB_NAME: str = 'The Test Lab' # noqa: N806

client.select_laboratory(lab_name=LAB_NAME)

# FILES
Expand Down
Loading

0 comments on commit d0019a6

Please sign in to comment.