Skip to content

Commit

Permalink
Merge pull request #10 from timsutton/pyinstaller-20221004
Browse files Browse the repository at this point in the history
Set up PyInstaller for self-contained binary
  • Loading branch information
timsutton authored Oct 4, 2022
2 parents a534bb4 + d47625c commit b0f9115
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.DS_Store
.venv
build/
dist-*/
pkgroot/
*.pkg
*.pyc

*.spec
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

This is a simple command-line Python script that can check, set or unset a custom ColorSync ICC profile for a given display. It uses PyObjC and the most current (as of 2013) ColorSync API to do this.

## Usage
## Installation

You can either **(1)** download a pre-compiled executable, or **(2)** execute the script directly with a Python runtime you have available.

### 1. Pre-compiled executable

### Installing Python dependencies
Download the latest version from the [Releases](https://github.com/timsutton/customdisplayprofiles/releases/latest) section, make the file executable and run it. The executable contains the necessary runtime and libraries, bundled via [PyInstaller](https://pyinstaller.org/).

This script requires the 'pyobjc' package available through pip, e.g.:
### 2. Execute the script directly

Clone or download this repo (or just the single `customdisplayprofiles` script) and execute it directly. You'll also need to have the [PyObjC PyPi package](https://pypi.org/project/pyobjc/) installed and available in your Python runtime's environment:

`pip3 install pyobjc`

NOTE: This script calls for `import Foundation` and `import Quartz`, but these are not the modules installed through `pip install Foundation` or `pip install Quartz`.

## Usage

### Setting a profile

Expand All @@ -26,6 +33,7 @@ If you want to get a list of displays with their associated index:

`customdisplayprofiles displays`


### Configurable user scope

The `--user-scope` option allows you to define whether the profile will be applied to the "Current" or "Any" user domain, which may allow you set this preference as a default for all users:
Expand All @@ -36,6 +44,7 @@ Specifying `any` here requires root privileges, as it will write these preferenc

More information on the user preferences system on OS X can be found [here](https://developer.apple.com/library/mac/#documentation/userexperience/Conceptual/PreferencePanes/Concepts/Managing.html) and [here](http://developer.apple.com/library/ios/#DOCUMENTATION/MacOSX/Conceptual/BPRuntimeConfig/Articles/UserPreferences.html).


### Retrieving the current profile

The full path to an ICC profile can be printed to stdout:
Expand All @@ -46,6 +55,7 @@ This could be useful if you want to check the current setting using an idempoten

`current-path` will output nothing if there is no profile currently set for that display.


### Full details

A more complete dictionary of information can be printed with the `info` action:
Expand All @@ -70,10 +80,12 @@ A more complete dictionary of information can be printed with the `info` action:
}
</pre></code>


## Sample wrapper script

There's a (very simple) example script in the [sample-helper-login-script](https://github.com/timsutton/customdisplayprofiles/blob/master/sample-helper-login-script/configure_display_profiles.sh) folder, which demonstrates how you could wrap this utility in an environment where you don't manage the ICC profiles directly. Someone calibrating a display would only need to drop the profile in a known folder location, indexed by display number, and at login for all users, the desired color profiles are configured for each online display.


## Building a pkg

You might want to build a pkg to deploy the script to one or more Macs in your environment. To create a pkg so, you can run the `make` command in the repo folder.
Expand Down
28 changes: 28 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# This script will output a single self-contained executable at
# the output specified to pyinstaller's `--distpath` option

set -eu -o pipefail

# Pick a Python distribution to use, we'll use Apple's for now
PYTHON_DIST_BIN=/usr/bin/python3
# PYTHON_DIST_BIN=/opt/homebrew/bin/python3

# clean and setup
command -v deactivate && deactivate
rm -rf .venv dist-*
"${PYTHON_DIST_BIN}" -m venv .venv
source .venv/bin/activate

# build virtualenv
pip install -U pip
pip install -r requirements-build.txt

# build it
pyinstaller \
--clean \
--log-level DEBUG \
--distpath dist-onefile \
--onefile \
customdisplayprofiles
2 changes: 2 additions & 0 deletions requirements-build.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r requirements-dev.txt
-r requirements-pyinstaller.txt
10 changes: 10 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-r requirements.txt

black==22.1.0
click==8.0.4
isort==5.10.1
mypy-extensions==0.4.3
pathspec==0.9.0
platformdirs==2.5.0
tomli==2.0.1
typing_extensions==4.1.1
4 changes: 4 additions & 0 deletions requirements-pyinstaller.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
altgraph==0.17.3
macholib==1.16.2
pyinstaller==5.4.1
pyinstaller-hooks-contrib==2022.10
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyobjc==8.5.1

0 comments on commit b0f9115

Please sign in to comment.