Skip to content

Commit

Permalink
Running black, and flake8, fixing flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris committed Apr 24, 2024
1 parent 215005f commit d84fd5c
Show file tree
Hide file tree
Showing 26 changed files with 537 additions and 130 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
per-file-ignores = tests/test_app.py:F841
2 changes: 1 addition & 1 deletion .github/workflows/precommit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ repos:
rev: 6.1.0
hooks:
- id: flake8
args: [ --config, pyproject.toml ]
args: [ --config, .flake8 ]
23 changes: 19 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,37 @@ repos:
- id: end-of-file-fixer
files: '\.py$'
- id: check-yaml
# Keep this unchanged for YAML files
- id: check-added-large-files
files: '\.py$'

- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
language_version: python3.12
language_version: python3.9
files: '\.py$'
args:
- --line-length=120
- --exclude=staging_service/auth2Client.py
- --exclude=import_specifications/clients/baseclient\.py

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
args:
- --config=server/pyproject.toml
- --ignore=E203 # Ignore E203 directly in the pre-commit configuration
- --ignore=E203,W503
- --max-line-length=120
- --config=.flake8
files: '\.py$'
additional_dependencies: [ flake8 ]


# - repo: https://github.com/astral-sh/ruff-pre-commit
# # Ruff version.
# rev: v0.4.1
# hooks:
# # Run the linter.
# - id: ruff
# # Run the formatter.
# - id: ruff-format
1 change: 1 addition & 0 deletions import_specifications/clients/authclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@author: [email protected]
"""

import hashlib
import threading as _threading
import time as _time
Expand Down
28 changes: 23 additions & 5 deletions import_specifications/clients/baseclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _get_token(user_id, password, auth_svc):


def _read_inifile(
file=_os.environ.get("KB_DEPLOYMENT_CONFIG", _os.environ["HOME"] + "/.kbase_config")
file=_os.environ.get("KB_DEPLOYMENT_CONFIG", _os.environ["HOME"] + "/.kbase_config"),
): # @ReservedAssignment
# Another bandaid to read in the ~/.kbase_config file if one is present
authdata = None
Expand All @@ -65,7 +65,14 @@ def _read_inifile(
# strip down whatever we read to only what is legit
authdata = {
x: config.get("authentication", x) if config.has_option("authentication", x) else None
for x in ("user_id", "token", "client_secret", "keyfile", "keyfile_passphrase", "password")
for x in (
"user_id",
"token",
"client_secret",
"keyfile",
"keyfile_passphrase",
"password",
)
}
except Exception as e:
print("Error while reading INI file {}: {}".format(file, e))
Expand Down Expand Up @@ -165,15 +172,24 @@ def __init__(
raise ValueError("Timeout value must be at least 1 second")

def _call(self, url, method, params, context=None):
arg_hash = {"method": method, "params": params, "version": "1.1", "id": str(_random.random())[2:]}
arg_hash = {
"method": method,
"params": params,
"version": "1.1",
"id": str(_random.random())[2:],
}
if context:
if type(context) is not dict:
raise ValueError("context is not type dict as required.")
arg_hash["context"] = context

body = _json.dumps(arg_hash, cls=_JSONObjectEncoder)
ret = _requests.post(
url, data=body, headers=self._headers, timeout=self.timeout, verify=not self.trust_all_ssl_certificates
url,
data=body,
headers=self._headers,
timeout=self.timeout,
verify=not self.trust_all_ssl_certificates,
)
ret.encoding = "utf-8"
if ret.status_code == 500:
Expand Down Expand Up @@ -201,7 +217,9 @@ def _get_service_url(self, service_method, service_version):
return self.url
service, _ = service_method.split(".")
service_status_ret = self._call(
self.url, "ServiceWizard.get_service_status", [{"module_name": service, "version": service_version}]
self.url,
"ServiceWizard.get_service_status",
[{"module_name": service, "version": service_version}],
)
return service_status_ret["url"]

Expand Down
65 changes: 54 additions & 11 deletions import_specifications/clients/narrative_method_store_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ def list_methods_full_info(self, params, context=None):
String, parameter "link" of type "url"
"""
return self._client.call_method(
"NarrativeMethodStore.list_methods_full_info", [params], self._service_ver, context
"NarrativeMethodStore.list_methods_full_info",
[params],
self._service_ver,
context,
)

def list_methods_spec(self, params, context=None):
Expand Down Expand Up @@ -541,7 +544,12 @@ def list_methods_spec(self, params, context=None):
"target_property" of String, parameter "target_type_transform" of
String, parameter "job_id_output_field" of String
"""
return self._client.call_method("NarrativeMethodStore.list_methods_spec", [params], self._service_ver, context)
return self._client.call_method(
"NarrativeMethodStore.list_methods_spec",
[params],
self._service_ver,
context,
)

def list_method_ids_and_names(self, params, context=None):
"""
Expand All @@ -551,7 +559,10 @@ def list_method_ids_and_names(self, params, context=None):
:returns: instance of mapping from String to String
"""
return self._client.call_method(
"NarrativeMethodStore.list_method_ids_and_names", [params], self._service_ver, context
"NarrativeMethodStore.list_method_ids_and_names",
[params],
self._service_ver,
context,
)

def list_apps(self, params, context=None):
Expand Down Expand Up @@ -598,7 +609,10 @@ def list_apps_full_info(self, params, context=None):
parameter "url" of type "url"
"""
return self._client.call_method(
"NarrativeMethodStore.list_apps_full_info", [params], self._service_ver, context
"NarrativeMethodStore.list_apps_full_info",
[params],
self._service_ver,
context,
)

def list_apps_spec(self, params, context=None):
Expand Down Expand Up @@ -643,7 +657,12 @@ def list_app_ids_and_names(self, context=None):
"""
:returns: instance of mapping from String to String
"""
return self._client.call_method("NarrativeMethodStore.list_app_ids_and_names", [], self._service_ver, context)
return self._client.call_method(
"NarrativeMethodStore.list_app_ids_and_names",
[],
self._service_ver,
context,
)

def list_types(self, params, context=None):
"""
Expand Down Expand Up @@ -692,7 +711,10 @@ def get_method_brief_info(self, params, context=None):
parameter "app_type" of String
"""
return self._client.call_method(
"NarrativeMethodStore.get_method_brief_info", [params], self._service_ver, context
"NarrativeMethodStore.get_method_brief_info",
[params],
self._service_ver,
context,
)

def get_method_full_info(self, params, context=None):
Expand Down Expand Up @@ -731,7 +753,10 @@ def get_method_full_info(self, params, context=None):
String, parameter "link" of type "url"
"""
return self._client.call_method(
"NarrativeMethodStore.get_method_full_info", [params], self._service_ver, context
"NarrativeMethodStore.get_method_full_info",
[params],
self._service_ver,
context,
)

def get_method_spec(self, params, context=None):
Expand Down Expand Up @@ -1091,7 +1116,12 @@ def get_app_brief_info(self, params, context=None):
parameter "categories" of list of String, parameter
"loading_error" of String
"""
return self._client.call_method("NarrativeMethodStore.get_app_brief_info", [params], self._service_ver, context)
return self._client.call_method(
"NarrativeMethodStore.get_app_brief_info",
[params],
self._service_ver,
context,
)

def get_app_full_info(self, params, context=None):
"""
Expand All @@ -1112,7 +1142,12 @@ def get_app_full_info(self, params, context=None):
parameter "screenshots" of list of type "ScreenShot" -> structure:
parameter "url" of type "url"
"""
return self._client.call_method("NarrativeMethodStore.get_app_full_info", [params], self._service_ver, context)
return self._client.call_method(
"NarrativeMethodStore.get_app_full_info",
[params],
self._service_ver,
context,
)

def get_app_spec(self, params, context=None):
"""
Expand Down Expand Up @@ -2463,7 +2498,10 @@ def load_widget_java_script(self, params, context=None):
:returns: instance of String
"""
return self._client.call_method(
"NarrativeMethodStore.load_widget_java_script", [params], self._service_ver, context
"NarrativeMethodStore.load_widget_java_script",
[params],
self._service_ver,
context,
)

def register_repo(self, params, context=None):
Expand Down Expand Up @@ -2495,4 +2533,9 @@ def push_repo_to_tag(self, params, context=None):
two values: 'beta' or 'release'.) -> structure: parameter
"module_name" of String, parameter "tag" of String
"""
return self._client.call_method("NarrativeMethodStore.push_repo_to_tag", [params], self._service_ver, context)
return self._client.call_method(
"NarrativeMethodStore.push_repo_to_tag",
[params],
self._service_ver,
context,
)
19 changes: 14 additions & 5 deletions import_specifications/generate_import_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,30 @@
def parse_args():
parser = argparse.ArgumentParser(description="Generate a bulk import template for an app")
parser.add_argument(
"app_id", help="The app ID to process, for example kb_uploadmethods/import_sra_as_reads_from_staging"
"app_id",
help="The app ID to process, for example kb_uploadmethods/import_sra_as_reads_from_staging",
)
parser.add_argument(
"data_type",
help="The datatype corresponding to the the app. This id is shared between the "
+ "staging service and the narrative, for example sra_reads",
help="The datatype corresponding to the the app."
+ "This id is shared between the staging service and the narrative, for example sra_reads",
)
parser.add_argument(
"--tsv",
action="store_true",
help="Create a TSV file rather than a CSV file (the default)",
)
parser.add_argument("--tsv", action="store_true", help="Create a TSV file rather than a CSV file (the default)")
parser.add_argument(
"--env",
choices=["prod", "appdev", "next", "ci"],
default="prod",
help="The KBase environment to query, default prod",
)
parser.add_argument("--print-spec", action="store_true", help="Print the input specification for the app to stderr")
parser.add_argument(
"--print-spec",
action="store_true",
help="Print the input specification for the app to stderr",
)
return parser.parse_args()


Expand Down
9 changes: 0 additions & 9 deletions pyproject.toml

This file was deleted.

6 changes: 5 additions & 1 deletion scripts/prune_acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
Deletes ACLS from globus, and then clears out directories older than THRESHOLD (60) days
"""

from __future__ import print_function # for python 2

import configparser
Expand All @@ -20,7 +21,10 @@
current_time = time.time()
THRESHOLD_DAYS = 60

admin_acls = ["9cb619d0-4417-11e8-8e06-0a6d4e044368", "580118b2-dc53-11e6-9d02-22000a1e3b52"]
admin_acls = [
"9cb619d0-4417-11e8-8e06-0a6d4e044368",
"580118b2-dc53-11e6-9d02-22000a1e3b52",
]
admin_names = ["dolsonadmin", "dolson"]

config = configparser.ConfigParser()
Expand Down
5 changes: 4 additions & 1 deletion staging_service/AutoDetectUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
This class is in charge of determining possible importers by determining the suffix of the filepath pulled in,
and by looking up the appropriate mappings in the supported_apps_w_extensions.json file
"""

from typing import Optional, Tuple, Dict


class AutoDetectUtils:
_MAPPINGS = None # expects to be set by config

@staticmethod
def determine_possible_importers(filename: str) -> Tuple[Optional[list], Dict[str, object]]:
def determine_possible_importers(
filename: str,
) -> Tuple[Optional[list], Dict[str, object]]:
"""
Given a filename, come up with a reference to all possible apps.
:param filename: The filename to find applicable apps for
Expand Down
12 changes: 7 additions & 5 deletions staging_service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,13 @@ async def write_bulk_specification(request: web.Request) -> web.json_response:
if request.content_type != _APP_JSON:
# There should be a way to get aiohttp to handle this but I can't find it
return _createJSONErrorResponse(
f"Required content-type is {_APP_JSON}", error_class=web.HTTPUnsupportedMediaType
f"Required content-type is {_APP_JSON}",
error_class=web.HTTPUnsupportedMediaType,
)
if not request.content_length:
return _createJSONErrorResponse(
"The content-length header is required and must be > 0", error_class=web.HTTPLengthRequired
"The content-length header is required and must be > 0",
error_class=web.HTTPLengthRequired,
)
# No need to check the max content length; the server already does that. See tests
data = await request.json()
Expand Down Expand Up @@ -208,9 +210,9 @@ async def add_acl_concierge(request: web.Request):
aclm = AclManager()
result = aclm.add_acl_concierge(shared_directory=user_dir, concierge_path=concierge_path)
result["msg"] = f"Requesting Globus Perms for the following globus dir: {concierge_path}"
result[
"link"
] = f"https://app.globus.org/file-manager?destination_id={aclm.endpoint_id}&destination_path={concierge_path}"
result["link"] = (
f"https://app.globus.org/file-manager?destination_id={aclm.endpoint_id}&destination_path={concierge_path}"
)
return web.json_response(result)


Expand Down
1 change: 1 addition & 0 deletions staging_service/auth2Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@author: [email protected]
modified for python3 and authV2
"""

import hashlib
import time as _time

Expand Down
Loading

0 comments on commit d84fd5c

Please sign in to comment.