8000 remove python 2 and workarounds · jacalata/document-api-python@c8466d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit c8466d4

Browse files
committed
remove python 2 and workarounds
1 parent cbc027b commit c8466d4

File tree

10 files changed

+63
-39
lines changed

10 files changed

+63
-39
lines changed

.github/workflows/python-package.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python package
5+
6+
on:
7+
push:
8+
paths-ignore:
9+
- 'docs/**'
10+
pull_request:
11+
branches: '*'
12+
13+
jobs:
14+
build:
15+
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python-version: [3.7, 3.8, 3.9]
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
python -m pip install pycodestyle
32+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33+
- name: Lint with pycodestyle
34+
run: |
35+
pycodestyle tableaudocumentapi test samples
36+
- name: Test
37+
run: |
38+
python setup.py test

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ language: python
22
cache: pip
33

44
python:
5-
- "2.7"
65
- "3.4"
76
- "3.5"
87
- "3.6"
9-
- "pypy"
8+
- "pypy3"
109
# command to install dependencies
1110
install:
1211
- "pip install -e ."

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ Features include:
2929
- Get all fields in use by certain sheets in a workbook
3030

3131
We don't yet support creating files from scratch, adding extracts into workbooks or data sources, or updating field information
32+
33+
34+
As of 2021, this SDK no longer supports Python 2.

publish.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ set -e
55
rm -rf dist
66
python setup.py sdist
77
python setup.py bdist_wheel
8-
python3 setup.py bdist_wheel
98
twine upload dist/*

setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
try:
2-
from setuptools import setup
3-
except ImportError:
4-
from distutils.core import setup
5-
1+
from setuptools import setup
2+
63
setup(
74
name='tableaudocumentapi',
85
version='0.6',

tableaudocumentapi/datasource.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@
99
from tableaudocumentapi.multilookup_dict import MultiLookupDict
1010
from tableaudocumentapi.xfile import xml_open
1111

12-
########
13-
# This is needed in order to determine if something is a string or not. It is necessary because
14-
# of differences between python2 (basestring) and python3 (str). If python2 support is ever
15-
# dropped, remove this and change the basestring references below to str
16-
try:
17-
basestring
18-
except NameError: # pragma: no cover
19-
basestring = str
20-
########
21-
2212
_ColumnObjectReturnTuple = collections.namedtuple('_ColumnObjectReturnTupleType', ['id', 'object'])
2313

2414

@@ -38,7 +28,7 @@ class FieldDictionary(MultiLookupDict):
3828
def used_by_sheet(self, name):
3929
# If we pass in a string, no need to get complicated, just check to see if name is in
4030
# the field's list of worksheets
41-
if isinstance(name, basestring):
31+
if isinstance(name, str):
4232
return [x for x in self.values() if name in x.worksheets]
4333

4434
# if we pass in a list, we need to check to see if any of the names in the list are in

tableaudocumentapi/xfile.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import zipfile
66
import xml.etree.ElementTree as ET
77

8-
try:
9-
from distutils2.version import NormalizedVersion as Version
10-
except ImportError:
11-
from distutils.version import LooseVersion as Version
8+
from distutils.version import LooseVersion as Version
129

1310
MIN_SUPPORTED_VERSION = Version("9.0")
1411

@@ -28,7 +25,7 @@ def xml_open(filename, expected_root=None):
2825
# Is the file a zip (.twbx or .tdsx)
2926
if zipfile.is_zipfile(filename):
3027
tree = get_xml_from_archive(filename)
31-
else:
28+
else:
3229
_register_all_namespaces()
3330
tree = ET.parse(filename)
3431

@@ -55,9 +52,11 @@ def temporary_directory(*args, **kwargs):
5552
finally:
5653
shutil.rmtree(d)
5754

58-
def _register_all_namespaces():
55+
56+
def _register_all_namespaces():
5957
# TO DO: should look at the file to find namespaces, not hardcode this one
60-
ET.register_namespace("user","http://www.tableausoftware.com/xml/user")
58+
ET.register_namespace("user", "http://www.tableausoftware.com/xml/user")
59+
6160

6261
def find_file_in_zip(zip_file):
6362
'''Returns the twb/tds file from a Tableau packaged file format. Packaged
@@ -124,9 +123,9 @@ def save_into_archive(xml_tree, filename, new_filename=None):
124123

125124

126125
def _save_file(container_file, xml_tree, new_filename=None):
127-
128-
_register_all_namespaces() # this shouldn't be necessary, should be done on open
129-
126+
127+
_register_all_namespaces() # this shouldn't be necessary, should be done on open
128+
130129
if new_filename is None:
131130
new_filename = container_file
132131

test/assets/index.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@
2727
TWBX_WITH_CACHE_FILES = os.path.join(TEST_DIR, 'Cache.twbx')
2828

2929
COMPLEX_TWB = os.path.join(TEST_DIR, 'filtering.twb')
30-

test/bvt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from tableaudocumentapi import Workbook, Datasource, Connection, ConnectionParser
77
from tableaudocumentapi.xfile import TableauInvalidFileException, TableauVersionNotSupportedException
88

9+
910
class ConnectionParserTests(unittest.TestCase):
1011

1112
def test_can_extract_legacy_connection(self):

test/test_xfile.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ def test_find_file_in_zip_no_xml_file(self):
1111
badzip = zipfile.ZipFile(BAD_ZIP_FILE)
1212
self.assertIsNone(find_file_in_zip(badzip))
1313

14-
1514
def test_only_find_twbs(self):
1615
twb_from_twbx_with_cache = zipfile.ZipFile(TWBX_WITH_CACHE_FILES)
1716
self.assertEqual(find_file_in_zip(twb_from_twbx_with_cache), 'Superstore.twb')
18-
17+
18+
1919
class Namespacing(unittest.TestCase):
2020

2121
def assertContainsUserNamespace(self, filename):
@@ -27,23 +27,23 @@ def assertContainsUserNamespace(self, filename):
2727
doc_beginning_excerpt += (in_file.readline().strip()) # first line should be xml tag
2828
lineCount += 1
2929
found = doc_beginning_excerpt.rfind("xmlns:user=")
30-
#print(doc_beginning_excerpt[found:found+10])
30+
# print(doc_beginning_excerpt[found:found+10])
3131
self.assertRegex(doc_beginning_excerpt, "xmlns:user=")
32-
32+
3333
def test_save_preserves_namespace_twb(self):
34-
filename = COMPLEX_TWB
34+
filename = COMPLEX_TWB
3535
self.assertContainsUserNamespace(filename)
3636
wb = Workbook(filename)
3737
new_name = 'saved-as-twb.twb'
3838
wb.save_as(new_name)
3939
self.assertContainsUserNamespace(new_name)
4040

41-
'''
41+
'''
4242
def demo_bug_ns_not_preserved_if_not_used(self):
4343
filename = TABLEAU_10_TDS
4444
self.assertContainsUserNamespace(filename)
4545
wb = Datasource.from_file(filename)
46-
#wb.save()
46+
#wb.save()
4747
new_name = 'saved-as-tds.tds'
4848
wb.save_as(new_name)
4949
self.assertContainsUserNamespace(new_name) <- throws
@@ -52,8 +52,7 @@ def demo_bug_ns_not_preserved_if_not_used(self):
5252
none will be added.
5353
If there is a namespace but it *is not used* in the document, it will be stripped
5454
55-
Fix will be something like
55+
Fix will be something like
5656
https://stackoverflow.com/questions/41937624/elementtree-why-are-my-namespace-declarations-stripped-out
5757
5858
'''
59-

0 commit comments

Comments
 (0)
0