Skip to content

Commit

Permalink
Update all dependencies and Python to the latest versions, autoformat…
Browse files Browse the repository at this point in the history
… using Black, release v1.1.0 (#48)

Closes #44
Fixes #43 and fixes #47 by way of updating PyInstaller

Co-authored-by: Pavel Kirienko <[email protected]>
  • Loading branch information
Silver Valdvee and pavel-kirienko authored Jun 20, 2022
1 parent fced366 commit 67a1f1d
Show file tree
Hide file tree
Showing 76 changed files with 5,229 additions and 2,984 deletions.
12 changes: 3 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
[submodule "kucher/libraries/popcop"]
path = kucher/libraries/popcop
url = https://github.com/Zubax/popcop
[submodule "kucher/libraries/construct"]
path = kucher/libraries/construct
url = https://github.com/construct/construct
[submodule "kucher/libraries/dataclasses"]
path = kucher/libraries/dataclasses
url = https://github.com/ericvsmith/dataclasses
[submodule "kucher/libraries/quamash"]
path = kucher/libraries/quamash
url = https://github.com/harvimt/quamash
[submodule "kucher/libraries/qasync"]
path = kucher/libraries/qasync
url = https://github.com/CabbageDevelopment/qasync.git
37 changes: 2 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Join the chat at https://gitter.im/Zubax/general](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/Zubax/general)
[![Forum](https://img.shields.io/discourse/https/forum.zubax.com/users.svg?color=e00000)](https://forum.zubax.com)

# Kucher

Expand Down Expand Up @@ -35,9 +35,7 @@ Non-conforming contributions should not be accepted.
This section describes how to configure the local system for development.
An AMD64 GNU/Linux system is required.

Kucher requires Python version 3.6 or newer.
If your system uses an older version, please refer to the section below to install
Python 3.6 before continuing.
Kucher requires Python version 3.10 or newer.

```bash
git clone --recursive https://github.com/Zubax/kucher
Expand Down Expand Up @@ -67,37 +65,6 @@ On Windows:
pytest
```


### Getting the right version of Python

Kucher requires Python 3.6 or newer.
You can check whether you have the right version by running `python3 --version`.
If a newer Python is needed, and you're running Ubuntu or an Ubuntu-based distro such as Mint,
execute the following commands:

```bash
sudo apt-get install -y git-core curl build-essential libsqlite3-dev
sudo apt-get install -y libbz2-dev libssl-dev libreadline-dev libsqlite3-dev tk-dev libpng-dev libfreetype6-dev
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
```

Follow the instructions in the output of the last command above.
**WARNING:** If the above command tells you to use `~/.bash_profile`,
disregard that and use `~/.bashrc` instead.

Reload the bash profile configuration
(e.g. close the current shell session and open a new one).
Then continue:

```
PYTHON_CONFIGURE_OPTS='--enable-shared' pyenv install 3.6.4
pyenv global 3.6.4
```

If there was a warning that `sqlite3` has not been compiled,
make sure to resolve it first before continuing - `sqlite3` is required by Kucher.
Now run `python3 --version` and ensure that you have v3.6 as default.

### CI artifacts

The CI builds redistributable release binaries automatically.
Expand Down
44 changes: 17 additions & 27 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,42 @@
environment:
matrix:
# Windows & python 3.6
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
PYTHON: "C:\\Python36-x64"
# Windows & python 3.10
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
PYTHON: "C:\\Python310-x64"
PYTHON_ARCH: "64"

# Windows & python 3.7
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
PYTHON: "C:\\Python37-x64"
PYTHON_ARCH: "64"

# Ubuntu & python 3.6
- APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu
PYTHON: "3.6"

# Ubuntu & python 3.7
# Ubuntu & python 3.10
- APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu
PYTHON: "3.7"
PYTHON: "3.10"

stack: python %PYTHON%

build: false
install:
- "git submodule update --init --recursive"
- cmd: "SET PATH=%PYTHON%;%PATH%"
- cmd: "SET PATH=C:\\Python36-x64\\Scripts;%PATH%"
- cmd: "SET PATH=C:\\Python37-x64\\Scripts;%PATH%"
- cmd: "SET PATH=C:\\Python310-x64\\Scripts;%PATH%"
- sh: "lsb_release -a"
- "python -V"
- "pip --version"
- cmd: "python -m pip install -r requirements.txt"
- cmd: "python -m pip install -r requirements-dev-windows.txt"
- cmd: "python -m pip install --upgrade pip"
- cmd: "python -m pip install -r requirements.txt"
- cmd: "python -m pip install -r requirements-dev-windows.txt"
- sh: "sudo add-apt-repository -y ppa:deadsnakes/ppa"
- sh: "sudo apt-get -y install python3.10-dev"
- sh: "pip install --upgrade pip"
- sh: "pip install -r requirements.txt"
- sh: "pip install -r requirements-dev-linux.txt"
- sh: "sudo add-apt-repository -y ppa:deadsnakes/ppa "
- sh: "sudo apt-get update"
- sh: "sudo apt-get -y install python3.6-dev"
- sh: "sudo apt-get -y install python3.7-dev"


build: off
#build: off

test_script:
- cmd: "test_windows.bat"
# Plugins related to software display are missing on Linux. Appveyor can't handle display so we disable it. See:
# https://doc.qt.io/qt-5/embedded-linux.html
# https://github.com/ariya/phantomjs/issues/14376
- sh: "export QT_QPA_PLATFORM=offscreen"
- sh: "bash test_linux.sh"
- sh: "pytest"
- sh: "black kucher/fuhrer kucher/model kucher/view kucher/*.py --check"

after_test:
- cmd: "7z a zubax-kucher.7z *"
Expand All @@ -55,4 +45,4 @@ after_test:
- sh: "bash build_linux.sh"
- cmd: "build_windows.bat"
- cmd: "appveyor PushArtifact dist\\Kucher.exe"
- sh: "appveyor PushArtifact dist/Kucher"
- sh: "appveyor PushArtifact dist/Kucher"
18 changes: 6 additions & 12 deletions kucher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import os
import sys

if sys.version_info[:2] < (3, 6):
raise ImportError('A newer version of Python is required')
if sys.version_info[:2] < (3, 10):
raise ImportError("A newer version of Python is required")

from .version import * # noqa
from .main import main # noqa
Expand All @@ -27,20 +27,14 @@
# The list of paths defined here can also be used by external packaging tools such as PyInstaller.
#
_SOURCE_PATH = os.path.abspath(os.path.dirname(__file__))
THIRDPARTY_PATH_ROOT = os.path.join(_SOURCE_PATH, 'libraries')
THIRDPARTY_PATH_ROOT = os.path.join(_SOURCE_PATH, "libraries")

THIRDPARTY_PATH = [
os.path.join(THIRDPARTY_PATH_ROOT),
os.path.join(THIRDPARTY_PATH_ROOT, 'popcop', 'python'),
os.path.join(THIRDPARTY_PATH_ROOT, 'construct'),
os.path.join(THIRDPARTY_PATH_ROOT, 'quamash'),
os.path.join(THIRDPARTY_PATH_ROOT, "popcop", "python"),
os.path.join(THIRDPARTY_PATH_ROOT, "construct"),
os.path.join(THIRDPARTY_PATH_ROOT, "qasync"),
]

# 'dataclasses' module is included in Python libraries since version 3.7. For Python versions below, the dataclass
# module located in the 'libraries' directory will be used. It is not compatible with Python 3.7, so we only declare
# its path if Python version is below 3.7. Otherwise, the built-in module will be used by default.
if sys.version_info[:2] < (3, 7):
THIRDPARTY_PATH.append(os.path.join(THIRDPARTY_PATH_ROOT, 'dataclasses'))

for tp in THIRDPARTY_PATH:
sys.path.insert(0, tp)
49 changes: 32 additions & 17 deletions kucher/data_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
_logger = getLogger(__name__)


if hasattr(sys, 'getwindowsversion'):
_appdata_env = os.getenv('LOCALAPPDATA') or os.getenv('APPDATA')
USER_SPECIFIC_DATA_DIR = os.path.abspath(os.path.join(_appdata_env, 'Zubax', 'Kucher'))
if hasattr(sys, "getwindowsversion"):
_appdata_env = os.getenv("LOCALAPPDATA") or os.getenv("APPDATA")
USER_SPECIFIC_DATA_DIR = os.path.abspath(
os.path.join(_appdata_env, "Zubax", "Kucher")
)
else:
USER_SPECIFIC_DATA_DIR = os.path.expanduser('~/.zubax/kucher')
USER_SPECIFIC_DATA_DIR = os.path.expanduser("~/.zubax/kucher")

LOG_DIR = os.path.join(USER_SPECIFIC_DATA_DIR, 'log')
LOG_DIR = os.path.join(USER_SPECIFIC_DATA_DIR, "log")


_MAX_AGE_OF_LOG_FILE_IN_DAYS = 30
Expand All @@ -49,15 +51,19 @@ def _create_directory(*path_items):
def _old_log_cleaner():
# noinspection PyBroadException
try:
_logger.info('Old log cleaner is waiting...')
_logger.info("Old log cleaner is waiting...")
# This delay is needed to avoid slowing down application startup, when disk access rates may be high
time.sleep(10)

_logger.info('Old log cleaner is ready to work now')
_logger.info("Old log cleaner is ready to work now")

files_sorted_new_to_old = map(lambda x: os.path.join(LOG_DIR, x), os.listdir(LOG_DIR))
files_sorted_new_to_old = list(sorted(files_sorted_new_to_old, key=lambda x: -os.path.getctime(x)))
_logger.info('Log files found: %r', files_sorted_new_to_old)
files_sorted_new_to_old = map(
lambda x: os.path.join(LOG_DIR, x), os.listdir(LOG_DIR)
)
files_sorted_new_to_old = list(
sorted(files_sorted_new_to_old, key=lambda x: -os.path.getctime(x))
)
_logger.info("Log files found: %r", files_sorted_new_to_old)

num_kept = 0
num_removed = 0
Expand All @@ -66,7 +72,9 @@ def _old_log_cleaner():
for f in files_sorted_new_to_old:
creation_time = os.path.getctime(f)

too_old = (current_time - creation_time) / (24 * 3600) >= _MAX_AGE_OF_LOG_FILE_IN_DAYS
too_old = (current_time - creation_time) / (
24 * 3600
) >= _MAX_AGE_OF_LOG_FILE_IN_DAYS
too_small = os.path.getsize(f) < _MIN_USEFUL_LOG_FILE_SIZE
too_many = num_kept >= _MAX_LOG_FILES_TO_KEEP

Expand All @@ -75,16 +83,21 @@ def _old_log_cleaner():
try:
os.unlink(f)
except Exception:
_logger.exception('Could not remove file %r', f)
_logger.exception("Could not remove file %r", f)
else:
_logger.info(f'File {f} removed successfully; old={too_old} small={too_small} many={too_many}')
_logger.info(
f"File {f} removed successfully; old={too_old} small={too_small} many={too_many}"
)
num_removed += 1
else:
num_kept += 1

_logger.info('Background old log cleaner has finished successfully; total files removed: %r', num_removed)
_logger.info(
"Background old log cleaner has finished successfully; total files removed: %r",
num_removed,
)
except Exception:
_logger.exception('Background old log cleaner has failed')
_logger.exception("Background old log cleaner has failed")


def init():
Expand All @@ -93,7 +106,9 @@ def init():
_create_directory(USER_SPECIFIC_DATA_DIR)
_create_directory(LOG_DIR)
except Exception:
_logger.exception('Could not create user-specific application data directories')
_logger.exception("Could not create user-specific application data directories")

# Fire and forget
threading.Thread(target=_old_log_cleaner, name='old_log_cleaner', daemon=True).start()
threading.Thread(
target=_old_log_cleaner, name="old_log_cleaner", daemon=True
).start()
Loading

0 comments on commit 67a1f1d

Please sign in to comment.