Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(restapi): added signature analysis workflow endpoint & tests #719

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ select = B,C,E,F,W,B9
ignore = E203,E302,E501,W503,B905,B907,B909
per-file-ignores =
examples/*/src/*.py:E402
tests/unit/restapi/v1/signature_analysis/test*.py:F821,F401,B006,B950,E402
extend-exclude =
.ipynb_checkpoints
alembic
Empty file modified examples/DEPRECATED-pytorch-detectron2-demo/src/poison_train.py
100755 → 100644
Empty file.
Empty file modified examples/DEPRECATED-pytorch-detectron2-demo/src/test.py
100755 → 100644
Empty file.
Empty file modified examples/DEPRECATED-pytorch-detectron2-demo/src/train.py
100755 → 100644
Empty file.
39 changes: 39 additions & 0 deletions src/dioptra/client/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
T = TypeVar("T")

JOB_FILES_DOWNLOAD: Final[str] = "jobFilesDownload"
SIGNATURE_ANALYSIS: Final[str] = "signatureAnalysis"


class WorkflowsCollectionClient(CollectionClient[T]):
Expand Down Expand Up @@ -86,3 +87,41 @@ def download_job_files(
return self._session.download(
self.url, JOB_FILES_DOWNLOAD, output_path=job_files_path, params=params
)

def signature_analysis_contents(
self, fileContents: str, filename: str = "something.py"
) -> T:
"""
Requests signature analysis for the functions in an annotated python file.

Args:
fileContents: The contents of the python file.
filename: The name of the file.

Returns:
The response from the Dioptra API.

"""
return self._session.post(
self.url,
SIGNATURE_ANALYSIS,
json_={"filename": filename, "fileContents": fileContents},
)

def signature_analysis_file(self, filename: str) -> T:
"""
Reads a file, and then requests signature analysis for the
functions in an annotated python file.

Args:
filename: The name of the file.

Returns:
The response from the Dioptra API.

"""
with open(filename, "r+") as f:
contents = f.read()
return self.signature_analysis_contents(
fileContents=contents, filename=filename
)
16 changes: 16 additions & 0 deletions src/dioptra/restapi/v1/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This Software (Dioptra) is being made available as a public service by the
# National Institute of Standards and Technology (NIST), an Agency of the United
# States Department of Commerce. This software was developed in part by employees of
# NIST and in part by NIST contractors. Copyright in portions of this software that
# were developed by NIST contractors has been licensed or assigned to NIST. Pursuant
# to Title 17 United States Code Section 105, works of NIST employees are not
# subject to copyright protection in the United States. However, NIST may hold
# international copyright in software created by its employees and domestic
# copyright (or licensing rights) in portions of software that were assigned or
# licensed to NIST. To the extent that NIST holds copyright in this software, it is
# being made available under the Creative Commons Attribution 4.0 International
# license (CC BY 4.0). The disclaimers of the CC BY 4.0 license apply to all parts
# of the software developed or licensed by NIST.
#
# ACCESS THE FULL CC BY 4.0 LICENSE HERE:
# https://creativecommons.org/licenses/by/4.0/legalcode
Loading
Loading