Skip to content
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
5 changes: 3 additions & 2 deletions .github/workflows/check-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ jobs:
run: |
python --version
python -m pip install --upgrade pip
pip install -e .[build]
pip install -e .[test]
python -m pip install --upgrade build
pip install .
pip install .[test]
doit version
python -m build

Expand Down
18 changes: 12 additions & 6 deletions .github/workflows/generate-metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ jobs:

- name: Install App and Extras
run: |
python --version
python -m pip install --upgrade pip
python -m pip install -e .[build]
python -m pip install --upgrade build
pip install .
pip install .[test]
doit version
python -m build

- name: Generate dependencies list
- name: Run license check
run: python bin/license-checker.py

- name: Type-check
Expand All @@ -35,7 +38,10 @@ jobs:
run: black . --check

- name: Generate pyinstaller specs
run: echo Using locally generated specs
# pyi-makespec tabcmd\tabcmd.py -n tabcmd-windows -i res\tabcmd.ico -F -c --version-file versionfile.txt --onefile --collect-data tabcmd.locales &&
# pyi-makespec tabcmd\tabcmd.py -n tabcmd-mac -i res\tabcmd.icns -F -c --version-file versionfile.txt --onefile --collect-data tabcmd.locales --osx-bundle-identifier com.tableau.tabcmd
# 3. Unix
run: |
echo "Using manually generated specs"

# todo: add hidden dependencies to these command lines
# pyi-makespec tabcmd\tabcmd.py -n tabcmd-windows -i res\tabcmd.ico -F -c --version-file versionfile.txt --onefile --collect-data tabcmd.locales
# pyi-makespec tabcmd\tabcmd.py -n tabcmd-mac -i res\tabcmd.icns -F -c --version-file versionfile.txt --onefile --collect-data tabcmd.locales --osx-bundle-identifier com.tableau.tabcmd
# 3. Unix
14 changes: 8 additions & 6 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ jobs:
TARGET: windows
CMD_BUILD: >
pyinstaller tabcmd-windows.spec --clean --noconfirm --distpath ./dist/windows
OUT_FILE_NAME: tabcmd.exe
OUT_FILE_NAME: tabcmd-windows.exe
ASSET_MIME: application/vnd.microsoft.portable-executable
- os: macos-latest
TARGET: macos
CMD_BUILD: >
pyinstaller tabcmd-mac.spec --clean --noconfirm --distpath ./dist/macos &&
cwd && ls && ls dist
pyinstaller tabcmd-mac.spec --clean --noconfirm --distpath ./dist/macos && ls && ls dist
# zip -r9 mac tabcmd-mac*
OUT_FILE_NAME: tabcmd-mac.app # tabcmd.zip
ASSET_MIME: application/zip
Expand All @@ -54,8 +53,11 @@ jobs:

- name: Install dependencies and build
run: |
pip install -e .[build]
pip install -e .[package]
python --version
python -m pip install --upgrade pip
python -m pip install --upgrade build
pip install .
pip install .[test]
doit version
python -m build

Expand All @@ -66,7 +68,7 @@ jobs:
uses: WebFreak001/upload-asset@v1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # automatically provided by github actions
OS: windows # just a variable we use in the name pattern
OS: windows # a variable we use in the name pattern?
with:
file: ./dist/${{ matrix.TARGET }}/tabcmd/${{ matrix.OUT_FILE_NAME}}
mime: ${{ matrix.ASSET_MIME}} # required by GitHub API
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ jobs:
python-version: 3.8
- name: Build dist files
run: |
pip install -e .[build]
python --version
python -m pip install --upgrade pip
python -m pip install --upgrade build
pip install .
pip install .[package]
doit version
python -m build
- name: Publish distribution 📦 to Test PyPI
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/run-e2-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ jobs:
run: |
python --version
python -m pip install --upgrade pip
pip install -e .[build]
pip install -e .[test]
python -m pip install --upgrade build
pip install .
pip install .[test]
doit version
python -m build

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ jobs:
run: |
python --version
python -m pip install --upgrade pip
pip install -e .[build]
pip install -e .[test]
python -m pip install --upgrade build
pip install .
pip install .[test]
doit version
python -m build

Expand Down
68 changes: 67 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
[build-system]
requires = ["build", "setuptools>=62", "wheel", "setuptools_scm>=6.2"]
build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
"local_scheme"= "no-local-version" # require pypi supported versions always
local_scheme = "no-local-version" # require pypi supported versions always
[tool.setuptools]
packages = ["tabcmd"]
[tool.setuptools.package-data]
tabcmd = ["tabcmd.locales/**/*.mo"]
[tool.black]
line-length = 120
target-version = ['py37', 'py38', 'py39', 'py310']
extend-exclude = '^/bin/*'
[tool.mypy]
disable_error_code = [
'misc',
'import'
]
files = ["tabcmd", "tests"]
show_error_codes = true
ignore_missing_imports = true
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--junitxml=./test.junit.xml"

[project]
name="tabcmd"
dynamic = ["version"]
description="A command line client for working with Tableau Server."
authors = [{name="Tableau", email="github@tableau.com"}]
license = {file = "LICENSE"}
readme = "README.md"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10"
]
dependencies = [
'argparse',
"appdirs",
"doit",
"ftfy",
"polling2",
"pyinstaller_versionfile",
"requests>=2.11,<3.0",
"setuptools_scm",
"types-appdirs",
"types-mock",
"types-requests",
"types-setuptools",
"tableauserverclient>=0.19",
"urllib3>=1.24.3,<2.0",
]
[project.optional-dependencies]
test = [
"black",
"mock",
"mypy",
"pytest>=7.0",
"pytest-cov",
"pytest-order",
"pytest-runner",
"requests-mock>=1.0,<2.0"]
localize = ["doit", "ftfy"]
package = ["pyinstaller>=5.1"]
[project.urls]
repository = "https://github.com/tableau/tabcmd"
[project.scripts]
tabcmd = "tabcmd.tabcmd:main"
10 changes: 0 additions & 10 deletions setup.cfg

This file was deleted.

65 changes: 3 additions & 62 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,4 @@
from setuptools import setup, find_packages
# legacy stub setup.py, do not add configuration here
from setuptools import setup

setup(
name="tabcmd",
author="Tableau",
author_email="github@tableau.com",
description="A command line client for working with Tableau Server.",
long_description="A command line client for working with Tableau Server.",
license="MIT",
url="https://github.com/tableau/tabcmd",
python_requires=">=3.7",
packages=find_packages(),
package_data={"tabcmd": ["tabcmd.locales/**/*.mo"]},
include_package_data=True,
entry_points={"console_scripts": ["tabcmd = tabcmd.tabcmd:main"]},
setup_requires=[
# copy of pyproject.toml for back compat
"build",
"setuptools>=62",
"setuptools_scm>=6.2",
"wheel",
],
install_requires=[
"polling2",
"requests>=2.11,<3.0",
"tableauserverclient>=0.19",
"urllib3>=1.24.3,<2.0",
],
extras_require={
"localize": [
"doit",
"ftfy",
],
"build": [
"appdirs",
"black",
"doit",
"ftfy",
"mypy",
"pyinstaller_versionfile",
"setuptools>=62",
"setuptools_scm",
"types-appdirs",
"types-mock",
"types-requests",
"types-setuptools",
],
"package": [
"pyinstaller>=5.1",
"pyinstaller-versionfile",
],
"test": [
"mock",
"pytest",
"pytest-cov",
"pytest-order",
"pytest-runner",
"requests-mock>=1.0,<2.0",
],
},
test_suite="tests",
zip_safe=False,
)
setup()
2 changes: 1 addition & 1 deletion tabcmd-linux.spec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a = Analysis(
pathex=[],
binaries=[],
datas=datas,
hiddenimports=[],
hiddenimports=['tableauserverclient', 'requests.packages.urllib3', 'pkg_resources'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
Expand Down
2 changes: 1 addition & 1 deletion tabcmd-mac.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ a = Analysis(
pathex=[],
binaries=[],
datas=datas,
hiddenimports=[],
hiddenimports=['tableauserverclient', 'requests.packages.urllib3', 'pkg_resources'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
Expand Down
2 changes: 1 addition & 1 deletion tabcmd-windows.spec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a = Analysis(
pathex=[],
binaries=[],
datas=datas,
hiddenimports=[],
hiddenimports=['tableauserverclient', 'requests', 'pkg_resources'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
Expand Down
2 changes: 1 addition & 1 deletion tabcmd.spec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ a = Analysis(
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hiddenimports=['tableauserverclient', 'requests.packages.urllib3', 'pkg_resources'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
Expand Down
46 changes: 28 additions & 18 deletions tabcmd/execution/localize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import sys
from os import listdir
from typing import Any
from typing import Callable

Expand All @@ -20,7 +21,7 @@ def _(string_key: str) -> str:


def _identity_func(x: Any) -> Any:
return x
return "++" + x + "++"


# The client should present text in the OS language, or english if not present.
Expand All @@ -41,31 +42,40 @@ def set_client_locale(lang: str = None, logger=None) -> Callable:
for lang in locale_options:
try:
if lang:
translate = _load_language(lang, domain)
translate = _load_language(lang, domain, logger)
break
except Exception as e:
print("Failed to load language '", lang, "':", e)

return translate or _identity_func


# Handling file locations in unbundled (e.g dev) layout and when bundled by pyinstaller
"""Get absolute path to resource, works for unbundled (e.g dev) and when bundled by PyInstaller"""
# https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile/13790741#13790741
def resource_path(relative_path):
"""Get absolute path to resource, works for dev and for PyInstaller"""
base_path = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)


def _load_language(current_locale, domain):
locale_path = os.path.join("..", "locales")

# fallback=True means if loading the translated files fails, strings will be returned
# we use the identity function above instead
locale_dir = resource_path(locale_path)
language: gettext.NullTranslations = gettext.translation(
domain, locale_dir, languages=[current_locale], fallback=False
)
def define_locale_dir(logger):
try:
base_path = getattr(sys, "_MEIPASS")
except AttributeError: # sys._MEIPASS will only exist in bundled pyinstaller exe,
# in unbundled src code we take the location of the current file
# and go 2 dirs up so that the relative path /tabcmd/locales is still correct
base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..")
relative_path = os.path.join(".", "tabcmd", "locales")
locale_dir = os.path.join(base_path, relative_path)
logger.debug("Checking for language resources at " + locale_dir)
""" to debug pyinstaller file bundling, try something like this example debug line
try:
logger.debug(listdir(sys._MEIPASS))
except AttributeError as e:
logger.debug(e)
"""
print(locale_dir)
print(listdir(locale_dir))
return locale_dir


def _load_language(current_locale, domain, logger):
locale_dir = define_locale_dir(logger)
language: gettext.NullTranslations = gettext.translation(domain, locale_dir, languages=[current_locale])
language.install() # I believe this is the expensive call
_ = language.gettext
return _
Expand Down
2 changes: 1 addition & 1 deletion tabcmd/execution/logger_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
FORMATS = {
logging.ERROR: "%(asctime)s %(levelname)-5s:(%(name)-10s %(filename)-10s: %(lineno)d): %(message)-30s",
logging.WARN: "%(asctime)s %(levelname)-5s: (%(name)-10s %(filename)-10s: %(lineno)d): %(message)-30s",
logging.INFO: "%(message)-30s",
logging.INFO: "%(filename)-10s: %(message)-30s",
logging.DEBUG: "%(asctime)s %(levelname)-5s: (%(name)-10s %(filename)-10s: %(lineno)d): %(message)-30s",
}

Expand Down
Loading