Skip to content

Commit 4123ff5

Browse files
authored
Merge pull request #28 from homebysix/pypi
v1.2.0 - Reconfigure docklib repo structure to support publication of releases to PyPI
2 parents fc6f401 + a4ac069 commit 4123ff5

File tree

11 files changed

+382
-25
lines changed

11 files changed

+382
-25
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.DS_Store
2+
*.egg-info
23
*.pyc
34
build/
5+
dist/
6+
venv/

.pre-commit-config.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.4.0
3+
rev: v3.2.0
44
hooks:
55
- id: check-added-large-files
66
args: [--maxkb=100]
@@ -14,16 +14,12 @@ repos:
1414
- id: trailing-whitespace
1515
args: [--markdown-linebreak-ext=md]
1616
- repo: https://github.com/ambv/black
17-
rev: 19.10b0
17+
rev: 20.8b1
1818
hooks:
1919
- id: black
2020
language_version: python3.7
2121
- repo: https://github.com/asottile/blacken-docs
22-
rev: v1.5.0-1
22+
rev: v1.8.0
2323
hooks:
2424
- id: blacken-docs
25-
additional_dependencies: [black==19.3b0]
26-
- repo: https://github.com/homebysix/pre-commit-macadmin
27-
rev: v1.6.2
28-
hooks:
29-
- id: check-munkipkg-buildinfo
25+
additional_dependencies: [black==20.8b1]

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ All notable changes to this project will be documented in this file. This projec
88
Nothing yet.
99

1010

11+
## [1.2.0] - 2020-10-15
12+
13+
(Includes changes from briefly-published versions 1.1.0 and 1.1.1.)
14+
15+
### Added
16+
17+
- Published docklib to PyPI so that administrators can manage it with `pip` and more easily bundle it in [custom Python frameworks](https://github.com/macadmins/python). Adjusted repo file structure to match Python packaging standards.
18+
- Created __build_pkg.sh__ script for creation of macOS package installer.
19+
- Added `findExistingURL()` and `removeDockURLEntry()` functions for handling URL items.
20+
- Created a few basic unit tests.
21+
22+
### Changed
23+
24+
- Updated pre-commit configuration.
25+
26+
1127
## [1.0.5] - 2020-01-29
1228

1329
### Fixed
@@ -70,7 +86,9 @@ Nothing yet.
7086
- Initial release
7187

7288

73-
[Unreleased]: https://github.com/homebysix/docklib/compare/v1.0.4...HEAD
89+
[Unreleased]: https://github.com/homebysix/docklib/compare/v1.2.0...HEAD
90+
[1.2.0]: https://github.com/homebysix/docklib/compare/v1.0.5...v1.2.0
91+
[1.0.5]: https://github.com/homebysix/docklib/compare/v1.0.4...v1.0.5
7492
[1.0.4]: https://github.com/homebysix/docklib/compare/v1.0.3...v1.0.4
7593
[1.0.3]: https://github.com/homebysix/docklib/compare/v1.0.2...v1.0.3
7694
[1.0.2]: https://github.com/homebysix/docklib/compare/v1.0.1...v1.0.2

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,39 @@
22

33
This is a Python module intended to assist IT administrators with manipulation of the macOS Dock.
44

5-
Originally created as a [Gist](https://gist.github.com/gregneagle/5c422d709c93615341a21009f800222e) by @gregneagle, this fork has been modified to include support for some additional Dock features.
5+
Originally created as a [Gist](https://gist.github.com/gregneagle/5c422d709c93615341a21009f800222e) by @gregneagle, this fork has been modified to include support for some additional Dock features, and has been packaged for multiple distribution options.
66

77
## Installation
88

9-
Place the docklib.py file in your Python path so its contents can be imported into scripts you create. Or, include the file in the same directory as your script.
9+
There are multiple methods of installing docklib, depending on how you plan to use it.
1010

11-
The packages available in the [Releases](https://github.com/homebysix/docklib/releases) section will place the docklib.py file into /Library/Python/2.7/site-packages.
11+
### Package installer
12+
13+
You can use the included __build_pkg.sh__ script to build a macOS installer .pkg file. You can use this package to install docklib on your own Mac, or deploy the package using a tool like Jamf or Munki to install docklib on managed devices.
14+
15+
To run the script, `cd` to a local clone of this repository, then run:
16+
17+
```
18+
./build_pkg.sh
19+
```
20+
21+
The resulting pkg will be built in a temporary folder and shown in the Finder.
22+
23+
__NOTE__: The default install destination is __/Library/Python/2.7/site-packages/docklib__, which makes docklib available to the built-in macOS Python 2.7 framework. If you leverage a different Python installation, you'll need to modify this path in the __build_pkg.sh__ script prior to building the installer package.
24+
25+
### Pip
26+
27+
Docklib has been published to PyPI in order to make it available for installation using pip.
28+
29+
```
30+
pip install docklib
31+
```
32+
33+
This method is not intended to be used directly on managed devices, but it could be leveraged alongside a custom Python framework (like one built with [macadmins/python](https://github.com/macadmins/python) or [relocatable-python](https://github.com/gregneagle/relocatable-python)) using a requirements file.
34+
35+
### Manual
36+
37+
Another method of using docklib is to simply place the docklib.py file in the same location as the Python script(s) you use to manipulate the macOS dock. Some examples of such scripts are included below.
1238

1339
## Examples
1440

@@ -154,5 +180,3 @@ dock.items["persistent-apps"] = [
154180
]
155181
dock.save()
156182
```
157-
158-

RELEASING.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Releasing new versions of docklib
2+
3+
1. Ensure the version in __\_\_init\_\_.py__ has been updated.
4+
5+
1. Ensure the change log has been updated and reflects actual release date.
6+
7+
1. Merge development branch to main/master branch.
8+
9+
1. Run docklib unit tests and fix any errors:
10+
11+
/usr/local/munki/munki-python -m unittest -v tests/unit.py
12+
13+
1. Build a new distribution package:
14+
15+
rm -fv dist/*
16+
python3 setup.py sdist bdist_wheel
17+
18+
1. Upload package to test.pypi.org:
19+
20+
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
21+
22+
1. View resulting project on test.pypi.org and make sure it looks good.
23+
24+
1. Install test docklib in Munki Python on a test Mac:
25+
26+
/usr/local/munki/Python.framework/Versions/Current/bin/python3 -m pip install --upgrade -i https://test.pypi.org/simple/ docklib
27+
28+
1. Perform tests - manual for now.
29+
30+
1. Upload package to pypi.org:
31+
32+
twine upload dist/*
33+
34+
1. View resulting project on pypi.org and make sure it looks good.
35+
36+
1. Install production docklib in Munki Python on a test Mac:
37+
38+
/usr/local/munki/Python.framework/Versions/Current/bin/python3 -m pip install --upgrade docklib
39+
40+
1. Build new installer package using __build_pkg.sh__:
41+
42+
./build_pkg.sh
43+
44+
1. Create new release on GitHub. Add notes from change log. Attach built installer package.
45+
46+
1. Announce to [dock-management](https://macadmins.slack.com/archives/C17NRH534) and other relevant channels, if desired.

build-info.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

build_pkg.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
cd "$(dirname "$0")" || exit 1
4+
5+
echo "Preparing source folder..."
6+
rm -rfv ./docklib/__pycache__
7+
rm -fv ./docklib/*.pyc
8+
9+
echo "Preparing pkgroot and output folders..."
10+
PKGROOT=$(mktemp -d /tmp/docklib-build-root-XXXXXXXXXXX)
11+
OUTPUTDIR=$(mktemp -d /tmp/docklib-output-XXXXXXXXXXX)
12+
mkdir -p "$PKGROOT/Library/Python/2.7/site-packages/"
13+
14+
echo "Copying docklib into pkgroot..."
15+
# Customize this path if you're not using the macOS built-in Python 2.7 with docklib.
16+
cp -R ./docklib "$PKGROOT/Library/Python/2.7/site-packages/docklib"
17+
18+
echo "Determining version..."
19+
VERSION=$(awk -F \" '/version/{print $2}' docklib/__init__.py)
20+
echo " Version: $VERSION"
21+
22+
echo "Building package..."
23+
OUTFILE="$OUTPUTDIR/docklib-$VERSION.pkg"
24+
pkgbuild --root "$PKGROOT" --identifier com.elliotjordan.docklib --version "$VERSION" "$OUTFILE"
25+
echo "$OUTFILE"
26+
open "$OUTPUTDIR"

docklib/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .docklib import *
2+
3+
__version__ = "1.2.0"

payload/Library/Python/2.7/site-packages/docklib.py renamed to docklib/docklib.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#!/usr/bin/python
21
# -*- coding: utf-8 -*-
32

43
# pylint: disable=C0103
54

6-
"""Routines for manipulating the Dock."""
5+
"""Python module intended to assist IT administrators with manipulation of the macOS Dock."""
76

87
import os
98
import subprocess
@@ -18,6 +17,7 @@
1817
CFPreferencesSetAppValue,
1918
)
2019

20+
2121
# pylint: enable=E0611
2222

2323

@@ -124,6 +124,18 @@ def findExistingLabel(self, test_label, section="persistent-apps"):
124124

125125
return -1
126126

127+
def findExistingURL(self, test_url):
128+
"""Returns index of item with URL matching test_url or -1 if not
129+
found."""
130+
section_items = self.items["persistent-others"]
131+
if section_items:
132+
for index, item in enumerate(section_items):
133+
if item["tile-data"].get("url"):
134+
if item["tile-data"]["url"]["_CFURLString"] == test_url:
135+
return index
136+
137+
return -1
138+
127139
def removeDockEntry(self, label, section=None):
128140
"""Removes a Dock entry with matching label, if any."""
129141
if section:
@@ -135,6 +147,12 @@ def removeDockEntry(self, label, section=None):
135147
if found_index > -1:
136148
del self.items[sect][found_index]
137149

150+
def removeDockURLEntry(self, url):
151+
"""Removes a Dock entry with matching url, if any."""
152+
found_index = self.findExistingURL(url)
153+
if found_index > -1:
154+
del self.items["persistent-others"][found_index]
155+
138156
def replaceDockEntry(self, thePath, label=None, section="persistent-apps"):
139157
"""Replaces a Dock entry.
140158

setup.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""setup.py for docklib"""
2+
3+
import pathlib
4+
5+
from setuptools import setup
6+
7+
# The directory containing this file
8+
HERE = pathlib.Path(__file__).parent
9+
10+
# The text of the README file
11+
README = (HERE / "README.md").read_text()
12+
13+
14+
def get_version(rel_path):
15+
"""Given a path to a Python init file, return the version string."""
16+
with open(rel_path, "r") as openfile:
17+
lines = openfile.readlines()
18+
for line in lines:
19+
if line.startswith("__version__"):
20+
delim = '"' if '"' in line else "'"
21+
return line.split(delim)[1]
22+
raise RuntimeError("Unable to find version string.")
23+
24+
25+
setup(
26+
name="docklib",
27+
version=get_version("docklib/__init__.py"),
28+
description=(
29+
"Python module intended to assist IT "
30+
"administrators with manipulation of the macOS Dock."
31+
),
32+
long_description=README,
33+
long_description_content_type="text/markdown",
34+
url="https://github.com/homebysix/docklib",
35+
author="Elliot Jordan",
36+
author_email="[email protected]",
37+
license="Apache 2.0",
38+
classifiers=[
39+
"Development Status :: 5 - Production/Stable",
40+
"Environment :: MacOS X",
41+
"Intended Audience :: Information Technology",
42+
"Intended Audience :: System Administrators",
43+
"License :: OSI Approved :: Apache Software License",
44+
"Programming Language :: Python :: 2",
45+
"Programming Language :: Python :: 3",
46+
"Topic :: System :: Systems Administration",
47+
"Topic :: Utilities",
48+
],
49+
packages=["docklib"],
50+
include_package_data=True,
51+
)

0 commit comments

Comments
 (0)