Skip to content

Commit cec0fa6

Browse files
authored
Merge pull request #835 from tableau/black
Format the world with black
2 parents acbaa8c + 7443d33 commit cec0fa6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2531
-1794
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ jobs:
2525
pip install -e .[test]
2626
pip install mypy
2727
28-
- name: Lint with pycodestyle
29-
run: |
30-
pycodestyle tableauserverclient test samples
31-
3228
- name: Test with pytest
3329
run: |
3430
pytest test
31+
3532
- name: Run Mypy but allow failures
3633
run: |
3734
mypy --show-error-codes --disable-error-code misc tableauserverclient

tableauserverclient/__init__.py

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,54 @@
11
from .namespace import NEW_NAMESPACE as DEFAULT_NAMESPACE
2-
from .models import ConnectionCredentials, ConnectionItem, DataAlertItem, DatasourceItem,\
3-
GroupItem, JobItem, BackgroundJobItem, PaginationItem, ProjectItem, ScheduleItem,\
4-
SiteItem, TableauAuth, PersonalAccessTokenAuth, UserItem, ViewItem, WorkbookItem, UnpopulatedPropertyError,\
5-
HourlyInterval, DailyInterval, WeeklyInterval, MonthlyInterval, IntervalItem, TaskItem,\
6-
SubscriptionItem, Target, PermissionsRule, Permission, DatabaseItem, TableItem, ColumnItem, FlowItem, \
7-
WebhookItem, PersonalAccessTokenAuth
8-
from .server import RequestOptions, CSVRequestOptions, ImageRequestOptions, PDFRequestOptions, Filter, Sort, \
9-
Server, ServerResponseError, MissingRequiredFieldError, NotSignedInError, Pager
2+
from .models import (
3+
ConnectionCredentials,
4+
ConnectionItem,
5+
DataAlertItem,
6+
DatasourceItem,
7+
GroupItem,
8+
JobItem,
9+
BackgroundJobItem,
10+
PaginationItem,
11+
ProjectItem,
12+
ScheduleItem,
13+
SiteItem,
14+
TableauAuth,
15+
PersonalAccessTokenAuth,
16+
UserItem,
17+
ViewItem,
18+
WorkbookItem,
19+
UnpopulatedPropertyError,
20+
HourlyInterval,
21+
DailyInterval,
22+
WeeklyInterval,
23+
MonthlyInterval,
24+
IntervalItem,
25+
TaskItem,
26+
SubscriptionItem,
27+
Target,
28+
PermissionsRule,
29+
Permission,
30+
DatabaseItem,
31+
TableItem,
32+
ColumnItem,
33+
FlowItem,
34+
WebhookItem,
35+
PersonalAccessTokenAuth,
36+
)
37+
from .server import (
38+
RequestOptions,
39+
CSVRequestOptions,
40+
ImageRequestOptions,
41+
PDFRequestOptions,
42+
Filter,
43+
Sort,
44+
Server,
45+
ServerResponseError,
46+
MissingRequiredFieldError,
47+
NotSignedInError,
48+
Pager,
49+
)
1050
from ._version import get_versions
11-
__version__ = get_versions()['version']
51+
52+
__version__ = get_versions()["version"]
1253
__VERSION__ = __version__
1354
del get_versions

tableauserverclient/_version.py

Lines changed: 73 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# This file helps to compute a version number in source trees obtained from
32
# git-archive tarball (such as those provided by githubs download-from-tag
43
# feature). Distribution tarballs (built by setup.py sdist) and build
@@ -58,28 +57,28 @@ class NotThisMethod(Exception):
5857

5958
def register_vcs_handler(vcs, method): # decorator
6059
"""Decorator to mark a method as the handler for a particular VCS."""
60+
6161
def decorate(f):
6262
"""Store f in HANDLERS[vcs][method]."""
6363
if vcs not in HANDLERS:
6464
HANDLERS[vcs] = {}
6565
HANDLERS[vcs][method] = f
6666
return f
67+
6768
return decorate
6869

6970

70-
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
71-
env=None):
71+
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None):
7272
"""Call the given command(s)."""
7373
assert isinstance(commands, list)
7474
p = None
7575
for c in commands:
7676
try:
7777
dispcmd = str([c] + args)
7878
# remember shell=False, so use git.cmd on windows, not just git
79-
p = subprocess.Popen([c] + args, cwd=cwd, env=env,
80-
stdout=subprocess.PIPE,
81-
stderr=(subprocess.PIPE if hide_stderr
82-
else None))
79+
p = subprocess.Popen(
80+
[c] + args, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=(subprocess.PIPE if hide_stderr else None)
81+
)
8382
break
8483
except EnvironmentError:
8584
e = sys.exc_info()[1]
@@ -116,16 +115,19 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
116115
for i in range(3):
117116
dirname = os.path.basename(root)
118117
if dirname.startswith(parentdir_prefix):
119-
return {"version": dirname[len(parentdir_prefix):],
120-
"full-revisionid": None,
121-
"dirty": False, "error": None, "date": None}
118+
return {
119+
"version": dirname[len(parentdir_prefix) :],
120+
"full-revisionid": None,
121+
"dirty": False,
122+
"error": None,
123+
"date": None,
124+
}
122125
else:
123126
rootdirs.append(root)
124127
root = os.path.dirname(root) # up a level
125128

126129
if verbose:
127-
print("Tried directories %s but none started with prefix %s" %
128-
(str(rootdirs), parentdir_prefix))
130+
print("Tried directories %s but none started with prefix %s" % (str(rootdirs), parentdir_prefix))
129131
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
130132

131133

@@ -181,7 +183,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
181183
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
182184
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
183185
TAG = "tag: "
184-
tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
186+
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
185187
if not tags:
186188
# Either we're using git < 1.8.3, or there really are no tags. We use
187189
# a heuristic: assume all version tags have a digit. The old git %d
@@ -190,27 +192,34 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
190192
# between branches and tags. By ignoring refnames without digits, we
191193
# filter out many common branch names like "release" and
192194
# "stabilization", as well as "HEAD" and "master".
193-
tags = set([r for r in refs if re.search(r'\d', r)])
195+
tags = set([r for r in refs if re.search(r"\d", r)])
194196
if verbose:
195197
print("discarding '%s', no digits" % ",".join(refs - tags))
196198
if verbose:
197199
print("likely tags: %s" % ",".join(sorted(tags)))
198200
for ref in sorted(tags):
199201
# sorting will prefer e.g. "2.0" over "2.0rc1"
200202
if ref.startswith(tag_prefix):
201-
r = ref[len(tag_prefix):]
203+
r = ref[len(tag_prefix) :]
202204
if verbose:
203205
print("picking %s" % r)
204-
return {"version": r,
205-
"full-revisionid": keywords["full"].strip(),
206-
"dirty": False, "error": None,
207-
"date": date}
206+
return {
207+
"version": r,
208+
"full-revisionid": keywords["full"].strip(),
209+
"dirty": False,
210+
"error": None,
211+
"date": date,
212+
}
208213
# no suitable tags, so version is "0+unknown", but full hex is still there
209214
if verbose:
210215
print("no suitable tags, using unknown + full revision id")
211-
return {"version": "0+unknown",
212-
"full-revisionid": keywords["full"].strip(),
213-
"dirty": False, "error": "no suitable tags", "date": None}
216+
return {
217+
"version": "0+unknown",
218+
"full-revisionid": keywords["full"].strip(),
219+
"dirty": False,
220+
"error": "no suitable tags",
221+
"date": None,
222+
}
214223

215224

216225
@register_vcs_handler("git", "pieces_from_vcs")
@@ -225,19 +234,17 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
225234
if sys.platform == "win32":
226235
GITS = ["git.cmd", "git.exe"]
227236

228-
out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root,
229-
hide_stderr=True)
237+
out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
230238
if rc != 0:
231239
if verbose:
232240
print("Directory %s not under git control" % root)
233241
raise NotThisMethod("'git rev-parse --git-dir' returned error")
234242

235243
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
236244
# if there isn't one, this yields HEX[-dirty] (no NUM)
237-
describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty",
238-
"--always", "--long",
239-
"--match", "%s*" % tag_prefix],
240-
cwd=root)
245+
describe_out, rc = run_command(
246+
GITS, ["describe", "--tags", "--dirty", "--always", "--long", "--match", "%s*" % tag_prefix], cwd=root
247+
)
241248
# --long was added in git-1.5.5
242249
if describe_out is None:
243250
raise NotThisMethod("'git describe' failed")
@@ -260,17 +267,16 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
260267
dirty = git_describe.endswith("-dirty")
261268
pieces["dirty"] = dirty
262269
if dirty:
263-
git_describe = git_describe[:git_describe.rindex("-dirty")]
270+
git_describe = git_describe[: git_describe.rindex("-dirty")]
264271

265272
# now we have TAG-NUM-gHEX or HEX
266273

267274
if "-" in git_describe:
268275
# TAG-NUM-gHEX
269-
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
276+
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
270277
if not mo:
271278
# unparseable. Maybe git-describe is misbehaving?
272-
pieces["error"] = ("unable to parse git-describe output: '%s'"
273-
% describe_out)
279+
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
274280
return pieces
275281

276282
# tag
@@ -279,10 +285,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
279285
if verbose:
280286
fmt = "tag '%s' doesn't start with prefix '%s'"
281287
print(fmt % (full_tag, tag_prefix))
282-
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
283-
% (full_tag, tag_prefix))
288+
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (full_tag, tag_prefix)
284289
return pieces
285-
pieces["closest-tag"] = full_tag[len(tag_prefix):]
290+
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
286291

287292
# distance: number of commits since tag
288293
pieces["distance"] = int(mo.group(2))
@@ -293,13 +298,11 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
293298
else:
294299
# HEX: no tags
295300
pieces["closest-tag"] = None
296-
count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
297-
cwd=root)
301+
count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], cwd=root)
298302
pieces["distance"] = int(count_out) # total number of commits
299303

300304
# commit date: see ISO-8601 comment in git_versions_from_keywords()
301-
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
302-
cwd=root)[0].strip()
305+
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip()
303306
pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
304307

305308
return pieces
@@ -330,8 +333,7 @@ def render_pep440(pieces):
330333
rendered += ".dirty"
331334
else:
332335
# exception #1
333-
rendered = "0+untagged.%d.g%s" % (pieces["distance"],
334-
pieces["short"])
336+
rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
335337
if pieces["dirty"]:
336338
rendered += ".dirty"
337339
return rendered
@@ -445,11 +447,13 @@ def render_git_describe_long(pieces):
445447
def render(pieces, style):
446448
"""Render the given version pieces into the requested style."""
447449
if pieces["error"]:
448-
return {"version": "unknown",
449-
"full-revisionid": pieces.get("long"),
450-
"dirty": None,
451-
"error": pieces["error"],
452-
"date": None}
450+
return {
451+
"version": "unknown",
452+
"full-revisionid": pieces.get("long"),
453+
"dirty": None,
454+
"error": pieces["error"],
455+
"date": None,
456+
}
453457

454458
if not style or style == "default":
455459
style = "pep440" # the default
@@ -469,9 +473,13 @@ def render(pieces, style):
469473
else:
470474
raise ValueError("unknown style '%s'" % style)
471475

472-
return {"version": rendered, "full-revisionid": pieces["long"],
473-
"dirty": pieces["dirty"], "error": None,
474-
"date": pieces.get("date")}
476+
return {
477+
"version": rendered,
478+
"full-revisionid": pieces["long"],
479+
"dirty": pieces["dirty"],
480+
"error": None,
481+
"date": pieces.get("date"),
482+
}
475483

476484

477485
def get_versions():
@@ -485,8 +493,7 @@ def get_versions():
485493
verbose = cfg.verbose
486494

487495
try:
488-
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
489-
verbose)
496+
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
490497
except NotThisMethod:
491498
pass
492499

@@ -495,13 +502,16 @@ def get_versions():
495502
# versionfile_source is the relative path from the top of the source
496503
# tree (where the .git directory might live) to this file. Invert
497504
# this to find the root from __file__.
498-
for i in cfg.versionfile_source.split('/'):
505+
for i in cfg.versionfile_source.split("/"):
499506
root = os.path.dirname(root)
500507
except NameError:
501-
return {"version": "0+unknown", "full-revisionid": None,
502-
"dirty": None,
503-
"error": "unable to find root of source tree",
504-
"date": None}
508+
return {
509+
"version": "0+unknown",
510+
"full-revisionid": None,
511+
"dirty": None,
512+
"error": "unable to find root of source tree",
513+
"date": None,
514+
}
505515

506516
try:
507517
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
@@ -515,6 +525,10 @@ def get_versions():
515525
except NotThisMethod:
516526
pass
517527

518-
return {"version": "0+unknown", "full-revisionid": None,
519-
"dirty": None,
520-
"error": "unable to compute version", "date": None}
528+
return {
529+
"version": "0+unknown",
530+
"full-revisionid": None,
531+
"dirty": None,
532+
"error": "unable to compute version",
533+
"date": None,
534+
}

tableauserverclient/filesys_helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
2-
ALLOWED_SPECIAL = (' ', '.', '_', '-')
2+
3+
ALLOWED_SPECIAL = (" ", ".", "_", "-")
34

45

56
def to_filename(string_to_sanitize):
@@ -37,10 +38,10 @@ def get_file_type(file):
3738

3839
# This reference lists magic file signatures: https://www.garykessler.net/library/file_sigs.html
3940
MAGIC_BYTES = {
40-
'zip': bytes.fromhex("504b0304"),
41-
'tde': bytes.fromhex("20020162"),
42-
'xml': bytes.fromhex("3c3f786d6c20"),
43-
'hyper': bytes.fromhex("487970657208000001000000")
41+
"zip": bytes.fromhex("504b0304"),
42+
"tde": bytes.fromhex("20020162"),
43+
"xml": bytes.fromhex("3c3f786d6c20"),
44+
"hyper": bytes.fromhex("487970657208000001000000"),
4445
}
4546

4647
# Peek first bytes of a file

0 commit comments

Comments
 (0)