Skip to content
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
6 changes: 3 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ automated e2e/unit tests.
code that was well tested you do not have to add tests)
- [ ] I ran `mvn clean package` right before creating this pull request and
added all formatting changes to my commit.
- [ ] If I made any Python code changes, I ran `black .` and `pylint .` right
before creating this pull request and added all formatting changes to my
commit.
- [ ] If I made any Python code changes, I ran `black .`, `pylint .` and
`pyright` . right before creating this pull request and added all
formatting changes to my commit.
- [ ] All new and existing **tests passed**.
- [ ] My pull request is **based on the latest changes** of the master branch.

Expand Down
6 changes: 3 additions & 3 deletions doc/developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ replay the new events with no more interactions with OpenMRS.

## Python development

This requires you to run to install some dev dependencies e.g. `black` and
`pylint` packages. It is a good idea to first create a Python `virtualenv`: (Run
these commands from the root of the repo)
This requires you to run to install some dev dependencies e.g. `black`, `pylint`
and `pyright` packages. It is a good idea to first create a Python `virtualenv`:
(Run these commands from the root of the repo)

_Note:_ we removed `isort` since now have `pylint` which can flag out of order
imports that the developer can check and fix.
Expand Down
22 changes: 15 additions & 7 deletions pipelines/controller-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,24 @@ Then you can execute the following command from the project's root directory:

## Formatting and Linting

This project uses `black` for code formatting, and `PyLint` for linting. To run
these commands, you need to have installed the requirements in the repo's root
declared in the `requirements-dev.txt` file _(i.e. navigating to the root and
using `pip install -r requirements-dev.txt` in the root folder's `venv`)_.
This project uses `black` for code formatting, `Pylint` for linting, and
`Pyright` for static type checking. To run these commands, you need to have
installed the requirements in the repo's root declared in the
`requirements-dev.txt` file _(i.e. navigating to the root and using
`pip install -r requirements-dev.txt` in the root folder's `venv`)_.

Ensure you have activated your venv. You can then run the formatter and linter
by changing directory to the `controller-cli` folder and running:
Ensure you have activated your venv. You can then run the tools by running:

The formatter:

```sh
black pipelines/controller-cli
```

The type checker:

```sh
black .
pyright pipelines/controller-cli
```

You can run the linter with:
Expand Down
29 changes: 15 additions & 14 deletions pipelines/controller-cli/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ def process_response(response: str, args: argparse.Namespace):
logger.info(f"Request url: {args.url}")
logger.info("Response:")
try:
logger.info(json.dumps(response, indent=4))
except json.JSONDecodeError:
if isinstance(response, dict):
logger.info(json.dumps(response, indent=4))
else:
logger.info(response)
except TypeError:
logger.info(response)


def _make_api_request(
verb: str, url: str, params: Optional[Dict[str, Any]] = None
) -> Optional[Dict[str, Any]]:
) -> str:
logger.debug(f"Making API request: {verb} {url}")
logger.debug(f"Request parameters: {params}")
try:
Expand Down Expand Up @@ -103,11 +106,10 @@ def _make_api_request(
logger.error(f"An error occurred during the request: {req_err}")
except json.JSONDecodeError as json_err:
logger.error(f"Failed to decode JSON response: {json_err}")
logger.error(response)
return None
return "API REQUEST FAILED"


def config(args: argparse.Namespace) -> str:
def config(args: argparse.Namespace) -> None:
try:
if args.config_name:
response = _make_api_request(
Expand All @@ -120,23 +122,23 @@ def config(args: argparse.Namespace) -> str:
logger.error(f"Error processing: {e}")


def next_scheduled(args: argparse.Namespace) -> str:
def next_scheduled(args: argparse.Namespace) -> None:
try:
response = _make_api_request(HTTP_GET, f"{args.url}/next")
process_response(response, args)
except requests.exceptions.RequestException as e:
logger.error(f"Error processing: {e}")


def status(args: argparse.Namespace) -> str:
def status(args: argparse.Namespace) -> None:
try:
response = _make_api_request(HTTP_GET, f"{args.url}/status")
process_response(response, args)
except requests.exceptions.RequestException as e:
logger.error(f"Error processing: {e}")


def run(args: argparse.Namespace) -> str:
def run(args: argparse.Namespace) -> None:
logger.info("=" * 50)
logger.info("Executing 'run' command - starting pipeline run")
logger.info(f"Run mode: {args.mode}")
Expand Down Expand Up @@ -164,10 +166,9 @@ def run(args: argparse.Namespace) -> str:
logger.error(f"Error in run command: {e}")
logger.error(f"Failed to execute pipeline run with mode: {args.mode}")
logger.error("=" * 50)
logger.error(f"Error processing: {e}")


def tables(args: argparse.Namespace) -> str:
def tables(args: argparse.Namespace) -> None:
try:
response = _make_api_request(HTTP_POST, f"{args.url}/tables")
process_response(response, args)
Expand All @@ -185,11 +186,11 @@ def download_file(url: str, filename: str) -> str:
return f"Error downloading file: {e}"


def logs(args: argparse.Namespace) -> str:
def logs(args: argparse.Namespace) -> None:
try:
if args.download:
filename = args.filename if args.filename else "error.log"
response = download_file(f"{args.url}/download-error-log", filename)
response: str = download_file(f"{args.url}/download-error-log", filename)
process_response(response, args)
else:
logger.info(
Expand All @@ -211,7 +212,7 @@ def delete_snapshot(args: argparse.Namespace) -> str:
return f"Error deleting snapshot: {e}"


def dwh(args: argparse.Namespace) -> str:
def dwh(args: argparse.Namespace) -> None:
try:
if hasattr(args, "snapshot_id"):
response = delete_snapshot(args)
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
black
pylint
pyright
Loading