Skip to content

Commit

Permalink
Hatch (#2212)
Browse files Browse the repository at this point in the history
* style(format): update to newer black and isort

* build(hatch): switch from setuptools to hatch

* build(hatch): update requirements and manifest

* ci(workflows): update github and pre commit hook

* version 3.52
  • Loading branch information
ultrabug committed Jul 29, 2023
1 parent 87088a9 commit 7ada927
Show file tree
Hide file tree
Showing 115 changed files with 455 additions and 1,010 deletions.
14 changes: 3 additions & 11 deletions .git-hooks/pre-push
Expand Up @@ -5,16 +5,8 @@
# $ git config core.hooksPath .git-hooks # (in dir) to add hooks
# $ git config --unset core.hooksPath # (in dir) to remove hooks

if command -v black &>/dev/null; then
black --diff --check --quiet py3status/ || exit 1
black --diff --check --quiet setup.py fastentrypoints.py || exit 1
black --diff --check --quiet tests/ || exit 1
if command -v hatch &>/dev/null; then
hatch run all
else
echo 'hooks/pre-push: command "black" not found, skipping black tests'
fi

if command -v pytest &>/dev/null; then
pytest --flake8 || exit 1
else
echo 'hooks/pre-push: command "pytest" not found, skipping flake8 tests'
echo 'hooks/pre-push: command "hatch" not found, skipping hatch tests'
fi
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -19,6 +19,6 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
pip install -r requirements/project.txt
- name: Test with hatch
run: hatch run all
3 changes: 2 additions & 1 deletion CHANGELOG
@@ -1,4 +1,5 @@
version 3.52 (2023-07-11)
version 3.52 (2023-07-29)
* IMPORTANT: the project has moved from setuptools to pyproject.toml and hatch
* IMPORTANT: gevent support is now deprecated and removed
* core: drop gevent support

Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Expand Up @@ -5,4 +5,3 @@ recursive-include doc *.rst *.md *.txt *.py
include CHANGELOG
include LICENSE
include README.md
include fastentrypoints.py
13 changes: 7 additions & 6 deletions Makefile
@@ -1,21 +1,22 @@
qa:
tox
hatch run style:format
hatch run style:check

clean:
rm -rf dist
hatch clean

release: clean qa test
python3 setup.py sdist && python3 -m twine upload dist/*
release: clean qa test build
hatch publish -u __token__

serve:
mkdocs serve

build:
mkdocs build
hatch build

# TODO: maybe move the docs to github
#deploy: qa test
# mkdocs gh-deploy

test:
pytest -xsvv
hatch run all
114 changes: 0 additions & 114 deletions fastentrypoints.py

This file was deleted.

2 changes: 1 addition & 1 deletion py3status/argparsers.py
Expand Up @@ -2,9 +2,9 @@
import os
import subprocess
from pathlib import Path
from platform import python_version
from shutil import which

from platform import python_version
from py3status.version import version


Expand Down
1 change: 0 additions & 1 deletion py3status/autodoc.py
@@ -1,5 +1,4 @@
import re

from pathlib import Path

from py3status.docstrings import core_module_docstrings
Expand Down
6 changes: 2 additions & 4 deletions py3status/command.py
Expand Up @@ -3,7 +3,6 @@
import os
import socket
import threading

from pathlib import Path

SERVER_ADDRESS = "/tmp/py3status_uds"
Expand Down Expand Up @@ -419,6 +418,7 @@ def _check_value(self, action, value):
elif options.version:
# print version
from platform import python_version

from py3status.version import version

print(f"py3status {version} (python {python_version()})")
Expand Down Expand Up @@ -460,9 +460,7 @@ def parse_list_or_docstring(options, sps):

# HARDCODE: make include path to search for user modules
home_path = Path.home()
xdg_home_path = Path(
os.environ.get("XDG_CONFIG_HOME", home_path / ".config")
).resolve()
xdg_home_path = Path(os.environ.get("XDG_CONFIG_HOME", home_path / ".config")).resolve()
options.include_paths = [
xdg_home_path / "py3status/modules",
xdg_home_path / "i3status/py3status",
Expand Down
41 changes: 13 additions & 28 deletions py3status/core.py
@@ -1,24 +1,24 @@
import pkg_resources
import sys
import time

from collections import deque
from pathlib import Path
from pprint import pformat
from signal import signal, Signals, SIGTERM, SIGUSR1, SIGTSTP, SIGCONT
from signal import SIGCONT, SIGTERM, SIGTSTP, SIGUSR1, Signals, signal
from subprocess import Popen
from syslog import LOG_ERR, LOG_INFO, LOG_WARNING, syslog
from threading import Event, Thread
from syslog import syslog, LOG_ERR, LOG_INFO, LOG_WARNING
from traceback import extract_tb, format_tb, format_stack
from traceback import extract_tb, format_stack, format_tb

import pkg_resources

from py3status.command import CommandServer
from py3status.events import Events
from py3status.formatter import expand_color
from py3status.helpers import print_stderr
from py3status.i3status import I3status
from py3status.parse_config import process_config
from py3status.module import Module
from py3status.output import OutputFormat
from py3status.parse_config import process_config
from py3status.profiling import profile
from py3status.udev_monitor import UdevMonitor

Expand Down Expand Up @@ -217,9 +217,7 @@ def report_exception(self, msg, notify_user=True, level="error", error_frame=Non
if found:
break
# all done! create our message.
msg = "{} ({}) {} line {}.".format(
msg, exc_type.__name__, filename, line_no
)
msg = "{} ({}) {} line {}.".format(msg, exc_type.__name__, filename, line_no)
except: # noqa e722
# something went wrong report what we can.
msg = f"{msg}."
Expand Down Expand Up @@ -549,8 +547,7 @@ def _log_gitversion(self):
out = f.readline()
except OSError:
self.log(
"Unable to read git HEAD. "
"Use python git package for more repo information"
"Unable to read git HEAD. " "Use python git package for more repo information"
)
return
branch = "/".join(out.strip().split("/")[2:])
Expand Down Expand Up @@ -636,9 +633,7 @@ def setup(self):
time.sleep(0.1)
if self.config["debug"]:
self.log(
"i3status thread {} with config {}".format(
i3s_mode, self.config["py3_config"]
)
"i3status thread {} with config {}".format(i3s_mode, self.config["py3_config"])
)

# add i3status thread monitoring task
Expand Down Expand Up @@ -671,9 +666,7 @@ def setup(self):
# make sure we honor custom i3bar protocol stop/resume signals
# while providing users a way to opt out from that feature
# using the 0 value as specified by the i3bar protocol
custom_stop_signal = (
self.config["py3_config"].get("py3status", {}).get("stop_signal")
)
custom_stop_signal = self.config["py3_config"].get("py3status", {}).get("stop_signal")
if custom_stop_signal is not None:
try:
# 0 is a special value for i3bar protocol, use it as-is
Expand Down Expand Up @@ -769,9 +762,7 @@ def notify_user(
if msg_hash in self.notified_messages:
return
elif module_name:
log_msg = 'Module `{}` sent a notification. "{}: {}"'.format(
module_name, title, msg
)
log_msg = 'Module `{}` sent a notification. "{}: {}"'.format(module_name, title, msg)
self.log(log_msg, level)
else:
self.log(msg, level)
Expand Down Expand Up @@ -1021,10 +1012,7 @@ def process_module_output(self, module):
return self.output_format.format(outputs)

def i3bar_stop(self, signum, frame):
if (
self.next_allowed_signal == signum
and time.monotonic() > self.inhibit_signal_ts
):
if self.next_allowed_signal == signum and time.monotonic() > self.inhibit_signal_ts:
self.log(f"received stop_signal {Signals(signum).name}")
self.i3bar_running = False
# i3status should be stopped
Expand All @@ -1036,10 +1024,7 @@ def i3bar_stop(self, signum, frame):
self.inhibit_signal_ts = time.monotonic() + 0.1

def i3bar_start(self, signum, frame):
if (
self.next_allowed_signal == signum
and time.monotonic() > self.inhibit_signal_ts
):
if self.next_allowed_signal == signum and time.monotonic() > self.inhibit_signal_ts:
self.log(f"received resume signal {Signals(signum).name}")
self.i3bar_running = True
self.wake_modules()
Expand Down
23 changes: 6 additions & 17 deletions py3status/docstrings.py
@@ -1,7 +1,6 @@
import ast
import re
import difflib

import re
from pathlib import Path

from py3status.helpers import print_stderr
Expand Down Expand Up @@ -38,9 +37,7 @@ def parse_readme():
return modules_dict


def core_module_docstrings(
include_core=True, include_user=False, config=None, format="md"
):
def core_module_docstrings(include_core=True, include_user=False, config=None, format="md"):
"""
Get docstrings for all core modules and user ones if requested
returns a dict of {<module_name>: <docstring>}
Expand Down Expand Up @@ -79,13 +76,9 @@ def core_module_docstrings(
docstring = parts[0]

if format == "md":
docstring = [
d for d in _from_docstring_md(str(docstring).strip().split("\n"))
]
docstring = [d for d in _from_docstring_md(str(docstring).strip().split("\n"))]
elif format == "rst":
docstring = [
d for d in _from_docstring_rst(str(docstring).strip().split("\n"))
]
docstring = [d for d in _from_docstring_rst(str(docstring).strip().split("\n"))]
else:
raise Exception("`md` and `rst` format supported only")

Expand Down Expand Up @@ -316,9 +309,7 @@ def update_docstrings():
if quotes and row.strip().startswith(quotes) and not done:
out.append(row)
if not replaced:
out = out + [
"".join(_to_docstring(modules_dict[mod])).strip() + "\n"
]
out = out + ["".join(_to_docstring(modules_dict[mod])).strip() + "\n"]
replaced = True
if lines:
done = True
Expand Down Expand Up @@ -403,9 +394,7 @@ def show_modules(config, modules_list):
core_mods = not config["user"]
user_mods = not config["core"]

modules = core_module_docstrings(
include_core=core_mods, include_user=user_mods, config=config
)
modules = core_module_docstrings(include_core=core_mods, include_user=user_mods, config=config)

new_modules = []
if modules_list:
Expand Down

0 comments on commit 7ada927

Please sign in to comment.