Skip to content

Commit

Permalink
chore: Use Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Sep 17, 2024
1 parent 5943cee commit 8e3a87e
Show file tree
Hide file tree
Showing 9 changed files with 640 additions and 699 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@ jobs:
linting:

runs-on: ubuntu-latest
strategy:
matrix:
# Only lint using the primary version used for dev
python-version: ["3.9"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: 3.x
- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry==1.2.*
pip install poetry==1.8.*
- name: Install dependencies
run: |
poetry install
Expand All @@ -37,7 +32,7 @@ jobs:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -47,7 +42,7 @@ jobs:
- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry==1.2.*
pip install poetry==1.8.*
- name: Clone Hub repository
uses: actions/checkout@v3
with:
Expand Down
15 changes: 7 additions & 8 deletions hub_utils/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from copy import copy
from datetime import datetime
from enum import Enum
from typing import List, Optional

import requests
import typer
Expand Down Expand Up @@ -82,7 +81,7 @@ class YamlLint(str, Enum):


@app.command()
def yamllint(action: YamlLint, paths: Optional[List[str]] = None):
def yamllint(action: YamlLint, paths: list[str] | None = None):
"""
Run yamllint on all yamls in the hub or a specific path.
"""
Expand All @@ -97,7 +96,7 @@ def yamllint(action: YamlLint, paths: Optional[List[str]] = None):


@app.command()
def add(repo_url: str = None, auto_accept: bool = typer.Option(False)):
def add(repo_url: str | None = None, auto_accept: bool = typer.Option(False)):
"""
Add a new tap or target to the hub.
It will prompt you for any attributes that need input.
Expand Down Expand Up @@ -160,8 +159,8 @@ def add(repo_url: str = None, auto_accept: bool = typer.Option(False)):

@app.command()
def update_definition(
repo_url: str = None,
plugin_name: str = None,
repo_url: str | None = None,
plugin_name: str | None = None,
auto_accept: bool = typer.Option(False),
):
"""
Expand Down Expand Up @@ -240,7 +239,7 @@ def get_variant_names(
hub_root: str,
metadata_type: str = typer.Option("sdk"),
# comma separated list
plugin_type: str = None,
plugin_type: str | None = None,
skip: int = 0,
limit: int = 10000,
):
Expand Down Expand Up @@ -332,7 +331,7 @@ def upload_airbyte(
@app.command()
def download_metadata(
local_path: str,
variant_path_list: str = None,
variant_path_list: str | None = None,
all_sdk: bool = True,
ignore_list_str: str = "",
):
Expand Down Expand Up @@ -367,7 +366,7 @@ def download_metadata(
def merge_metadata(
hub_root: str,
local_path: str,
variant_path_list: str = None,
variant_path_list: str | None = None,
all_sdk: bool = True,
):
"""
Expand Down
20 changes: 10 additions & 10 deletions hub_utils/meltano_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ def get_cwd():
@staticmethod
def add(plugin_name, namespace, executable, pip_url, plugin_type):
python_version = subprocess.run(
"which python".split(" "), stdout=subprocess.PIPE, universal_newlines=True
"which python".split(" "), stdout=subprocess.PIPE, text=True
).stdout.replace("\n", "")
subprocess.run(
f"pipx uninstall {plugin_name}".split(" "),
stdout=subprocess.PIPE,
universal_newlines=True,
text=True,
)
subprocess.run(
f"pipx install {pip_url} --python {python_version}".split(" "),
stdout=subprocess.PIPE,
universal_newlines=True,
text=True,
check=True,
)

Expand All @@ -40,14 +40,14 @@ def help_test(plugin_name, config=None):
subprocess.run(
f"{plugin_name} --help --config {tmp.name}".split(" "),
stdout=subprocess.PIPE,
universal_newlines=True,
text=True,
check=True,
)
else:
subprocess.run(
f"{plugin_name} --help".split(" "),
stdout=subprocess.PIPE,
universal_newlines=True,
text=True,
check=True,
)

Expand All @@ -62,7 +62,7 @@ def sdk_about(plugin_name, config=None):
" "
),
stdout=subprocess.PIPE,
universal_newlines=True,
text=True,
check=True,
)
about_json_str = about_content.stdout.split("Setup Instructions:")[0]
Expand All @@ -71,7 +71,7 @@ def sdk_about(plugin_name, config=None):
about_content = subprocess.run(
f"{plugin_name} --about --format=json".split(" "),
stdout=subprocess.PIPE,
universal_newlines=True,
text=True,
check=True,
)
return json.loads(about_content.stdout)
Expand Down Expand Up @@ -174,10 +174,10 @@ def _parse_kind(kind, settings, format=None):
or format == "airbyte_secret"
):
return "password", None
if settings.get("enum"):
if allowed_values := settings.get("enum"):
option_parsed = [
{"label": MeltanoUtil._get_label(val), "value": val}
for val in settings.get("enum")
for val in allowed_values
]
return "options", option_parsed
return "string", None
Expand Down Expand Up @@ -254,7 +254,7 @@ def _handle_description(description, name, enforce_desc):
@staticmethod
def _get_kind_from_type(type, name, enforce_desc):
if isinstance(type, list):
kind = [s_type for s_type in type if s_type != "null"][0]
kind = next(s_type for s_type in type if s_type != "null")
else:
kind = type

Expand Down
4 changes: 2 additions & 2 deletions hub_utils/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def download_latest(self, bucket, prefix, local_file_path):
for obj in objs
]
)[-1]
latest_name = [
latest_name = next(
obj["Key"] for obj in objs if obj["Key"].endswith(f"{latest}.json")
][0]
)
Path(os.path.dirname(local_file_path)).mkdir(parents=True, exist_ok=True)
self._client.download_file(bucket, latest_name, local_file_path)
22 changes: 13 additions & 9 deletions hub_utils/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def get_variant_names(self, plugin_type, metadata_type, skip=0, limit=10000):
if "airbyte_protocol" not in data.get("keywords", []):
continue
suffix = "/".join(yaml_file.split("/")[-3:])
image_name = [
image_name = next(
setting.get("value")
for setting in data.get("settings")
if setting.get("name") == "airbyte_spec.image"
][0]
)
if not image_name:
continue
formatted_output.append(
Expand Down Expand Up @@ -125,12 +125,12 @@ def _write_dict(self, path, content):
json.dump(content, f)

def _read_yaml(self, path):
with open(path, "r") as f:
with open(path) as f:
data = self.yaml.load(f)
return data

def _read_json(self, path):
with open(path, "r") as f:
with open(path) as f:
data = json.load(f)
return data

Expand Down Expand Up @@ -388,7 +388,7 @@ def _install_test(plugin_name, plugin_type, pip_url, namespace, executable):
MeltanoUtil.add(plugin_name, namespace, executable, pip_url, plugin_type)
MeltanoUtil.help_test(executable)

def add(self, repo_url: str = None, definition_seed: dict = None):
def add(self, repo_url: str | None = None, definition_seed: dict | None = None):
plugin_name = self._prompt("plugin name", self._get_plugin_name(repo_url))
plugin_type = self._prompt("plugin type", self.get_plugin_type(repo_url))
pip_url = self._prompt("pip_url", f"git+{repo_url}.git")
Expand Down Expand Up @@ -440,7 +440,11 @@ def add(self, repo_url: str = None, definition_seed: dict = None):
print(definition_path)
print(f"Adds {plugin_type} {plugin_name} ({variant})\n\n")

def add_airbyte(self, definition_seed: dict = None, enforce_desc: bool = True):
def add_airbyte(
self,
definition_seed: dict | None = None,
enforce_desc: bool = True,
):
repo_url = "https://github.com/meltanolabs/tap-airbyte-wrapper"
plugin_name = self._prompt("plugin name", "tap-<source/x>")
plugin_type = "extractors"
Expand Down Expand Up @@ -496,7 +500,7 @@ def add_airbyte(self, definition_seed: dict = None, enforce_desc: bool = True):
print(f"Adds {plugin_type} {plugin_name} ({variant})\n\n")

def delete_rows(self, repo_urls_to_delete, edit_path, csv_path):
with open(csv_path, "r") as inp, open(edit_path, "w") as out:
with open(csv_path) as inp, open(edit_path, "w") as out:
writer = csv.writer(out)
for row in csv.reader(inp):
if row[0] in repo_urls_to_delete:
Expand Down Expand Up @@ -643,7 +647,7 @@ def _update_base(self, repo_url, plugin_name, is_meltano_sdk=False):
)
return repo_url, plugin_name, plugin_type, plugin_variant, existing_def, sdk_def

def update(self, repo_url: str = None, plugin_name: str = None):
def update(self, repo_url: str | None = None, plugin_name: str | None = None):
(
repo_url,
plugin_name,
Expand Down Expand Up @@ -676,7 +680,7 @@ def update(self, repo_url: str = None, plugin_name: str = None):
self._write_updated_def(plugin_name, plugin_variant, plugin_type, new_def)
print(f"\nUpdates {plugin_type} {plugin_name} ({plugin_variant})\n\n")

def update_sdk(self, repo_url: str = None, plugin_name: str = None):
def update_sdk(self, repo_url: str | None = None, plugin_name: str | None = None):
(
repo_url,
plugin_name,
Expand Down
4 changes: 2 additions & 2 deletions hub_utils/yaml_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
yaml.default_flow_style = False


def insert_newlines(string, every=160):
def insert_newlines(string: str, every: int = 160) -> str:
# TODO: this is not working because editing strings causes them
# to get wrapped in double quotes which looks ugly.
return string
Expand Down Expand Up @@ -79,7 +79,7 @@ def fix_yaml(yml_path):
overwriting the existing contents.
"""
print(f"Fixing: {yml_path}")
with open(yml_path, "r") as plugin_file:
with open(yml_path) as plugin_file:
plugin_data = yaml.load(plugin_file)
with open(yml_path, "w") as plugin_file:
updated_dict = plugin_data
Expand Down
Loading

0 comments on commit 8e3a87e

Please sign in to comment.