Skip to content

Commit

Permalink
Commit test files for bash_run and bash_compile. Support multi cluste…
Browse files Browse the repository at this point in the history
…r option. Remove TypeError
  • Loading branch information
RohithSurya committed Jun 26, 2024
1 parent 2430407 commit 4b329ce
Show file tree
Hide file tree
Showing 13 changed files with 610 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
pull_number: context.issue.number
})
const isTitleValid = /^\[#\d+\] /.test(pr.data.title)
const isDescriptionValid = /([Ff]ix(es|ed)?|[Cc]lose(s|d)?|[Rr]esolve(s|d)?|[Pp]art [Oo]f) \(.*\)\[.*\]/.test(pr.data.body)
const isDescriptionValid = /([Ff]ix(es|ed)?|[Cc]lose(s|d)?|[Rr]esolve(s|d)?|[Pp]art [Oo]f) \[.*\]\(.*\)/.test(pr.data.body)
if (isTitleValid && isDescriptionValid) {
return
}
Expand Down
35 changes: 30 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ We value your interest in contributing to `PyHPCC.`

Thank you

## Project Structure
```
.
└── pyhpcc/
├── .github # contains build, release, test and other gh actions
├── docs/ # contains files for documentation
├── examples/ # contains starter examples
├── src/
│ ├── pyhpcc/
│ │ ├── handlers/ # contains thor and roxie handler
│ │ └── models/ # contains classes auth, workunit submit
│ └── tests/
│ ├── models/
│ ├── test_files/ # contains resource files needed for testing
│ └── hanlders/
├── pyproject.toml # Project config
├── CONTRIBUTING.md
└── README.md
```

## Set up the repository locally.
## Prerequisites
Before starting to develop, make sure you install the following software:
Expand All @@ -25,6 +45,15 @@ To install the dependencies, run the following command, which downloads the depe
poetry install
```

## How to run tests
Since ecl client tools aren't installed in the GitHub runner, some tests are skipped in the github runner.

Some tests will fail if `ecl client tools` aren't installed.

```
pytest run # Run in project root
```

## Linting and Formatting
PyHPCC uses [Ruff](https://docs.astral.sh/ruff/) as its formatter and linter.

Expand Down Expand Up @@ -56,8 +85,4 @@ The base branch is the main repo's main branch.
- PR name: copy-and-paste the relevant issue name and include the issue number in front in square brackets, e.g. `[#1020] Make bash_runcommand in WorkUnitSubmit class configurable `
- PR description: mention the issue number in this format: Fixes #1020. Doing so will automatically close the related issue once the PR is merged.
- Please Ensure that "Allow edits from maintainers" is ticked.
- Please describe the changes you have made in your branch and how they resolve the issue.




- Please describe the changes you have made in your branch and how they resolve the issue.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ To use PyHPCC, you need these<br>
1. [Python3](https://www.python.org/downloads/)
2. [ECL Client Tools](https://hpccsystems.com/download/): Select your operating systems to download client tools



Download the latest stable build from releases in GitHub.<br>

``` bash
Expand All @@ -36,5 +38,4 @@ Contributions to PyHPCC are welcomed and encouraged.<br>
For specific contribution guidelines, please take a look at [CONTRIBUTING.md](CONTRIBUTING.md).


For more information about the package, please refer to the detailed documentation - https://upgraded-bassoon-daa9d010.pages.github.io/build/html/index.html

For more information about the package, please refer to the detailed documentation - https://upgraded-bassoon-daa9d010.pages.github.io/build/html/index.html
41 changes: 30 additions & 11 deletions src/pyhpcc/command_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import logging

from pyhpcc.config import (
CLUSTER_OPTION,
COMPILE_OPTIONS,
JOB_NAME_OPTION,
LIMIT_OPTION,
OUTPUT_FILE_OPTION,
PASSWORD_OPTIONS,
PORT_OPTION,
RUN_AUTH_OPTIONS,
Expand Down Expand Up @@ -35,6 +39,9 @@ class CompileConfig(object):
create_compile_bash_command:
Generate the eclcc command for the given options and input_file
get_option:
Retrieves the compile config option
"""

Expand All @@ -43,31 +50,35 @@ def __init__(self, options: dict):

def validate_options(self):
"""Validate if the compiler options are supported or not"""
invalid_options = set()
invalid_options = []
for option in self.options:
if option not in COMPILE_OPTIONS and not (
option.startswith("-R") or option.startswith("-f")
):
invalid_options.add(option)
invalid_options.append(option)
if len(invalid_options) > 0:
raise CompileConfigException(str(invalid_options))

def set_output_file(self, output_file):
"""Set name of output file (default a.out if linking to"""
self.options["-o"] = output_file
self.options[OUTPUT_FILE_OPTION] = output_file

def create_compile_bash_command(self, input_file):
"""Generate the eclcc command for the given options and input_file"""
self.validate_options()
eclcc_command = "eclcc"
for key, value in self.options.items():
if isinstance(value, bool):
if value is bool:
eclcc_command += f" {key}"
else:
eclcc_command += f" {key} {value}"
eclcc_command = f"{eclcc_command} {input_file}"
return eclcc_command

def get_option(self, option):
"""Get the option available for the option"""
return self.options[option]


class RunConfig(object):
"""
Expand Down Expand Up @@ -106,6 +117,10 @@ class RunConfig(object):
set_password:
Set password for accessing ecl services
get_option:
Retrieves the run config option
"""

def __init__(self, options: dict):
Expand All @@ -125,17 +140,17 @@ def validate_options(self):
f"Invalid options not supported by pyhpcc {str(invalid_options)}"
)

def create_run_bash_command(self, target_file=""):
def create_run_bash_command(self, target_file):
"""Generate the ecl command for the given options and target_file"""
self.validate_options()
ecl_command = "ecl run"
params = ""
for key, value in self.options.items():
if isinstance(value, bool):
if value is bool:
params += f" {key}"
else:
params += f" {key} {value}"
ecl_command = f"{ecl_command} {target_file} {params}"
ecl_command = f"{ecl_command} {target_file}{params}"
log.info(ecl_command)
return ecl_command

Expand All @@ -152,23 +167,23 @@ def set_auth_params(self, auth: Auth):

def set_target(self, target):
"""Set the target"""
self.options["--target"] = target
self.options[CLUSTER_OPTION] = target

def set_job_name(self, job_name):
"""Specify the job name for the workunit"""
self.options["--name"] = job_name
self.options[JOB_NAME_OPTION] = job_name

def set_limit(self, limit):
"""Sets the result limit for the query"""
self.options["--limit"] = limit
self.options[LIMIT_OPTION] = limit

def set_server(self, server):
"""Set IP of server running ecl services (eclwatch)"""
self.options[SERVER_OPTIONS[0]] = server

def set_port(self, port):
"""Set ECL services port"""
self.options[PORT_OPTION[0]] = port
self.options[PORT_OPTION] = port

def set_username(self, username):
"""Set username for accessing ecl services"""
Expand All @@ -177,3 +192,7 @@ def set_username(self, username):
def set_password(self, password):
"""Set password for accessing ecl services"""
self.options[PASSWORD_OPTIONS[0]] = password

def get_option(self, option):
"""Get the option available for the option"""
return self.options[option]
23 changes: 11 additions & 12 deletions src/pyhpcc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,27 @@
}


platforms = {"hthor", "thor", "roxie"}

DEFAULT_COMPILE_OPTIONS = {"-platform": "thor", "-wu": True, "-E": True}
DEFUALT_RUN_OPTIONS = {}

CLUSTER_PARAM = "--target"
JOB_NAME_PARAM = "--name"
LIMIT_PARAM = "--limit"
CLUSTER_OPTION = "--target"
JOB_NAME_OPTION = "--name"
LIMIT_OPTION = "--limit"
DEFAULT_LIMIT = 100
USER_OPTIONS = ["-u", "--username"]
PASSWORD_OPTIONS = ["-pw", "--password"]
SERVER_OPTIONS = ["-s", "--s"]
PORT_OPTION = ["--port"]
PORT_OPTION = "--port"
OUTPUT_FILE_OPTION = "-o"
VERBOSE_OPTIONS = [
"-v",
"--verbose",
]
RUN_AUTH_OPTIONS = {*USER_OPTIONS, *PASSWORD_OPTIONS, *SERVER_OPTIONS, *PORT_OPTION}
RUN_AUTH_OPTIONS = {*USER_OPTIONS, *PASSWORD_OPTIONS, *SERVER_OPTIONS, PORT_OPTION}

COMPILE_OPTIONS = {
"-I",
"-L",
"-o",
"-manifest",
"--main",
"-syntax",
Expand Down Expand Up @@ -84,7 +82,8 @@
*VERBOSE_OPTIONS,
"-wxxxx",
"--version",
CLUSTER_PARAM,
CLUSTER_OPTION,
OUTPUT_FILE_OPTION,
}

RUN_OPTIONS = {
Expand Down Expand Up @@ -118,12 +117,12 @@
"--cert",
"--key",
"--cacert",
*PORT_OPTION,
PORT_OPTION,
*USER_OPTIONS,
*PASSWORD_OPTIONS,
"--wait-connect",
"--wait-read",
CLUSTER_PARAM,
JOB_NAME_PARAM,
CLUSTER_OPTION,
JOB_NAME_OPTION,
*VERBOSE_OPTIONS,
}
13 changes: 0 additions & 13 deletions src/pyhpcc/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ def __init__(self, message: str):
super().__init__(self.message)


class TypeError(Error):
"""Exception raised for type errors.
Attributes:
message:
The error message
"""

def __init__(self, message: str):
self.message = message
super().__init__(self.message)


class HPCCException(Error):
"""Exception raised for HPCC errors.
Expand Down
2 changes: 1 addition & 1 deletion src/pyhpcc/handlers/roxie_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

import pyhpcc.config as conf
from pyhpcc.errors import HPCCAuthenticationError, TypeError
from pyhpcc.errors import HPCCAuthenticationError
from pyhpcc.utils import convert_arg_to_utf8_str

log = logging.getLogger(__name__)
Expand Down
7 changes: 5 additions & 2 deletions src/pyhpcc/handlers/thor_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

import pyhpcc.config as conf
from pyhpcc.errors import HPCCAuthenticationError, TypeError
from pyhpcc.errors import HPCCAuthenticationError
from pyhpcc.utils import convert_arg_to_utf8_str

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -134,10 +134,13 @@ def execute(self):
# self.api.cached_result = True
# return result

full_url = self.api.auth.get_url() + self.path + "." + self.response_type
full_url = (
self.api.auth.get_url() + "/" + self.path + "." + self.response_type
)

# Debugging
if conf.DEBUG:
print("Came jere")
print("full_url: ", full_url)
print("self.session.params: ", self.session.params)
print("self.session.headers: ", self.session.headers)
Expand Down
Loading

0 comments on commit 4b329ce

Please sign in to comment.