aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Miller <nwg.piotr@gmail.com>2020-07-20 22:18:21 +0200
committerGitHub <noreply@github.com>2020-07-20 22:18:21 +0200
commit02456a585f1e17bd034f0e06b884e525304a51a5 (patch)
tree8cab63125b7446243d53232a002b4b669107e8f4
parente56b7bd40f053bf7c6f3b6c92fb700f66495bf97 (diff)
parent26d4d8950a395e9db7fb66d476785335e6322d34 (diff)
downloadautotiling-02456a585f1e17bd034f0e06b884e525304a51a5.tar.gz
Merge pull request #14 from nschloe/package-structurev1.1
Python package structure
-rw-r--r--.flake85
-rw-r--r--Makefile33
-rw-r--r--README.md52
-rwxr-xr-xautotiling2
-rw-r--r--autotiling/__about__.py10
-rw-r--r--autotiling/__init__.py4
-rw-r--r--[-rwxr-xr-x]autotiling/main.py (renamed from autotiling.py)51
-rw-r--r--pyproject.toml3
-rw-r--r--setup.cfg38
-rw-r--r--setup.py4
10 files changed, 158 insertions, 44 deletions
diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..c321e71
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,5 @@
+[flake8]
+ignore = E203, E266, E501, W503
+max-line-length = 80
+max-complexity = 18
+select = B,C,E,F,W,T4,B9
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..aecacf2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,33 @@
+VERSION=$(shell python3 -c "from configparser import ConfigParser; p = ConfigParser(); p.read('setup.cfg'); print(p['metadata']['version'])")
+
+default:
+ @echo "\"make publish\"?"
+
+upload:
+ # Make sure we're on the master branch
+ @if [ "$(shell git rev-parse --abbrev-ref HEAD)" != "master" ]; then exit 1; fi
+ rm -f dist/*
+ # https://stackoverflow.com/a/58756491/353337
+ python3 -m pep517.build --source --binary .
+ twine upload dist/*
+
+tag:
+ @if [ "$(shell git rev-parse --abbrev-ref HEAD)" != "master" ]; then exit 1; fi
+ curl -H "Authorization: token `cat $(HOME)/.github-access-token`" -d '{"tag_name": "v$(VERSION)"}' https://api.github.com/repos/nwg-piotr/autotiling/releases
+
+publish: tag upload
+
+clean:
+ @find . | grep -E "(__pycache__|\.pyc|\.pyo$\)" | xargs rm -rf
+ @rm -rf *.egg-info/ build/ dist/ MANIFEST
+
+format:
+ isort .
+ black .
+
+black:
+ black .
+
+lint:
+ black --check .
+ flake8 .
diff --git a/README.md b/README.md
index 77648fc..28bf3ac 100644
--- a/README.md
+++ b/README.md
@@ -1,35 +1,49 @@
# autotiling
-This script uses the [i3ipc-python library](https://github.com/altdesktop/i3ipc-python) to switch the layout
-splith / splitv depending on the currently focused window dimensions. It works on both sway and i3 window managers.
+This script uses the [i3ipc-python library](https://github.com/altdesktop/i3ipc-python)
+to switch the layout splith/splitv depending on the currently focused window
+dimensions. It works on both sway and i3 window managers.
-Inspired by https://github.com/olemartinorg/i3-alternating-layout
+Inspired by https://github.com/olemartinorg/i3-alternating-layout.
## See on YouTube:
-[![Auto-tiling in action](https://img.youtube.com/vi/UWRZuhn92bQ/0.jpg)](https://www.youtube.com/watch?v=UWRZuhn92bQ)
+[![Auto-tiling in
+action](https://img.youtube.com/vi/UWRZuhn92bQ/0.jpg)](https://www.youtube.com/watch?v=UWRZuhn92bQ)
## Installation
-[![Packaging status](https://repology.org/badge/vertical-allrepos/autotiling.svg)](https://repology.org/project/autotiling/versions)
+1. Install autotiling. Possible methods:
-**Arch Linux**
+ * _PyPi._ autotiling is available from PyPi, so you can install it with
+ ```
+ pip install autotiling
+ ```
+ _NOTE:_ The current master branch is compatible with sway >= 1.5. For lower
+ versions you need to use the script from the [sway14
+ branch](https://github.com/nwg-piotr/autotiling/tree/sway14) or the [0.9
+ release](https://github.com/nwg-piotr/autotiling/releases/tag/v0.9).
-1. Install the `autotiling` (AUR) package.
-2. Add `exec autotiling` to the `~/.config/sway/config` or `exec_always --no-startup-id autotiling`
-to the `~/.config/i3/config` file.
-For the sway-git package use [autotiling-git](https://aur.archlinux.org/packages/autotiling-git).
+ * _Arch Linux_
-**Manually**
+ [![Packaging
+ status](https://repology.org/badge/vertical-allrepos/autotiling.svg)](https://repology.org/project/autotiling/versions)
-NOTE: Current master branch is compatible with sway 1.5. For lower versions you need to use the script from the
-[sway14 branch](https://github.com/nwg-piotr/autotiling/tree/sway14) or the
-[0.9 release](https://github.com/nwg-piotr/autotiling/releases/tag/v0.9).
+ For the sway-git package use
+ [autotiling-git](https://aur.archlinux.org/packages/autotiling-git).
-1. Install the `python-i3ipc>=2.0.1` package (or whatever it's called in your Linux distribution).
-2. Save the `autotiling.py` file anywhere, make executable and autostart in your i3/sway config file:
-`exec /path/to/the/script/autotiling.py` on sway or `exec_always --no-startup-id /path/to/the/script/autotiling.py` on i3.
+ * _Manually_
-**Snap**
+ 1. Install the `python-i3ipc>=2.0.1` package (or whatever it's called in your Linux
+ distribution).
+ 2. Save the `autotiling.py` file anywhere, make executable and autostart in your
+ i3/sway config file: `exec /path/to/the/script/autotiling.py` on sway or
+ `exec_always --no-startup-id /path/to/the/script/autotiling.py` on i3.
-`snap install autotiling`
+ * _Snap_
+ ```
+ snap install autotiling
+ ```
+
+2. Add `exec autotiling` to the `~/.config/sway/config` or `exec_always --no-startup-id
+ autotiling` to the `~/.config/i3/config` file.
diff --git a/autotiling b/autotiling
deleted file mode 100755
index 1e2cf34..0000000
--- a/autotiling
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env bash
-exec /usr/lib/autotiling/autotiling.py "$@"
diff --git a/autotiling/__about__.py b/autotiling/__about__.py
new file mode 100644
index 0000000..647d8a7
--- /dev/null
+++ b/autotiling/__about__.py
@@ -0,0 +1,10 @@
+try:
+ # Python 3.8
+ from importlib import metadata
+except ImportError:
+ import importlib_metadata as metadata
+
+try:
+ __version__ = metadata.version("autotiling")
+except Exception:
+ __version__ = "unknown"
diff --git a/autotiling/__init__.py b/autotiling/__init__.py
new file mode 100644
index 0000000..ac3962e
--- /dev/null
+++ b/autotiling/__init__.py
@@ -0,0 +1,4 @@
+from .__about__ import __version__
+from .main import main
+
+__all__ = ["main", "__version__"]
diff --git a/autotiling.py b/autotiling/main.py
index cc42a43..d253999 100755..100644
--- a/autotiling.py
+++ b/autotiling/main.py
@@ -1,6 +1,3 @@
-#!/usr/bin/env python3
-# _*_ coding: utf-8 _*_
-
"""
This script uses the i3ipc python module to switch the layout splith / splitv
for the currently focused window, depending on its dimensions.
@@ -26,46 +23,54 @@ def switch_splitting(i3, e, debug):
try:
con = i3.get_tree().find_focused()
if con:
- if con.floating: # We're on i3: on sway it would be None
- is_floating = '_on' in con.floating # May be 'auto_on' or 'user_on'
+ if con.floating:
+ # We're on i3: on sway it would be None
+ # May be 'auto_on' or 'user_on'
+ is_floating = "_on" in con.floating
is_full_screen = con.fullscreen_mode == 1
- else: # We are on sway
- is_floating = con.type == 'floating_con'
+ else:
+ # We are on sway
+ is_floating = con.type == "floating_con"
is_full_screen = con.fullscreen_mode == 1
- is_stacked = con.parent.layout == 'stacked'
- is_tabbed = con.parent.layout == 'tabbed'
+ is_stacked = con.parent.layout == "stacked"
+ is_tabbed = con.parent.layout == "tabbed"
- # Let's exclude floating containers, stacked layouts, tabbed layouts and full screen mode
- if not is_floating and not is_stacked and not is_tabbed and not is_full_screen:
- new_layout = 'splitv' if con.rect.height > con.rect.width else 'splith'
+ # Let's exclude floating containers, stacked layouts, tabbed layouts and
+ # full screen mode
+ if (
+ not is_floating
+ and not is_stacked
+ and not is_tabbed
+ and not is_full_screen
+ ):
+ new_layout = "splitv" if con.rect.height > con.rect.width else "splith"
if new_layout != con.parent.layout:
result = i3.command(new_layout)
if result[0].success and debug:
- print('Debug: Switched to {}'.format(new_layout), file=sys.stderr)
+ print(
+ "Debug: Switched to {}".format(new_layout), file=sys.stderr
+ )
elif debug:
- print('Error: Switch failed with err {}'.format(result[0].error), file=sys.stderr)
+ print(
+ "Error: Switch failed with err {}".format(result[0].error),
+ file=sys.stderr,
+ )
elif debug:
- print('Debug: No focused container found', file=sys.stderr)
+ print("Debug: No focused container found", file=sys.stderr)
except Exception as e:
- print('Error: {}'.format(e), file=sys.stderr)
+ print("Error: {}".format(e), file=sys.stderr)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
- '--debug',
- action='store_true',
- help='Print debug messages to stderr'
+ "--debug", action="store_true", help="Print debug messages to stderr"
)
args = parser.parse_args()
handler = partial(switch_splitting, debug=args.debug)
i3 = Connection()
i3.on(Event.WINDOW_FOCUS, handler)
i3.main()
-
-
-if __name__ == "__main__":
- main()
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..8fe2f47
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,3 @@
+[build-system]
+requires = ["setuptools>=42", "wheel"]
+build-backend = "setuptools.build_meta"
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..7155b99
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,38 @@
+[metadata]
+name = autotiling
+version = 1.1
+author = Piotr Miller
+author_email = nwg.piotr@gmail.com
+description = Automatically switch the horizontal/vertical window split orientation in i3 and sway
+url = https://github.com/nwg-piotr/autotiling
+project_urls =
+ Code=https://github.com/nwg-piotr/autotiling
+ Issues=https://github.com/nwg-piotr/autotiling/issues
+long_description = file: README.md
+long_description_content_type = text/markdown
+license = GPL-3.0-or-later
+license_file = LICENSE
+classifiers =
+ Development Status :: 4 - Beta
+ License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
+ Operating System :: OS Independent
+ Programming Language :: Python
+ Programming Language :: Python :: 3
+ Programming Language :: Python :: 3.6
+ Programming Language :: Python :: 3.7
+ Programming Language :: Python :: 3.8
+
+[options]
+packages = find:
+install_requires =
+ importlib_metadata;python_version<"3.8"
+ i3ipc
+python_requires = >=3.6
+setup_requires =
+ setuptools>=42
+ wheel
+
+
+[options.entry_points]
+console_scripts =
+ autotiling = autotiling.main:main
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..7f1a176
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,4 @@
+from setuptools import setup
+
+if __name__ == "__main__":
+ setup()