Skip to content

Commit

Permalink
Merge pull request #13 from RohithSurya/features/readfile_docs_32199_…
Browse files Browse the repository at this point in the history
…32200

WIP: [#32200] Commit show command, Move ReadFile getData API calls to JSON
  • Loading branch information
amila-desilva authored Jul 17, 2024
2 parents a6440cc + c0269d3 commit 58a1d0b
Show file tree
Hide file tree
Showing 19 changed files with 1,260 additions and 811 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/pytest-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: Test Coverage
on:
push:
branches:
main
pull_request:
branches:
main
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@ dmypy.json
tests/my_secret.py

# Miscellaneous folders
Dummy/
Dummy/

docs/build
37 changes: 37 additions & 0 deletions examples/file_exists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from pyhpcc.models.auth import Auth
from pyhpcc.models.file import ReadFileInfo
from pyhpcc.models.hpcc import HPCC

# Code to check if a logical file exists

# Configurations
environment = (
"university.us-hpccsystems-dev.azure.lnrsg.io" # Eg: myuniversity.hpccsystems.io
)
port = "8010" # Eg: 8010
user_name = "dummyusername" # HPCC username
password = "dummypassword" # HPCC password
protocol = "http" # Specify HTTP or HTTPS p
cluster = "thor" # Specify the cluster name to be used
logical_file = "pyhpcc::testing::internet.csv"

try:
auth_object = Auth(
environment,
port,
user_name,
password,
protocol=protocol,
)
hpcc_object = HPCC(auth=auth_object)
read_file = ReadFileInfo(
hpcc=hpcc_object,
logical_file_name=logical_file,
cluster=cluster,
file_type="flat",
)

print(read_file.check_file_in_dfu()) # Prints `True` if file exists else `False`

except Exception as e:
print(e)
35 changes: 35 additions & 0 deletions examples/read_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pyhpcc.models.auth import Auth
from pyhpcc.models.file import ReadFileInfo
from pyhpcc.models.hpcc import HPCC

# Example illustrating how to read a logical file

# Configurations
environment = (
"university.us-hpccsystems-dev.azure.lnrsg.io" # Eg: myuniversity.hpccsystems.io
)
port = "8010" # Eg: 8010
user_name = "dummy username" # HPCC username
password = "password" # HPCC password
protocol = "http" # Specify HTTP or HTTPS p
cluster = "thor" # Specify the cluster name to be used
logical_file = "pyhpcc::em::test::emp"

try:
auth_object = Auth(
environment,
port,
user_name,
password,
protocol=protocol,
)
hpcc_object = HPCC(auth=auth_object)
read_file = ReadFileInfo(hpcc=hpcc_object, logical_file_name=logical_file)

# Retrieves all records with a `batch_size` of 2. To retrieve all records in one go, set the batch_size to a large number
for data_attr, data in read_file.get_data_iter(0, -1, 2):
print(data_attr)
print(data)

except Exception as e:
print(e)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ elementpath = "^3.0.2" # XPath selectors for XML Data structures
[tool.poetry.group.dev.dependencies]
pytest = "^7.1.3"
pytest-mock = "^3.0.2"
pytest-dependency="^0.6.0"
pre-commit="^3.7.1"

[tool.poetry.group.coverage.dependencies]
Expand Down
7 changes: 7 additions & 0 deletions src/pyhpcc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
"-v",
"--verbose",
]
RUN_UNWANTED_PATTERNS = [
r"jsocket\([0-9]+,[0-9]+\) ",
"deploying",
"Deployed",
"Running",
"Using eclcc path ",
]
MASKED_PASSWORD = "*****"
RUN_AUTH_OPTIONS = {*USER_OPTIONS, *PASSWORD_OPTIONS, *SERVER_OPTIONS, PORT_OPTION}

Expand Down
4 changes: 3 additions & 1 deletion src/pyhpcc/handlers/roxie_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from requests.models import Response

import pyhpcc.config as conf
from pyhpcc.errors import HPCCAuthenticationError
from pyhpcc.utils import convert_arg_to_utf8_str
Expand Down Expand Up @@ -145,7 +147,7 @@ def execute(self):
auth = self.api.auth.oauth

# Execute request
resp = self.session.request(
resp: Response = self.session.request(
self.method,
full_url,
data=self.post_data,
Expand Down
4 changes: 3 additions & 1 deletion src/pyhpcc/handlers/thor_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from requests.models import Response

import pyhpcc.config as conf
from pyhpcc.errors import HPCCAuthenticationError
from pyhpcc.utils import convert_arg_to_utf8_str
Expand Down Expand Up @@ -152,7 +154,7 @@ def execute(self):
if self.api.auth:
auth = self.api.auth.oauth

resp = self.session.request(
resp: Response = self.session.request(
self.method,
full_url,
data=self.data,
Expand Down
Loading

0 comments on commit 58a1d0b

Please sign in to comment.