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

migrate from setup.py to pyproject.toml #639

Open
wants to merge 9 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
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ jobs:
pip install build wheel

- name: Get Current Version
run: |
project_version=$(python3 setup.py --version)
echo "project_version=$project_version" >> $GITHUB_OUTPUT
uses: SebRollen/[email protected]
with:
file: "pyproject.toml"
field: project.version
id: get_current_version

- name: Create Tag
uses: mathieudutour/[email protected]
with:
custom_tag: "${{steps.get_current_version.outputs.project_version}}"
custom_tag: "${{steps.get_current_version.outputs.value}}"
github_token: ${{ secrets.GH_API_SECRET }}

- name: Build Changelog
Expand All @@ -44,7 +45,7 @@ jobs:
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: 'v${{steps.get_current_version.outputs.project_version}}'
tag_name: 'v${{steps.get_current_version.outputs.value}}'
body: ${{steps.build_changelog.outputs.changelog}}
token: ${{ secrets.GH_API_SECRET }}

Expand Down
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
include LICENSES/GPL-3.0-or-later.txt
include README.md

graft safeeyes

global-exclude *.py[cod]
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,8 @@ To ensure the new strings are well-formed, you can use `python validate_po.py --
1. Checkout the latest commits from the `master` branch
2. Run `python3 -m safeeyes` to make sure nothing is broken
3. Update the Safe Eyes version in the following places (Open the project in VSCode and search for the current version):
- [setup.py](https://github.com/slgobinath/SafeEyes/blob/master/setup.py#L82)
- [setup.py](https://github.com/slgobinath/SafeEyes/blob/master/setup.py#L89)
- [safeeyes.py](https://github.com/slgobinath/SafeEyes/blob/master/safeeyes/safeeyes.py#L42)
- [pyproject.toml](https://github.com/slgobinath/SafeEyes/blob/master/pyproject.toml#L4)
- [pyproject.toml](https://github.com/slgobinath/SafeEyes/blob/master/pyproject.toml#L35)
- [io.github.slgobinath.SafeEyes.metainfo.xml](https://github.com/slgobinath/SafeEyes/blob/master/safeeyes/platform/io.github.slgobinath.SafeEyes.metainfo.xml#L56)
- [about_dialog.glade](https://github.com/slgobinath/SafeEyes/blob/master/safeeyes/glade/about_dialog.glade#L74)
4. Update the [changelog](https://github.com/slgobinath/SafeEyes/blob/master/debian/changelog) (for Ubuntu PPA release)
Expand Down
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[project]
name = "safeeyes"
version = "2.2.3"
description = "Protect your eyes from eye strain using this continuous breaks reminder."
keywords = ["linux utility health eye-strain safe-eyes"]
readme = "README.md"
authors = [
{name = "Gobinath Loganathan", email = "[email protected]"},
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: X11 Applications :: GTK",
"Environment :: Other Environment",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Utilities",
]
dependencies = [
"PyGObject",
"babel",
"psutil",
"packaging",
"python-xlib",
]
requires-python = ">=3.10"

[project.urls]
Homepage = "https://github.com/slgobinath/SafeEyes"
Downloads = "https://github.com/slgobinath/SafeEyes/archive/v2.2.3.tar.gz"

[project.scripts]
safeeyes = "safeeyes.__main__:main"

[project.optional-dependencies]
healthstats = ["croniter"]

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
include=["safeeyes*"]
4 changes: 3 additions & 1 deletion safeeyes/safeeyes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import logging
import os
from threading import Timer
from importlib import metadata

import gi
from safeeyes import utility
Expand All @@ -36,10 +37,11 @@
from safeeyes.core import SafeEyesCore
from safeeyes.ui.settings_dialog import SettingsDialog


gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio, GLib

SAFE_EYES_VERSION = "2.2.3"
SAFE_EYES_VERSION = metadata.version("safeeyes")


class SafeEyes(Gtk.Application):
Expand Down
174 changes: 72 additions & 102 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,103 +1,73 @@
import os, sys, site
import subprocess
import setuptools


requires = [
'babel',
'psutil',
'croniter',
'PyGObject',
'packaging',
'python-xlib'
]

_ROOT = os.path.abspath(os.path.dirname(__file__))

with open(os.path.join(_ROOT, 'README.md')) as f:
long_description = f.read()


def __compile_po_files():
"""
Compile the *.po trainslation files.
"""
localedir = 'safeeyes/config/locale'
po_dirs = [localedir + '/' + l + '/LC_MESSAGES/'
for l in next(os.walk(localedir))[1]]
for po_dir in po_dirs:
po_files = [f
for f in next(os.walk(po_dir))[2]
if os.path.splitext(f)[1] == '.po']
for po_file in po_files:
filename, _ = os.path.splitext(po_file)
mo_file = filename + '.mo'
msgfmt_cmd = 'msgfmt {} -o {}'.format(
po_dir + po_file, po_dir + mo_file)
subprocess.call(msgfmt_cmd, shell=True)


def __data_files():
"""
Collect the data files.
"""
root_dir = sys.prefix
return [(os.path.join(root_dir, "share/applications"), ["safeeyes/platform/io.github.slgobinath.SafeEyes.desktop"]),
(os.path.join(root_dir, "share/icons/hicolor/24x24/status"), ["safeeyes/platform/icons/hicolor/24x24/status/io.github.slgobinath.SafeEyes-disabled.png", "safeeyes/platform/icons/hicolor/24x24/status/io.github.slgobinath.SafeEyes-enabled.png", "safeeyes/platform/icons/hicolor/24x24/status/io.github.slgobinath.SafeEyes-timer.png"]),
(os.path.join(root_dir, "share/icons/hicolor/24x24/apps"), ["safeeyes/platform/icons/hicolor/24x24/apps/io.github.slgobinath.SafeEyes.png"]),
(os.path.join(root_dir, "share/icons/hicolor/16x16/status"), ["safeeyes/platform/icons/hicolor/16x16/status/io.github.slgobinath.SafeEyes-disabled.png", "safeeyes/platform/icons/hicolor/16x16/status/io.github.slgobinath.SafeEyes-enabled.png", "safeeyes/platform/icons/hicolor/16x16/status/io.github.slgobinath.SafeEyes-timer.png"]),
(os.path.join(root_dir, "share/icons/hicolor/16x16/apps"), ["safeeyes/platform/icons/hicolor/16x16/apps/io.github.slgobinath.SafeEyes.png"]),
(os.path.join(root_dir, "share/icons/hicolor/32x32/status"), ["safeeyes/platform/icons/hicolor/32x32/status/io.github.slgobinath.SafeEyes-disabled.png", "safeeyes/platform/icons/hicolor/32x32/status/io.github.slgobinath.SafeEyes-enabled.png"]),
(os.path.join(root_dir, "share/icons/hicolor/32x32/apps"), ["safeeyes/platform/icons/hicolor/32x32/apps/io.github.slgobinath.SafeEyes.png"]),
(os.path.join(root_dir, "share/icons/hicolor/64x64/apps"), ["safeeyes/platform/icons/hicolor/64x64/apps/io.github.slgobinath.SafeEyes.png"]),
(os.path.join(root_dir, "share/icons/hicolor/128x128/apps"), ["safeeyes/platform/icons/hicolor/128x128/apps/io.github.slgobinath.SafeEyes.png"]),
(os.path.join(root_dir, "share/icons/hicolor/48x48/status"), ["safeeyes/platform/icons/hicolor/48x48/status/io.github.slgobinath.SafeEyes-disabled.png", "safeeyes/platform/icons/hicolor/48x48/status/io.github.slgobinath.SafeEyes-enabled.png"]),
(os.path.join(root_dir, "share/icons/hicolor/48x48/apps"), ["safeeyes/platform/icons/hicolor/48x48/apps/io.github.slgobinath.SafeEyes.png"]),]


def __package_files(directory):
"""
Collect the package files.
"""
paths = []
for (path, _, filenames) in os.walk(directory):
for filename in filenames:
paths.append(os.path.join('..', path, filename))
return paths


def __package_data():
"""
Return a list of package data.
"""
__compile_po_files()
data = ['glade/*.glade', 'resource/*']
data.extend(__package_files('safeeyes/config'))
data.extend(__package_files('safeeyes/plugins'))
data.extend(__package_files('safeeyes/platform'))
return data

setuptools.setup(
name="safeeyes",
version="2.2.3",
description="Protect your eyes from eye strain using this continuous breaks reminder.",
long_description=long_description,
long_description_content_type="text/markdown",
author="Gobinath Loganathan",
author_email="[email protected]",
url="https://github.com/slgobinath/SafeEyes",
download_url="https://github.com/slgobinath/SafeEyes/archive/v2.2.3.tar.gz",
packages=setuptools.find_packages(),
package_data={'safeeyes': __package_data()},
data_files=__data_files(),
install_requires=requires,
entry_points={'console_scripts': ['safeeyes = safeeyes.__main__:main']},
keywords='linux utility health eye-strain safe-eyes',
classifiers=[
"Operating System :: POSIX :: Linux",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Development Status :: 5 - Production/Stable",
"Environment :: X11 Applications :: GTK",
"Intended Audience :: End Users/Desktop",
"Topic :: Utilities"] + [('Programming Language :: Python :: %s' % x) for x in '3 3.5 3.6 3.7 3.8 3.9'.split()]
#!/usr/bin/python3

import os

from pathlib import Path
from setuptools import Command, setup
from setuptools.command.build import build as OriginalBuildCommand

class BuildCommand(OriginalBuildCommand):
sub_commands = [('build_mo', None), *OriginalBuildCommand.sub_commands]


class BuildMoSubCommand(Command):
description = 'Compile .po files into .mo files'

files = None

def initialize_options(self):
self.files = None
self.editable_mode = False
self.build_lib = None

def finalize_options(self):
self.set_undefined_options("build_py", ("build_lib", "build_lib"))

def run(self):
files = self._get_files()

for build_file, source_file in files.items():
if not self.editable_mode:
# Parent directory required for msgfmt to work correctly
Path(build_file).parent.mkdir(parents=True, exist_ok=True)
self.spawn(['msgfmt', source_file, '-o', build_file])

def _get_files(self):
if self.files is not None:
return self.files

files = {}

localedir = Path('safeeyes/config/locale')
po_dirs = [l.joinpath('LC_MESSAGES') for l in localedir.iterdir() if l.is_dir()]
for po_dir in po_dirs:
po_files = [f
for f in po_dir.iterdir()
if f.is_file() and f.suffix == '.po']
for po_file in po_files:
mo_file = po_file.with_suffix(".mo")

source_file = po_file
build_file = mo_file

if not self.editable_mode:
build_file = Path(self.build_lib).joinpath(build_file)

files[str(build_file)] = str(source_file)

self.files = files
return files

def get_output_mapping(self):
return self._get_files()

def get_outputs(self):
return self._get_files().keys()

def get_source_files(self):
return self._get_files().values()


setup(
cmdclass={'build': BuildCommand, 'build_mo': BuildMoSubCommand}
)
Loading