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

CI: add ruff linting job, fix PEP8/257 violations and formatting #615

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4

[*.{py}]
trim_trailing_whitespace = true
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Lint

on: [push, pull_request]

jobs:
lint-ruff:
runs-on: ubuntu-latest
name: ruff
steps:
- name: Check out source repository
uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
17 changes: 17 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
target-version = "py310"

# gettext
builtins = ["_"]

[lint]
select = ["E", "W", "F", "D2", "D3", "D4"]
ignore = [
# PyGObject needs require_version before imports
"E402",

# these are disabled for now, but should probably be cleaned up at some point
"D205", "D401", "D404",
]

[lint.pydocstyle]
convention = "numpy"
98 changes: 69 additions & 29 deletions safeeyes/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Safe Eyes is a utility to remind you to take break frequently to protect
your eyes from eye strain.
"""
Safe Eyes is a utility to remind you to take break frequently to protect your eyes from eye strain.
"""

import argparse
import gettext
import locale
Expand All @@ -33,13 +34,11 @@
from safeeyes.safeeyes import SAFE_EYES_VERSION
from safeeyes.rpc import RPCClient

gettext.install('safeeyes', utility.LOCALE_PATH)
gettext.install("safeeyes", utility.LOCALE_PATH)


def __running():
"""
Check if SafeEyes is already running.
"""
"""Check if SafeEyes is already running."""
process_count = 0
for proc in psutil.process_iter():
if not proc.cmdline:
Expand All @@ -52,7 +51,9 @@ def __running():
else:
# In older versions cmdline was a list object
cmd_line = proc.cmdline
if ('python3' in cmd_line[0] or 'python' in cmd_line[0]) and ('safeeyes' in cmd_line[1] or 'safeeyes' in cmd_line):
if ("python3" in cmd_line[0] or "python" in cmd_line[0]) and (
"safeeyes" in cmd_line[1] or "safeeyes" in cmd_line
):
process_count += 1
if process_count > 1:
return True
Expand All @@ -64,29 +65,63 @@ def __running():


def main():
"""
Start the Safe Eyes.
"""
system_locale = gettext.translation('safeeyes', localedir=utility.LOCALE_PATH, languages=[utility.system_locale(), 'en_US'], fallback=True)
"""Start the Safe Eyes."""
system_locale = gettext.translation(
"safeeyes",
localedir=utility.LOCALE_PATH,
languages=[utility.system_locale(), "en_US"],
fallback=True,
)
system_locale.install()
try:
# locale.bindtextdomain is required for Glade files
locale.bindtextdomain('safeeyes', utility.LOCALE_PATH)
locale.bindtextdomain("safeeyes", utility.LOCALE_PATH)
except AttributeError:
logging.warning('installed python\'s gettext module does not support locale.bindtextdomain. locale.bindtextdomain is required for Glade files')

logging.warning(
"installed python's gettext module does not support locale.bindtextdomain."
" locale.bindtextdomain is required for Glade files"
)

parser = argparse.ArgumentParser(prog='safeeyes')
parser = argparse.ArgumentParser(prog="safeeyes")
group = parser.add_mutually_exclusive_group()
group.add_argument('-a', '--about', help=_('show the about dialog'), action='store_true')
group.add_argument('-d', '--disable', help=_('disable the currently running safeeyes instance'), action='store_true')
group.add_argument('-e', '--enable', help=_('enable the currently running safeeyes instance'), action='store_true')
group.add_argument('-q', '--quit', help=_('quit the running safeeyes instance and exit'), action='store_true')
group.add_argument('-s', '--settings', help=_('show the settings dialog'), action='store_true')
group.add_argument('-t', '--take-break', help=_('Take a break now').lower(), action='store_true')
parser.add_argument('--debug', help=_('start safeeyes in debug mode'), action='store_true')
parser.add_argument('--status', help=_('print the status of running safeeyes instance and exit'), action='store_true')
parser.add_argument('--version', action='version', version='%(prog)s ' + SAFE_EYES_VERSION)
group.add_argument(
"-a", "--about", help=_("show the about dialog"), action="store_true"
)
group.add_argument(
"-d",
"--disable",
help=_("disable the currently running safeeyes instance"),
action="store_true",
)
group.add_argument(
"-e",
"--enable",
help=_("enable the currently running safeeyes instance"),
action="store_true",
)
group.add_argument(
"-q",
"--quit",
help=_("quit the running safeeyes instance and exit"),
action="store_true",
)
group.add_argument(
"-s", "--settings", help=_("show the settings dialog"), action="store_true"
)
group.add_argument(
"-t", "--take-break", help=_("Take a break now").lower(), action="store_true"
)
parser.add_argument(
"--debug", help=_("start safeeyes in debug mode"), action="store_true"
)
parser.add_argument(
"--status",
help=_("print the status of running safeeyes instance and exit"),
action="store_true",
)
parser.add_argument(
"--version", action="version", version="%(prog)s " + SAFE_EYES_VERSION
)
args = parser.parse_args()

# Initialize the logging
Expand All @@ -99,10 +134,15 @@ def main():
logging.info("Safe Eyes is already running")
if not config.get("use_rpc_server", True):
# RPC sever is disabled
print(_('Safe Eyes is running without an RPC server. Turn it on to use command-line arguments.'))
print(
_(
"Safe Eyes is running without an RPC server. Turn it on to use"
" command-line arguments."
)
)
sys.exit(0)
return
rpc_client = RPCClient(config.get('rpc_port'))
rpc_client = RPCClient(config.get("rpc_port"))
if args.about:
rpc_client.show_about()
elif args.disable:
Expand All @@ -123,14 +163,14 @@ def main():
sys.exit(0)
else:
if args.status:
print(_('Safe Eyes is not running'))
print(_("Safe Eyes is not running"))
sys.exit(0)
elif not args.quit:
logging.info("Starting Safe Eyes")
safe_eyes = SafeEyes(system_locale, config, args)
safe_eyes.start()


if __name__ == '__main__':
signal.signal(signal.SIGINT, signal.SIG_DFL) # Handle Ctrl + C
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal.SIG_DFL) # Handle Ctrl + C
main()
Loading
Loading