Skip to content

Commit

Permalink
Add linter file to help with local development (#72)
Browse files Browse the repository at this point in the history
* Add PyLint file to help with local dev

* Adding ruff config file and removing pylintrc

* Fixing basic issues with ruff

* remove unused var

* more ruff changes

* Update formatting and set default python version to minimum

* Add more rules

* formatting with ruff

* Do not format raw objects + skip formatting for long html strings

* ignore ruff config + other git files when packaging plugin

* Revert "ignore ruff config + other git files when packaging plugin"

This reverts commit 887738f.
  • Loading branch information
vrutz authored Jun 21, 2024
1 parent 00d48d0 commit 02be2c1
Show file tree
Hide file tree
Showing 26 changed files with 924 additions and 707 deletions.
62 changes: 62 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

# Same as Black.
line-length = 150
indent-width = 4

# Assume Python 3.7
target-version = "py37"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and pycodestyle (`E`) codes by default.
select = ["E", "F"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
30 changes: 17 additions & 13 deletions python-clusters/attach-eks-cluster/cluster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os, sys, json, subprocess, time, logging, yaml
import os
import json
import yaml

import dku_utils.tools_version
from dataiku.cluster import Cluster
Expand All @@ -9,6 +11,7 @@
from dku_utils.config_parser import get_region_arg
from dku_utils.tools_version import get_kubectl_version, kubectl_should_use_beta_apiVersion


class MyCluster(Cluster):
def __init__(self, cluster_id, cluster_name, config, plugin_config, global_settings):
self.cluster_id = cluster_id
Expand All @@ -19,24 +22,24 @@ def __init__(self, cluster_id, cluster_name, config, plugin_config, global_setti

def start(self):
dku_utils.tools_version.check_versions()
cluster_id = self.config['clusterId']
cluster_id = self.config["clusterId"]

# retrieve the cluster info from EKS
# this will fail if the cluster doesn't exist, but the API message is enough

connection_info = get_connection_info(self.config)
args = ['get', 'cluster']
args = args + ['--name', cluster_id]

args = ["get", "cluster"]
args = args + ["--name", cluster_id]

args = args + get_region_arg(connection_info)
args = args + ['-o', 'json']
args = args + ["-o", "json"]

c = EksctlCommand(args, connection_info)
cluster_info = json.loads(c.run_and_get_output())[0]

kubectl_version = get_kubectl_version()
apiVersion_to_use = 'v1beta1' if kubectl_should_use_beta_apiVersion(kubectl_version) else 'v1alpha1'
apiVersion_to_use = "v1beta1" if kubectl_should_use_beta_apiVersion(kubectl_version) else "v1alpha1"

kube_config_str = """
apiVersion: v1
Expand Down Expand Up @@ -64,14 +67,15 @@ def start(self):
- %s
command: aws-iam-authenticator
env: null
""" % (cluster_info['CertificateAuthority']['Data'], cluster_info['Endpoint'], apiVersion_to_use, cluster_id)
kube_config_str = kube_config_str.replace("__CLUSTER_ID__", cluster_id) # cluster_id is as good as anything, since this kubeconfig won't be merged into another one
""" % (cluster_info["CertificateAuthority"]["Data"], cluster_info["Endpoint"], apiVersion_to_use, cluster_id)
# cluster_id is as good as anything, since this kubeconfig won't be merged into another one
kube_config_str = kube_config_str.replace("__CLUSTER_ID__", cluster_id)

# build the config file for kubectl
# we don't add the context to the main config file, to not end up with an oversized config,
# and because 2 different clusters could be concurrently editing the config file
kube_config_path = os.path.join(os.getcwd(), 'kube_config')
with open(kube_config_path, 'w') as f:
kube_config_path = os.path.join(os.getcwd(), "kube_config")
with open(kube_config_path, "w") as f:
f.write(kube_config_str)

setup_creds_env(kube_config_path, connection_info, self.config)
Expand All @@ -80,7 +84,7 @@ def start(self):

# collect and prepare the overrides so that DSS can know where and how to use the cluster
overrides = make_overrides(self.config, kube_config, kube_config_path)
return [overrides, {'kube_config_path':kube_config_path, 'cluster':cluster_info}]
return [overrides, {"kube_config_path": kube_config_path, "cluster": cluster_info}]

def stop(self, data):
pass
Loading

0 comments on commit 02be2c1

Please sign in to comment.