Skip to content

refactor: Code cleanup and linting #170

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

Merged
merged 6 commits into from
Nov 19, 2020
Merged
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
6 changes: 4 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[flake8]
ignore = E501, F821
ignore = E501, F821, W504, W605, E303
show-source = True

count = True
statistics = True
max-line-length=127
3 changes: 1 addition & 2 deletions .github/workflows/ci-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ jobs:
run: poetry install

- name: Lint
continue-on-error: true
run: |
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

Expand Down
12 changes: 3 additions & 9 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath('..'))

# -- General configuration ------------------------------------------------

Expand All @@ -30,7 +30,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.linkcode' ]
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.linkcode']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down Expand Up @@ -76,7 +76,6 @@
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
Expand All @@ -95,13 +94,11 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'python-sdc-clientdoc'


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
Expand Down Expand Up @@ -130,7 +127,6 @@
u'Sysdig Inc.', 'manual'),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
Expand All @@ -140,7 +136,6 @@
[author], 1)
]


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
Expand All @@ -159,13 +154,12 @@ def find_line():
for part in info['fullname'].split('.'):
obj = getattr(obj, part)
import inspect
fn = inspect.getsourcefile(obj)
source, lineno = inspect.findsource(obj)
return lineno + 1

if domain != 'py' or not info['module']:
return None
#tag = 'master' if 'dev' in release else ('v' + release)
# tag = 'master' if 'dev' in release else ('v' + release)
url = "https://github.com/draios/python-sdc-client/blob/master/sdcclient/_client.py"
try:
return url + '#L%d' % find_line()
Expand Down
8 changes: 2 additions & 6 deletions examples/dashboard_backup_v1_restore_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
# Parse arguments
#
if len(sys.argv) != 5:
print((
'usage: %s <sysdig-v1-url> <sysdig-v1-token> <sysdig-v2-url> <sysdig-v2-token>'
% sys.argv[0]))
print(
'You can find your token at https://app.sysdigcloud.com/#/settings/user'
)
print(f'usage: {sys.argv[0]} <sysdig-v1-url> <sysdig-v1-token> <sysdig-v2-url> <sysdig-v2-token>')
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
sys.exit(1)

sdc_v1_url = sys.argv[1]
Expand Down
4 changes: 2 additions & 2 deletions examples/delete_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import getopt
import sys

from sdcclient import SdcClient, SdMonitorClient
from sdcclient import SdMonitorClient


#
# Parse arguments
#
from sdcclient.monitor import EventsClientV2


def usage():
Expand Down
6 changes: 3 additions & 3 deletions examples/get_data_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@
#
# Print table headers
#
dataToPrint = ' '.join([str(x['id']).ljust(colLen) if len(str(x['id'])) < colLen else str(x['id'])[
:(colLen - 3)].ljust(
colLen - 3) + '...' for x in metrics])
dataToPrint = ' '.join(
[str(x['id']).ljust(colLen) if len(str(x['id'])) < colLen else str(x['id'])[:(colLen - 3)].ljust(
colLen - 3) + '...' for x in metrics])
print(('%s %s' % ('timestamp'.ljust(colLen), dataToPrint) if sampling > 0 else dataToPrint))
print('')

Expand Down
10 changes: 5 additions & 5 deletions examples/get_secure_policy_events_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
# UNSUPPORTED: This script is unsupported as it is only an example from an old API version.
# ===========================================================================================

import os
import sys
import getopt
import json
import operator
import re
import getopt
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
import sys

from sdcclient.secure import PolicyEventsClientOld


def usage():
print('usage: %s [-s|--summarize] [-l|--limit <limit>] <sysdig-token> [<duration sec>|<from sec> <to sec>]' % sys.argv[0])
print('usage: %s [-s|--summarize] [-l|--limit <limit>] <sysdig-token> [<duration sec>|<from sec> <to sec>]' %
sys.argv[0])
print('-s|--summarize: group policy events by sanitized output and print by frequency')
print('-l|--limit: with -s, only print the first <limit> outputs')
print('You can find your token at https://secure.sysdig.com/#/settings/user')
Expand Down
3 changes: 1 addition & 2 deletions examples/list_access_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
# have Admin rights.
#

import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))

from sdcclient import SdcClient

#
Expand Down
4 changes: 2 additions & 2 deletions examples/restore_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@
print(res)
sys.exit(1)

print(('All Alerts in ' + alerts_dump_file + ' restored successfully ('
+ str(created_count) + ' created, ' + str(updated_count) + ' updated)'))
print(f'All Alerts in {alerts_dump_file} restored successfully '
f'({str(created_count)} created, {str(updated_count)} updated)')
29 changes: 18 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions sdcclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from sdcclient._monitor import SdcClient
from sdcclient._monitor import SdMonitorClient
import sdcclient.monitor as monitor
import sdcclient.secure as secure
from sdcclient._monitor import SdMonitorClient, SdcClient
from sdcclient._monitor_v1 import SdMonitorClientV1
from sdcclient._scanning import SdScanningClient
from sdcclient._secure import SdSecureClient
from sdcclient._secure_v1 import SdSecureClientV1
from sdcclient._scanning import SdScanningClient
from sdcclient.ibm_auth_helper import IbmAuthHelper
import sdcclient.secure
import sdcclient.monitor

__all__ = ["SdMonitorClient", "SdcClient", "SdMonitorClientV1", "SdScanningClient", "SdSecureClient",
"SdSecureClientV1", "IbmAuthHelper", "monitor", "secure"]
Loading