Skip to content
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

Fix exit_with_error handling #137

Merged
merged 8 commits into from
Jul 8, 2022
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
10 changes: 5 additions & 5 deletions .github/workflows/check-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ jobs:

- name: Install dependencies
run: |
python --version
python -m pip install --upgrade pip
pip install -e .[install]
pip install -e .[build]
pip install -e .[test]
python setup.py build
python res/versioning.py
doit version
python setup.py build

# https://github.com/marketplace/actions/pytest-coverage-comment
Expand All @@ -42,8 +41,9 @@ jobs:
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: ./pytest-coverage.txt
# broken? Error: The head commit for this pull_request event is not ahead of the base commit.
# Please submit an issue on this action's GitHub repo
# TODO: check if this has been fixed
# Error: The head commit for this pull_request event is not ahead of the base commit.
# Please submit an issue on this action's GitHub repo
# report-only-changed-files: true

# TODO update badge on readme:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/generate-metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
doit version
python setup.py build

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

- name: Type-check
run: mypy src tests

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
required: true
type: boolean
push:
branches: main
tags: 'pypi'

jobs:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: Python tests

on:
workflow_dispatch:
push:
branches:
- development
schedule:
- cron: 0 11 * * * # Every day at 11AM UTC (7AM EST)
pull_request:
branches:
- development
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ __pycache__/
*.pytest_cache
*.pyc
*.pkl
.coverage
venv/
tabcmd-dev/
workon/

# code coverage outputs
.coverage
Expand Down
3 changes: 0 additions & 3 deletions bin/black.sh

This file was deleted.

3 changes: 0 additions & 3 deletions bin/e2e.sh

This file was deleted.

54 changes: 54 additions & 0 deletions bin/license-checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
# https://git.soma.salesforce.com/python-at-sfdc/license_checker
# Modified version of https://stackoverflow.com/a/44090218
from __future__ import print_function
from collections import defaultdict
import pkg_resources

def get_pkg_license(pkg):
try:
lines = pkg.get_metadata_lines('METADATA')
except:
lines = pkg.get_metadata_lines('PKG-INFO')

for line in lines:
if line.startswith('License:'):
return line[9:]
return '(Licence not found)'
exit()

def print_table(table):
column_index_to_max_width = defaultdict(int)
for row_index, row in enumerate(table):
for cell_index, cell in enumerate(row):
cur_max = column_index_to_max_width[cell_index]
cell_width = len(cell)
if cell_width > cur_max:
column_index_to_max_width[cell_index] = cell_width
for row_index, row in enumerate(table):
line = ''
for cell_index, cell in enumerate(row):
cell_width = column_index_to_max_width[cell_index]
line += cell.ljust(cell_width)
line += " - "
line = line.ljust(25)
line = line.rstrip(" -")
print(line)
if row_index == 0:
print("-" * len(line))


def get_directory(package_name):
return pkg_resources.working_set.find(pkg_resources.Requirement.parse(package_name)).location


def print_packages_and_licenses():
table = []
table.append(['Package', 'License', 'Location'])
for pkg in sorted(pkg_resources.working_set):
table.append([str(pkg).rjust(25)[:25], get_pkg_license(pkg)[:25], pkg.location])
print_table(table)


if __name__ == "__main__":
print_packages_and_licenses()
4 changes: 2 additions & 2 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ _(note that running mypy and black is required for code being submitted to the r
> pytest
- run tests against a live server
> python -m tabcmd login {your server info here}
> bin/e2e.sh
> pytest -q tests\e2e\online_tests.py -r pfE
- autoformat your code with black (https://pypi.org/project/black/)
> bin/black.sh
> black .
- check types
> mypy src tests
- do test coverage calculation (https://coverage.readthedocs.io/en/6.3.2)
Expand Down
70 changes: 38 additions & 32 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import ftfy
import setuptools_scm

LOCALES = [
"en", "de", "es", "fr", "ga", "it", "pt",
"sv", "ja", "ko",
"zh"]
LOCALES = ["en", "de", "es", "fr", "ga", "it", "pt", "sv", "ja", "ko", "zh"]

"""
https://pydoit.org/
Expand Down Expand Up @@ -46,8 +43,8 @@ def process_locales():
outfile.write(ftfy.fixes.decode_escapes(data))

return {
'actions': [process_locales],
'verbosity': 2,
"actions": [process_locales],
"verbosity": 2,
}


Expand All @@ -65,40 +62,48 @@ def task_po():
- 3.x, from pip install translate-toolkit:
it copies key->comment, value-> msgid, ""->msgstr which is not at all what we want
"""

def process_locales():
for current_locale in LOCALES:

LOC_PATH = "src/locales/" + current_locale
for file in glob.glob(LOC_PATH+"/*.properties"):
for file in glob.glob(LOC_PATH + "/*.properties"):
basename = os.path.basename(file).split(".")[0]
print("processing", basename)
result = subprocess.run(["python",
"bin/i18n/prop2po.py",
"--encoding", "utf-8", # for the .po header
"--language", current_locale, # for the .po header
LOC_PATH + "/"+basename+".properties",
LOC_PATH + "/LC_MESSAGES/"+basename+".po"])
result = subprocess.run(
[
"python",
"bin/i18n/prop2po.py",
"--encoding",
"utf-8", # for the .po header
"--language",
current_locale, # for the .po header
LOC_PATH + "/" + basename + ".properties",
LOC_PATH + "/LC_MESSAGES/" + basename + ".po",
]
)
print("\n", result)
# print("stdout:", result.stdout)
if not result.returncode == 0:
print("stderr:", result.stderr)

return {
'actions': [process_locales],
'verbosity': 2,
"actions": [process_locales],
"verbosity": 2,
}


def task_clean_all():
"""For all languages: removes all generated artifacts (.po, .mo) which source from properties files. """
"""For all languages: removes all generated artifacts (.po, .mo) which source from properties files."""

def process_locales():
for current_locale in LOCALES:
LOC_PATH = "src/locales/" + current_locale
for file in glob.glob(LOC_PATH+"/*.properties"):
for file in glob.glob(LOC_PATH + "/*.properties"):
basename = os.path.basename(file).split(".")[0]
print("deleting",basename + ".*")
print("deleting", basename + ".*")
try:
os.remove(LOC_PATH + "/LC_MESSAGES/"+basename+".po")
os.remove(LOC_PATH + "/LC_MESSAGES/" + basename + ".po")
except OSError:
pass
try:
Expand All @@ -111,10 +116,9 @@ def process_locales():
except OSError:
pass


return {
'actions': [process_locales],
'verbosity': 2,
"actions": [process_locales],
"verbosity": 2,
}


Expand All @@ -128,7 +132,7 @@ def process_locales():

LOC_PATH = "src/locales/" + current_locale + "/LC_MESSAGES"

with open(LOC_PATH + "/tabcmd.po", 'w+', encoding="utf-8") as outfile:
with open(LOC_PATH + "/tabcmd.po", "w+", encoding="utf-8") as outfile:
for file in glob.glob(LOC_PATH + "/*.po"):
if file.endswith("tabcmd.po"):
pass
Expand All @@ -139,8 +143,8 @@ def process_locales():
outfile.write("\n")

return {
'actions': [process_locales],
'verbosity': 2,
"actions": [process_locales],
"verbosity": 2,
}


Expand All @@ -164,14 +168,15 @@ def process_locales():
print("stderr:", result.stderr)

return {
'actions': [process_locales],
'verbosity': 2,
"actions": [process_locales],
"verbosity": 2,
}


def task_version():

""" Generates a metadata info file with current version to be bundled by pyinstaller"""
"""Generates a metadata info file with current version to be bundled by pyinstaller"""

def write_for_pyinstaller():
import pyinstaller_versionfile
import os
Expand All @@ -183,12 +188,13 @@ def write_for_pyinstaller():
output_file = os.path.join(".", "program_metadata.txt")
input_file = os.path.join("res", "metadata.yml")
pyinstaller_versionfile.create_versionfile_from_input_file(
output_file, input_file,
output_file,
input_file,
# optional, can be set to overwrite version information (equivalent to --version when using the CLI)
version=numeric_version
version=numeric_version,
)

return {
'actions': [write_for_pyinstaller],
'verbosity': 2,
"actions": [write_for_pyinstaller],
"verbosity": 2,
}
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[build-system]
requires = ["setuptools>=62", "wheel", "setuptools_scm>=6.2"]
requires = ["build", "setuptools>=62", "wheel", "setuptools_scm>=6.2"]
[tool.setuptools_scm]
"local_scheme"= "no-local-version" # require pypi supported versions always
[tool.black]
line-length = 120
extend-exclude = '^/bin/*'
Loading