diff --git a/CHANGELOG.md b/CHANGELOG.md index c45f1aa..5eb4868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,23 +1,24 @@ +## 2025/04/08 Release 5.0.0 - API Changes: - **NEW:** `Receiver` class - A subclass of `asyncio.Queue` - `Client`: - - `subscribe` and `unsubscribe` methods use new `Receiver` class + - **BREAKING:** `subscribe` and `unsubscribe` methods use new `Receiver` class - Emit unmatched exceptions on expecting receivers instead of resolving `client.closed` - `detect_baud_rate` exposes `timeout` and `retry_times` arguments - Document `detect_baud_rate` - - **Breaking:** `ClientProtocol`/`EffectClient` + - **BREAKING:** `ClientProtocol`/`EffectClient` - `crystalfontz.protocol.ClientProtocol` type has been replaced by `crystalfontz.effects.EffectClient` - `EffectClient` enforces a smaller API than `ClientProtocol` did previously - - `Response`: + - **BREAKING:** `Response`: - `Response.from_bytes` accepts bytes as from packets, rather than `__init__` - `Response.__init__` accepts properties as arguments - - `SpecialCharacter` API: + - **BREAKING:** `SpecialCharacter` API: - Rename `as_bytes` method to `to_bytes` - Store pixels as `List[List[bool]]` instead of `List[List[int]]` - `KeyState` includes `keypress: KeyPress` attribute - CLI changes: - - **Breaking:** CLI now invoked through `python3 -m crystalfontz` + - **BREAKING:** CLI now invoked through `python3 -m crystalfontz` - Optional unpackaged `crystalfontz` entry point at `./bin/crystalfontz` - Use `configurence` library - Respect `CRYSTALFONTZ_CONFIG_FILE` environment variable @@ -29,11 +30,6 @@ - `python3 -m crystalfontz line 2` - `python3 -m crystalfontz send` - Help for `python3 -m crystalfontz listen` `--for` option -- Integration tests: - - Use `python-gak` plugin - - Use snapshots - - Leverage a config file at `./tests/fixtures/crystalfontz.yaml` - - Can be overridden with `CRYSTALFONTZ_CONFIG_FILE` environment variable - **NEW:** Dbus support: - `crystalfontz.dbus.DbusInterface` dbus Interface class, implementing most commands - `crystalfontz.dbus.DbusClient` dbus client class @@ -42,6 +38,22 @@ - Optional unpackaged `crystalfontz.dbus.service` entry point at `./bin/crystalfontz-service` - `python3 -m crystalfontz.dbus.client` dbus client CLI - Optional unpackaged `crystalfontz.dbus.client` entry point at `./bin/crystalfontz-dbus` +- Packaging and Releases: + - `python-crystalfontz` COPR package spec + - This has been moved from + - **NEW:** `crystalfontz` COPR package + - Depends on `python-crystalfontz` COPR package + - Includes systemd unit for `python3 -m crystalfontz.dbus.service` + - **BREAKING:** Includes shim bin `crystalfontz` -> `python3 -m crystalfontz.dbus.client` + - Tito based release tagging + - GitHub release tarball + - Improved PyPI classifiers + - **BREAKING:** Release under MPL-2.0 license +- Integration tests: + - Use `python-gak` plugin + - Use snapshots + - Leverage a config file at `./tests/fixtures/crystalfontz.yaml` + - Can be overridden with `CRYSTALFONTZ_CONFIG_FILE` environment variable ## 2025/01/12 Version 4.0.0 - Fedora package on COPR: diff --git a/LICENSE b/LICENSE index cca054d..fa0086a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,373 @@ -MIT License - -Copyright (c) 2025 Josh Holbrook - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/copr/crystalfontz.yml b/copr/crystalfontz.yml new file mode 100644 index 0000000..0a2f8b9 --- /dev/null +++ b/copr/crystalfontz.yml @@ -0,0 +1,13 @@ +apiVersion: coprctl/v1alpha1 +kind: package-scm +metadata: + name: crystalfontz +spec: + auto_rebuild: true + ownername: jfhbrook + projectname: joshiverse + clone-url: https://github.com/jfhbrook/crystalfontz + commit: null + spec: crystalfontz.spec + type: git + method: tito diff --git a/copr/python-crystalfontz.yml b/copr/python-crystalfontz.yml new file mode 100644 index 0000000..a68e6b6 --- /dev/null +++ b/copr/python-crystalfontz.yml @@ -0,0 +1,13 @@ +apiVersion: coprctl/v1alpha1 +kind: package-pypi +metadata: + name: python-crystalfontz +spec: + auto_rebuild: true + projectname: jfhbrook/joshiverse + packagename: crystalfontz + packageversion: 5.0.0 + pythonversions: + - "3" + spec-generator: pyp2spec + template: "" diff --git a/crystalfontz.spec b/crystalfontz.spec new file mode 100644 index 0000000..c0da056 --- /dev/null +++ b/crystalfontz.spec @@ -0,0 +1,41 @@ +Name: crystalfontz +Version: 4.0.0 +Release: 1 +License: MPL-2.0 +Summary: Serial client and Linux service for Crystalfontz LCD displays + +URL: https://github.com/jfhbrook/crystalfontz +Source0: %{name}-%{version}.tar.gz +BuildArch: noarch + +Requires: python-crystalfontz +Requires: python-sdbus + +%description + + +%prep +%autosetup + + +%build +tar -xzf %{SOURCE0} + + +%install +mkdir -p %{buildroot}%{_prefix}/lib/systemd/system +mkdir -p %{buildroot}%{_bindir} +install -p -D -m 0644 systemd/crystalfontz.service %{buildroot}%{_prefix}/lib/systemd/system/crystalfontz.service +install -p -D -m 0644 dbus/org.jfhbrook.crystalfontz.conf %{buildroot}%{_prefix}/share/dbus-1/system.d/org.jfhbrook.crystalfontz.conf +install -p -m 755 bin/crystalfontz-dbus %{buildroot}%{_bindir}/crystalfontz + +%check + + +%files +%{_prefix}/lib/systemd/system/crystalfontz.service +%{_prefix}/share/dbus-1/system.d/org.jfhbrook.crystalfontz.conf +%{_bindir}/crystalfontz + +%changelog + diff --git a/crystalfontz.spec.tmpl b/crystalfontz.spec.tmpl new file mode 100644 index 0000000..f306f76 --- /dev/null +++ b/crystalfontz.spec.tmpl @@ -0,0 +1,41 @@ +Name: crystalfontz +Version: {{ .Env.VERSION }} +Release: {{ .Env.RELEASE }} +License: MPL-2.0 +Summary: Serial client and Linux service for Crystalfontz LCD displays + +URL: https://github.com/jfhbrook/crystalfontz +Source0: %{name}-%{version}.tar.gz +BuildArch: noarch + +Requires: python-crystalfontz +Requires: python-sdbus + +%description + + +%prep +%autosetup + + +%build +tar -xzf %{SOURCE0} + + +%install +mkdir -p %{buildroot}%{_prefix}/lib/systemd/system +mkdir -p %{buildroot}%{_bindir} +install -p -D -m 0644 systemd/crystalfontz.service %{buildroot}%{_prefix}/lib/systemd/system/crystalfontz.service +install -p -D -m 0644 dbus/org.jfhbrook.crystalfontz.conf %{buildroot}%{_prefix}/share/dbus-1/system.d/org.jfhbrook.crystalfontz.conf +install -p -m 755 bin/crystalfontz-dbus %{buildroot}%{_bindir}/crystalfontz + +%check + + +%files +%{_prefix}/lib/systemd/system/crystalfontz.service +%{_prefix}/share/dbus-1/system.d/org.jfhbrook.crystalfontz.conf +%{_bindir}/crystalfontz + +%changelog +{{ .Env.CHANGELOG }} diff --git a/dbus/org.jfhbrook.crystalfontz.conf b/dbus/org.jfhbrook.crystalfontz.conf new file mode 100644 index 0000000..8011b91 --- /dev/null +++ b/dbus/org.jfhbrook.crystalfontz.conf @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + diff --git a/docs/development.md b/docs/development.md index 76f4476..c3b35b0 100644 --- a/docs/development.md +++ b/docs/development.md @@ -46,7 +46,9 @@ ### Interactive - `run` - Thin wrapper around `uv run` -- `start` - Run `crystalfontz` CLI +- `client` - Run `crystalfontz` serial client CLI +- `service` - Run `crystalfontz.dbus.service` DBus service on user session bus +- `dbus-client` - Run `crystalfontz.dbus.client` DBus client CLI on user session bus - `console` - Run a Python repl - `shell` - Start a bash shell with a sourced virtualenv diff --git a/docs/install.md b/docs/install.md index 80aa955..05f191e 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,14 +1,32 @@ # Install +`crystalfontz` is released as a PyPI package, a series of COPR packages, and a GitHub release. + +## Python Package + `crystalfontz` is a Python package, and therefore can be installed [from PyPi](https://pypi.org/project/crystalfontz/), for instance with `pip`: ```sh pip install crystalfontz ``` -In addition, I have a Fedora package on COPR, which can be installed like so: +This package contains the Python library, with the CLIs exposed with Python's `-m` flag (ie. `python3 -m crystalfontz`). + +## COPR Packages + +I package `crystalfontz` for Fedora on COPR. It can be installed like so: ```sh sudo dnf copr enable jfhbrook/joshiverse sudo dnf install crystalfontz ``` + +This package installs the Python package via `python-crystalfontz`, configures the systemd service, and includes a bin called `crystalfontz` that wraps `python3 -m crystalfontz.dbus.client`. + +## GitHub Release + +`crystalfontz` is also published as a GitHub release: + + + +These releases simply contain packaged source code, and will mostly be useful for package authors. diff --git a/justfile b/justfile index 407a25a..d2be0fd 100644 --- a/justfile +++ b/justfile @@ -101,6 +101,15 @@ _clean-test: rm -f pytest_runner-*.egg rm -rf tests/__pycache__ +# Install systemd service files and dbus config for development purposes +install-service: + sudo install -p -D -m 0644 systemd/crystalfontz.service /usr/lib/systemd/system/crystalfontz.service + sudo install -p -D -m 0644 dbus/org.jfhbrook.crystalfontz.conf /usr/share/dbus-1/system.d/org.jfhbrook.crystalfontz.conf + +# Pull the crystalfontz service's logs with journalctl +service-logs: + journalctl -xeu crystalfontz.service + # Display the raw XML introspection of the live dbus service print-iface: dbus-send --system --dest=org.jfhbrook.crystalfontz "/" --print-reply org.freedesktop.DBus.Introspectable.Introspect @@ -115,7 +124,6 @@ shell: console: uv run jupyter console - # # Documentation # @@ -143,13 +151,88 @@ build: _clean-build: rm -rf dist -# Tag the release in git -tag: - uv run git tag -a "$(python3 -c 'import toml; print(toml.load(open("pyproject.toml", "r"))["project"]["version"])')" -m "Release $(python3 -c 'import toml; print(toml.load(open("pyproject.toml", "r"))["project"]["version"])')" +# Generate crystalfontz.spec +generate-spec: + ./scripts/generate-spec.sh "$(./scripts/version.py)" "$(./scripts/release-version.py)" + +# Update the package version in ./copr/python-crystalfontz.yml +copr-update-version: + VERSION="$(./scripts/version.py)" yq -i '.spec.packageversion = strenv(VERSION)' ./copr/python-crystalfontz.yml -# Build the package and publish it to PyPI -publish: build - uv publish +# Commit generated files +commit-generated-files: + git add requirements.txt + git add requirements_dev.txt + git add crystalfontz.spec + git add ./copr + git commit -m 'Update generated files' || echo 'No changes to files' + +# Fail if there are uncommitted files +check-dirty: + ./scripts/is-dirty.sh + +# Fail if not on the main branch +check-main-branch: + ./scripts/is-main-branch.sh + +# Tag the release with tito +tag: + ./scripts/tag.sh + +# Bundle the package for GitHub release +bundle-gh-release: + ./scripts/bundle-gh-release.sh "$(./scripts/version.py)-$(./scripts/release-version.py)" + +# Clean up the release package +clean-release: + rm -f "crystalfontz-*-*.tar.gz" + +# Push main and tags +push: + git push origin main --follow-tags + +# Publish package to PyPI +publish-pypi: build + uv publish -t "$(op item get 'PyPI' --fields 'API Token' --reveal)" + +# Create a GitHub release +gh-release: + bash ./scripts/gh-release.sh "$(python ./scripts/version.py)-$(python ./scripts/release-version.py)" + +# Apply a COPR package configuration +apply-copr package: + coprctl apply -f ./copr/{{ package }}.yml + +# Build a COPR package +build-copr package: + copr build-package jfhbrook/joshiverse --name '{{ package }}' + +# Publish the release on PyPI, GitHub and Copr +publish: + # Generate files and commit + @just compile + @just generate-spec + @just copr-update-version + @just commit-generated-files + # Ensure git is in a good state + @just check-main-branch + @just check-dirty + # Tag and push + @just tag + @just push + # Build package and bundle release + if [[ "$(./scripts/release-version.py)" == '1' ]]; then just clean-build; fi + @just clean-release + if [[ "$(./scripts/release-version.py)" == '1' ]]; then just build; fi + @just bundle-gh-release + # Publish package and release + @just gh-release + if [[ "$(./scripts/release-version.py)" == '1' ]]; then just publish-pypi; fi + # Update packages on COPR + if [[ "$(./scripts/release-version.py)" == '1' ]]; then just apply-copr python-crystalfontz; fi + @just apply-copr crystalfontz + if [[ "$(./scripts/release-version.py)" == '1' ]]; then just build-copr python-crystalfontz; fi + @just build-copr crystalfontz # Clean up loose files clean: _clean-venv _clean-compile _clean-test diff --git a/pyproject.toml b/pyproject.toml index 4c9f982..08778d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,28 +2,36 @@ requires = ["setuptools", "setuptools-scm", "wheel"] build-backend = "setuptools.build_meta" +[tool.rpm] +# Generally this is "1", but can be incremented to roll up bugfixes in the +# top-level `crystalfontz` Fedora package. +release = "1" + [project] name = "crystalfontz" version = "4.0.0" authors = [ {name = "Josh Holbrook", email = "josh.holbrook@gmail.com"} ] -description = "Library for interacting with crystalfontz LCD displays" +description = "Serial client and Linux service for Crystalfontz LCD displays" readme = "README.md" keywords = [] -license = { text = "Apache-2.0" } +license = { text = "MPL-2.0" } classifiers = [ "Programming Language :: Python", "Development Status :: 4 - Beta", "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", + "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "Operating System :: OS Independent", + "Operating System :: POSIX :: Linux", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", - "Topic :: Other/Nonlisted Topic", + "Topic :: System :: Hardware", + "Topic :: System :: Hardware :: Hardware Drivers", + "Topic :: Terminals :: Serial", ] requires-python = ">=3.11" dependencies = [ diff --git a/scripts/bundle-gh-release.sh b/scripts/bundle-gh-release.sh new file mode 100755 index 0000000..7d115a2 --- /dev/null +++ b/scripts/bundle-gh-release.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -euo pipefail + +FULL_VERSION="${1}" + +tar -czf "crystalfontz-${FULL_VERSION}.tar.gz" \ + CHANGELOG.md \ + LICENSE \ + README.md \ + docs \ + crystalfontz \ + crystalfontz.spec \ + pyproject.toml \ + pytest.ini \ + requirements.txt \ + requirements_dev.txt \ + setup.cfg \ + systemd \ + tests \ + typings \ + uv.lock diff --git a/scripts/changelog-entry.py b/scripts/changelog-entry.py new file mode 100755 index 0000000..fb94219 --- /dev/null +++ b/scripts/changelog-entry.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import re +import sys + +FULL_VERSION = sys.argv[1] +VERSION, RELEASE = FULL_VERSION.split("-") + +TITLE_RE = r"\d{4}\/\d{2}\/\d{2} Version (\d+\.\d+\.\d+)\-?(\d+)?" + +found = False +changelog = "" + +with open("CHANGELOG.md", "r") as f: + it = iter(f) + try: + while True: + line = next(it) + m = re.findall(TITLE_RE, line) + if not found and m and m[0][0] == VERSION and m[0][1] == RELEASE: + found = True + # Consume ---- line + next(it) + elif found and m: + # Found next entry + break + elif found: + changelog += line + else: + continue + except StopIteration: + pass + +if not found: + raise Exception(f"Could not find changelog entry for {FULL_VERSION}") + +print(changelog.strip()) diff --git a/scripts/generate-spec.sh b/scripts/generate-spec.sh new file mode 100755 index 0000000..5b8dc98 --- /dev/null +++ b/scripts/generate-spec.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -euo pipefail + +VERSION="${1}" +RELEASE="${2}" + +# Pulls the existing changelog already in the spec file. This is generated +# by Tito. +CHANGELOG="$(./scripts/spec-changelog.py)" + +export VERSION +export RELEASE +export CHANGELOG + +gomplate -f ./crystalfontz.spec.tmpl -o crystalfontz.spec diff --git a/scripts/gh-release.sh b/scripts/gh-release.sh new file mode 100755 index 0000000..3d66376 --- /dev/null +++ b/scripts/gh-release.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -euo pipefail + +FULL_VERSION="${1}" + +NOTES="$(./scripts/changelog-entry.py "${FULL_VERSION}")" + +gh release create "crystalfontz-${FULL_VERSION}" \ + -t "crystalfontz v${FULL_VERSION}" \ + -n "${NOTES}" \ + "crystalfontz-${FULL_VERSION}.tar.gz" diff --git a/scripts/is-dirty.sh b/scripts/is-dirty.sh new file mode 100755 index 0000000..b032b48 --- /dev/null +++ b/scripts/is-dirty.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -euo pipefail + +LINES="$(git status --porcelain)" + +echo "${LINES}" 1>&2 + +[ -z "${LINES}" ] diff --git a/scripts/is-main-branch.sh b/scripts/is-main-branch.sh new file mode 100755 index 0000000..2d44b61 --- /dev/null +++ b/scripts/is-main-branch.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -euo pipefail + +BRANCH="$(git rev-parse --abbrev-ref HEAD)" + +echo "${BRANCH}" 1>&2 + +[[ "${BRANCH}" == main ]] diff --git a/scripts/release-version.py b/scripts/release-version.py new file mode 100755 index 0000000..2d4bcb4 --- /dev/null +++ b/scripts/release-version.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import tomllib + +with open("pyproject.toml", "rb") as f: + project = tomllib.load(f) + + print(project["tool"]["rpm"]["release"]) diff --git a/scripts/spec-changelog.py b/scripts/spec-changelog.py new file mode 100755 index 0000000..c8b7ef1 --- /dev/null +++ b/scripts/spec-changelog.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import re + +SECTION_RE = r"%(changelog)" + +found = False +changelog = "" + +with open("crystalfontz.spec", "r") as f: + it = iter(f) + try: + while True: + line = next(it) + m = re.findall(SECTION_RE, line) + if not found and m and m[0] == "changelog": + found = True + elif found and m: + # Found next section + break + elif found: + changelog += line + else: + continue + except StopIteration: + pass + +if not found: + raise Exception("Could not find changelog in crystalfontz.spec") + +print(changelog.strip()) diff --git a/scripts/tag.sh b/scripts/tag.sh new file mode 100755 index 0000000..bfcc06f --- /dev/null +++ b/scripts/tag.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -euo pipefail + +VERSION="$(./scripts/version.py)" +RELEASE="$(./scripts/release-version.py)" +FULL_VERSION="${VERSION}-${RELEASE}" + +tito tag --use-version "${VERSION}" \ + --use-release "${RELEASE}" \ + --changelog="$(./scripts/changelog-entry.py "${FULL_VERSION}" | sed 's/^/ /')" diff --git a/scripts/version.py b/scripts/version.py new file mode 100755 index 0000000..3751520 --- /dev/null +++ b/scripts/version.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import tomllib + +with open("pyproject.toml", "rb") as f: + project = tomllib.load(f) + + print(project["project"]["version"]) diff --git a/systemd/crystalfontz.service b/systemd/crystalfontz.service new file mode 100644 index 0000000..7507e92 --- /dev/null +++ b/systemd/crystalfontz.service @@ -0,0 +1,13 @@ +[Unit] +Description=Crystalfontz LCD +Requires=dbus.socket +After=dbus.socket + +[Service] +Type=dbus +BusName=org.jfhbrook.crystalfontz +ExecStart=/usr/bin/python3 -m crystalfontz.dbus.service --system +Restart=on-failure + +[Install] +WantedBy=multi-user.target