Skip to content

Commit

Permalink
Merge pull request #1 from TonicAI/f/ruff
Browse files Browse the repository at this point in the history
Adding ruff
  • Loading branch information
ethan-tonic authored Nov 13, 2024
2 parents 6ef40c0 + 82b78c9 commit 640721e
Show file tree
Hide file tree
Showing 36 changed files with 767 additions and 419 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Ruff
on: [push]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v1
with:
args: "check --target-version py37"
48 changes: 24 additions & 24 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx.ext.autosummary",
'sphinx.ext.autosectionlabel',
'sphinxcontrib.googleanalytics'
"sphinx.ext.autosectionlabel",
"sphinxcontrib.googleanalytics",
]
autosummary_generate = True
autosummary_generate = True
source_suffix = [".rst"]

# Napoleon settings
Expand All @@ -64,21 +64,21 @@
html_show_sourcelink = False
html_show_sphinx = False
html_theme_options = {
'analytics_anonymize_ip': False,
'logo_only': True,
'prev_next_buttons_location': 'bottom',
'style_external_links': False,
'vcs_pageview_mode': '',
'style_nav_header_background': 'white',
'flyout_display': 'hidden',
'version_selector': False,
'language_selector': True,
"analytics_anonymize_ip": False,
"logo_only": True,
"prev_next_buttons_location": "bottom",
"style_external_links": False,
"vcs_pageview_mode": "",
"style_nav_header_background": "white",
"flyout_display": "hidden",
"version_selector": False,
"language_selector": True,
# Toc options
'collapse_navigation': False,
'sticky_navigation': True,
'navigation_depth': 4,
'includehidden': True,
'titles_only': False,
"collapse_navigation": False,
"sticky_navigation": True,
"navigation_depth": 4,
"includehidden": True,
"titles_only": False,
}

extensions += []
Expand All @@ -92,12 +92,12 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_css_files = ["custom.css"]
#html_permalinks_icon = Icons.permalinks_icon
# html_permalinks_icon = Icons.permalinks_icon

# function signature
python_maximum_signature_line_length=20
python_display_short_literal_types=True
# function signature
python_maximum_signature_line_length = 20
python_display_short_literal_types = True

#google analytics
googleanalytics_id='G-F8WSWZQ7PC'
googleanalytics_enabled=True
# google analytics
googleanalytics_id = "G-F8WSWZQ7PC"
googleanalytics_enabled = True
264 changes: 163 additions & 101 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ more-itertools = "^8.6.0"
tqdm = "^4.0.0"
amplitude-analytics = "^1.1.4"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
ruff = "^0.7.3"
pytest = "^5.2"

[build-system]
Expand Down
14 changes: 11 additions & 3 deletions tonic_textual/classes/SolarCsvConfig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
class SolarCsvConfig:
def __init__(self, num_columns, has_header=False, escape_char="\"", quote_char="\"", delimiter=",", null_char="\\N"):
def __init__(
self,
num_columns,
has_header=False,
escape_char='"',
quote_char='"',
delimiter=",",
null_char="\\N",
):
self.num_columns = num_columns
self.has_header = has_header
self.escape_char = escape_char
Expand All @@ -14,5 +22,5 @@ def to_dict(self):
"escapeChar": self.escape_char,
"quoteChar": self.quote_char,
"delimiter": self.delimiter,
"nullChar": self.null_char
}
"nullChar": self.null_char,
}
39 changes: 27 additions & 12 deletions tonic_textual/classes/azure_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from tonic_textual.classes.httpclient import HttpClient
from tonic_textual.classes.pipeline import Pipeline


class AzurePipeline(Pipeline):
"""Class to represent and provide access to a Tonic Textual Azure blob storage pipeline.
Expand All @@ -17,11 +18,11 @@ class AzurePipeline(Pipeline):
client: HttpClient
The HTTP client to use.
"""

def __init__(self, name: str, id: str, client: HttpClient):
super().__init__(name, id, client)
def set_output_location(self, container: str, prefix: Optional[str]=None):

def set_output_location(self, container: str, prefix: Optional[str] = None):
"""Sets the location in Azure blob storage where the pipeline stores processed files.
Parameters
Expand All @@ -35,7 +36,9 @@ def set_output_location(self, container: str, prefix: Optional[str]=None):
container = self.__prepare_container_name(container)
prefix = prefix or ""
output_location = container + "/" + prefix
self.client.http_patch(f'/api/parsejobconfig/{self.id}', data={'outputPath': output_location})
self.client.http_patch(
f"/api/parsejobconfig/{self.id}", data={"outputPath": output_location}
)

def add_prefixes(self, container: str, prefixes: List[str]):
"""Add prefixes to your pipeline. Textual processes all of the files under the prefix that are of supported file types.
Expand All @@ -47,10 +50,16 @@ def add_prefixes(self, container: str, prefixes: List[str]):
prefix: List[str]
The list of prefixes to include
"""

container = self.__prepare_container_name(container)
path_prefixes = [container + "/" + prefix for prefix in prefixes if prefix is not None and len(prefix)>0]
self.client.http_patch(f'/api/parsejobconfig/{self.id}', data={'pathPrefixes': path_prefixes})
path_prefixes = [
container + "/" + prefix
for prefix in prefixes
if prefix is not None and len(prefix) > 0
]
self.client.http_patch(
f"/api/parsejobconfig/{self.id}", data={"pathPrefixes": path_prefixes}
)

def add_files(self, container: str, file_paths: List[str]) -> str:
"""Add files to your pipeline
Expand All @@ -62,18 +71,24 @@ def add_files(self, container: str, file_paths: List[str]) -> str:
prefix: List[str]
The list of files to include
"""

container = self.__prepare_container_name(container)

selected_files = [container + "/" + path for path in file_paths if path is not None and len(path)>0]
self.client.http_patch(f'/api/parsejobconfig/{self.id}', data={'selectedFiles': selected_files})
selected_files = [
container + "/" + path
for path in file_paths
if path is not None and len(path) > 0
]
self.client.http_patch(
f"/api/parsejobconfig/{self.id}", data={"selectedFiles": selected_files}
)

def __prepare_container_name(self,container: str) -> str:
def __prepare_container_name(self, container: str) -> str:
if container.startswith("adfs://"):
return container[7:]
elif container.startswith("wasbs://"):
return container[8:]
elif container.startswith("azure://"):
return container[8:]
else:
return container
return container
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ class LabelCustomList:
The list of regexes to use when overriding entities.
"""

def __init__(self, regexes: Optional[List[str]] = None):
self.regexes = regexes if regexes is not None else []

def to_dict(self):
return {
"regexes": self.regexes
}
return {"regexes": self.regexes}
6 changes: 5 additions & 1 deletion tonic_textual/classes/common_api_responses/replacement.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ def __init__(
score=score,
language=language,
**({} if new_text is None else {"new_text": new_text}),
**({} if example_redaction is None else {"example_redaction": example_redaction}),
**(
{}
if example_redaction is None
else {"example_redaction": example_redaction}
),
**({} if json_path is None else {"json_path": json_path}),
**({} if xml_path is None else {"xml_path": xml_path}),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from typing import Optional, Dict


class SingleDetectionResult(dict):
"""A span of text that has been detected as a named entity.
Expand All @@ -20,6 +21,7 @@ class SingleDetectionResult(dict):
The JSON path of the entity in the original JSON document. This is only
present if the input text was a JSON document.
"""

def __init__(
self,
start: int,
Expand Down
Loading

0 comments on commit 640721e

Please sign in to comment.