Skip to content

Commit 60c65b0

Browse files
authored
Merge pull request #43 from homebysix/dev
2.0.0 merge to main
2 parents 6ea7975 + ec4e93e commit 60c65b0

File tree

8 files changed

+61
-50
lines changed

8 files changed

+61
-50
lines changed

.flake8

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[flake8]
2+
select = B,C,E,F,P,W,B9
3+
max-line-length = 80
4+
### DEFAULT IGNORES FOR 4-space INDENTED PROJECTS ###
5+
# E127, E128 are hard to silence in certain nested formatting situations.
6+
# E203 doesn't work for slicing
7+
# E265, E266 talk about comment formatting which is too opinionated.
8+
# E402 warns on imports coming after statements. There are important use cases
9+
# that require statements before imports.
10+
# E501 is not flexible enough, we're using B950 instead.
11+
# E722 is a duplicate of B001.
12+
# P207 is a duplicate of B003.
13+
# P208 is a duplicate of C403.
14+
# W503 talks about operator formatting which is too opinionated.
15+
ignore = E127, E128, E203, E265, E266, E402, E501, E722, P207, P208, W503
16+
exclude =
17+
.git,
18+
.hg,
19+
max-complexity = 65

.isort.cfg

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[settings]
2-
multi_line_output=3
3-
include_trailing_comma=True
42
force_grid_wrap=0
5-
use_parentheses=True
3+
include_trailing_comma=True
64
line_length=88
5+
multi_line_output=3
6+
use_parentheses=True

CHANGELOG.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22

33
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [2.0.0] - 2024-04-13
56

6-
## [Unreleased]
7+
This release fixes compatibility with Python 10.12 by removing the dependencies on `distutils.versions`. (Thanks to @arubdesu for #42.)
78

8-
Nothing yet.
9+
### Removed
910

11+
- Removed Python 2 support. If you're still deploying docklib to macOS versions prior to Monterey 12.3, be sure you're deploying a Python runtime like [MacAdmins Python](https://github.com/macadmins/python) rather than relying on the built-in `/usr/bin/python`.
12+
- Removed macOS version detection. This may cause unexpected behavior when referencing the `AllowDockFixupOverride`, `show-recents`, `recent-apps`, `dblclickbehavior`, `show-recents-immutable`, and `windowtabbing` keys on macOS versions prior to Big Sur 11.0.
13+
14+
### Changed
15+
16+
- `makeDockAppSpacer()` parameter name has changed from `type` to `tile_type`. Please update your scripts if you use this function.
17+
- Updated unit tests with new `is-beta` preference key present in macOS Sonoma Dock tiles.
1018

1119
## [1.3.0] - 2021-05-31
1220

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The very capable [dockutil](https://github.com/kcrawford/dockutil) tool serves a
1010

1111
The primary benefit of **docklib** is that it allows the Dock to be manipulated in a "Pythonic" way. By parsing the Dock configuration into an object with attributes and data structures that can be modified using familiar functions like `.append()` and `.insert()`, docklib aims to make Python scripters feel at home.
1212

13-
In contrast, **dockutil** behaves more like a shell command-line utility. This makes dockutil a good choice if you're more comfortable writing user setup scripts in bash or zsh. Dockutil also has an `--allhomes` argument that allows Dock configuration for all users to be modified at the same time. Docklib isn't designed for this, instead focusing on configuring the Dock for the user that is currently logged in (for example, via an [outset](https://github.com/chilcote/outset) `login-once` or `login-every` script). [Here's](https://appleshare.it/posts/use-dockutil-in-a-script/) a great article to get you started with dockutil, if that sounds like what you're after.
13+
In contrast, **dockutil** behaves more like a shell command-line utility and is written in Swift. This makes dockutil a good choice if you don't have a 'management python' or you're more comfortable writing user setup scripts in bash or zsh. Dockutil also has an `--allhomes` argument that allows Dock configuration for all users to be modified at the same time. Docklib isn't designed for this, instead focusing on configuring the Dock for the user that is currently logged in (for example, via an [outset](https://github.com/macadmins/outset) `login-once` or `login-every` script). [Here's](https://appleshare.it/posts/use-dockutil-in-a-script/) a great article to get you started with dockutil, if that sounds like what you're after.
1414

1515
## Installation
1616

docklib/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .docklib import *
22

3-
__version__ = "1.3.0"
3+
__version__ = "2.0.0"

docklib/docklib.py

+25-43
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
# pylint: disable=C0103
42

53
"""Python module intended to assist IT administrators with manipulation of the macOS Dock.
@@ -9,18 +7,7 @@
97

108
import os
119
import subprocess
12-
from distutils.version import LooseVersion
13-
from platform import mac_ver
14-
15-
try:
16-
# Python 3
17-
from urllib.parse import unquote, urlparse
18-
except ImportError:
19-
# Python 2
20-
from urllib import unquote
21-
22-
from urlparse import urlparse
23-
10+
from urllib.parse import unquote, urlparse
2411

2512
# pylint: disable=E0611
2613
from Foundation import (
@@ -50,38 +37,33 @@ class Dock:
5037
_SECTIONS = ["persistent-apps", "persistent-others"]
5138
_MUTABLE_KEYS = [
5239
"autohide",
53-
"orientation",
54-
"tilesize",
55-
"largesize",
56-
"orientation-immutable",
57-
"position-immutable",
5840
"autohide-immutable",
41+
"contents-immutable",
42+
"dblclickbehavior",
43+
"largesize",
44+
"launchanim",
45+
"launchanim-immutable",
5946
"magnification",
6047
"magnification-immutable",
6148
"magsize-immutable",
62-
"show-progress-indicators",
63-
"contents-immutable",
64-
"size-immutable",
6549
"mineffect",
6650
"mineffect-immutable",
67-
"size-immutable",
6851
"minimize-to-application",
6952
"minimize-to-application-immutable",
53+
"orientation",
54+
"orientation-immutable",
55+
"position-immutable",
56+
"tilesize",
7057
"show-process-indicators",
71-
"launchanim",
72-
"launchanim-immutable",
58+
"show-progress-indicators",
59+
"show-recents",
60+
"show-recents-immutable",
61+
"size-immutable",
62+
"windowtabbing",
63+
"AllowDockFixupOverride",
7364
]
7465

75-
_IMMUTABLE_KEYS = ["mod-count", "trash-full"]
76-
if LooseVersion(mac_ver()[0]) >= LooseVersion("10.12"):
77-
_MUTABLE_KEYS.append("AllowDockFixupOverride")
78-
if LooseVersion(mac_ver()[0]) >= LooseVersion("10.14"):
79-
_MUTABLE_KEYS.append("show-recents")
80-
_IMMUTABLE_KEYS.append("recent-apps")
81-
if LooseVersion(mac_ver()[0]) >= LooseVersion("10.15"):
82-
_MUTABLE_KEYS.extend(
83-
["dblclickbehavior", "show-recents-immutable", "windowtabbing"]
84-
)
66+
_IMMUTABLE_KEYS = ["mod-count", "recent-apps", "trash-full"]
8567

8668
items = {}
8769

@@ -107,8 +89,8 @@ def save(self):
10789
for key in self._SECTIONS:
10890
try:
10991
CFPreferencesSetAppValue(key, self.items[key], self._DOMAIN)
110-
except Exception:
111-
raise DockError
92+
except Exception as exc:
93+
raise DockError from exc
11294
for key in self._MUTABLE_KEYS:
11395
# Python doesn't support hyphens in attribute names, so convert
11496
# to/from underscores as needed.
@@ -119,8 +101,8 @@ def save(self):
119101
getattr(self, key.replace("-", "_")),
120102
self._DOMAIN,
121103
)
122-
except Exception:
123-
raise DockError
104+
except Exception as exc:
105+
raise DockError from exc
124106
if not CFPreferencesAppSynchronize(self._DOMAIN):
125107
raise DockError
126108

@@ -253,12 +235,12 @@ def replaceDockEntry(
253235
if found_index > -1:
254236
self.items[section][found_index] = newitem
255237

256-
def makeDockAppSpacer(self, type="spacer-tile"):
238+
def makeDockAppSpacer(self, tile_type="spacer-tile"):
257239
"""Makes an empty space in the Dock."""
258-
if type not in ["spacer-tile", "small-spacer-tile"]:
259-
msg = "{0}: invalid makeDockAppSpacer type.".format(type)
240+
if tile_type not in ["spacer-tile", "small-spacer-tile"]:
241+
msg = f"{tile_type}: invalid makeDockAppSpacer type."
260242
raise ValueError(msg)
261-
result = {"tile-data": {}, "tile-type": type}
243+
result = {"tile-data": {}, "tile-type": tile_type}
262244

263245
return result
264246

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyobjc==10.1

tests/unit.py

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def test_20_tile_data_keys(self):
6363
"file-label",
6464
"file-mod-date",
6565
"file-type",
66+
"is-beta",
6667
"label",
6768
"parent-mod-date",
6869
"preferreditemsize",

0 commit comments

Comments
 (0)