diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index da8bcbe..2c1261b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -167,6 +167,39 @@ jobs: name: python-dist path: release-assets + - name: Download corresponding esptool source archive + run: | + python - <<'PY' + import subprocess + import sys + import tomllib + from pathlib import Path + + project = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8")) + requirement = next( + item for item in project["project"]["dependencies"] + if item.lower().startswith("esptool==") + ) + version = requirement.split("==", 1)[1] + subprocess.run( + [ + sys.executable, + "-m", + "pip", + "download", + "--no-deps", + "--no-binary=:all:", + "--dest", + "release-assets", + "esptool==" + version, + ], + check=True, + ) + source_archive = Path("release-assets") / ("esptool-" + version + ".tar.gz") + if not source_archive.is_file(): + raise SystemExit("esptool corresponding source archive was not downloaded") + PY + - name: Publish release uses: softprops/action-gh-release@v2 with: diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..872e0cb --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Edward Chamberlain + +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. diff --git a/README.md b/README.md index 97b5a9b..18b03d2 100644 --- a/README.md +++ b/README.md @@ -229,3 +229,10 @@ Use GPIO numbers, not physical pin positions. - Disconnect power before changing wiring. - Once configured a "power only" cable will be ok as no data is transferred. - You can power this from the P1S internal USB port. + +## Licence + +Bambutton is released under the [MIT Licence](LICENSE). The distributed setup +application and firmware also contain third-party components; see +[third-party notices](THIRD_PARTY_NOTICES.md) and the notices shipped with the +firmware. diff --git a/THIRD_PARTY_LICENSES/pyserial-3.5-LICENSE.txt b/THIRD_PARTY_LICENSES/pyserial-3.5-LICENSE.txt new file mode 100644 index 0000000..8920d4e --- /dev/null +++ b/THIRD_PARTY_LICENSES/pyserial-3.5-LICENSE.txt @@ -0,0 +1,39 @@ +Copyright (c) 2001-2020 Chris Liechti +All Rights Reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +--------------------------------------------------------------------------- +Note: +Individual files contain the following tag instead of the full license text. + + SPDX-License-Identifier: BSD-3-Clause + +This enables machine processing of license information based on the SPDX +License Identifiers that are here available: http://spdx.org/licenses/ diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md new file mode 100644 index 0000000..7ea401f --- /dev/null +++ b/THIRD_PARTY_NOTICES.md @@ -0,0 +1,23 @@ +# Third-party software notices + +Bambutton includes and redistributes third-party software under the terms of +its respective licence. These licences are separate from Bambutton's MIT +licence. The desktop application includes licence documents supplied by its +active runtime dependencies in `third_party_licenses/`. It also includes the +pinned pyserial licence text from `THIRD_PARTY_LICENSES/` and the firmware +notices and licence texts from `firmware/LICENSES/`. + +| Component | Version | Licence | Upstream licence/source | +| --- | --- | --- | --- | +| esptool | 5.2.0 | GPL-2.0-or-later | [Licence and source](https://github.com/espressif/esptool/tree/v5.2.0); the matching source archive is published with each Bambutton desktop release. | +| FreeSimpleGUI | 5.2.0.post1 | LGPL-3.0-or-later | The desktop build includes the full licence text from the installed distribution metadata and its [upstream notice](https://github.com/spyoungtech/FreeSimpleGUI/blob/main/NOTICE). | +| pyserial | 3.5 | BSD-3-Clause | The full text is included at `third_party_licenses/pyserial-3.5-LICENSE.txt`; see the [upstream licence](https://github.com/pyserial/pyserial/blob/v3.5/LICENSE.txt). | +| mpremote | 1.28.0 | MIT | [MicroPython source](https://github.com/micropython/micropython/tree/v1.28.0/tools/mpremote) | +| MicroPython ESP32-C3 firmware | v1.28.0 | MIT plus ESP-IDF component notices | See [`firmware/THIRD_PARTY_NOTICES.md`](firmware/THIRD_PARTY_NOTICES.md) and the included files under `firmware/LICENSES/`. | + +The application also installs transitive Python runtime dependencies. Their +licence documents are collected from active runtime requirements when the +desktop application is built. Long licence texts stored in package metadata +are included too. Source and wheel distributions declare the runtime +dependencies in `pyproject.toml`; each dependency retains its own licence and +copyright terms. diff --git a/firmware/LICENSES/ESP-IDF-COPYRIGHT-v5.5.1.rst b/firmware/LICENSES/ESP-IDF-COPYRIGHT-v5.5.1.rst new file mode 100644 index 0000000..bf9ad5f --- /dev/null +++ b/firmware/LICENSES/ESP-IDF-COPYRIGHT-v5.5.1.rst @@ -0,0 +1,178 @@ +Copyrights and Licenses +*********************** + +:link_to_translation:`zh_CN:[中文]` + +Software Copyrights +=================== + +All original source code in this repository is Copyright (C) 2015-2023 Espressif Systems. This source code is licensed under the Apache License 2.0 as described in the file LICENSE. + +Additional third party copyrighted code is included under the following licenses. + +Where source code headers specify Copyright & License information, this information takes precedence over the summaries made here. + +Some examples use external components which are not Apache licensed, please check the copyright description in each example source code. + +Firmware Components +------------------- + +These third party libraries can be included into the application (firmware) produced by ESP-IDF. + +* :component:`Newlib ` is licensed under the BSD License, with copyright held by the respective parties, as described in :component_file:`COPYING.NEWLIB `. If :ref:`CONFIG_LIBC_PICOLIBC` is enabled, see also :component_file:`COPYING.picolibc `. + +:component:`Picolibc ` is licensed under the BSD License, with copyright held by the respective parties, as described in :component_file:`COPYING.picolibc `. + +* :component:`Xtensa header files ` are Copyright (C) 2013 Tensilica Inc and are licensed under the MIT License as reproduced in the individual header files. + +* Original parts of FreeRTOS_ (components/freertos) are Copyright (C) 2017 Amazon.com, Inc. or its affiliates, and are licensed under the MIT License, as described in :component_file:`license.txt `. + +* Original parts of LWIP_ (components/lwip) are Copyright (C) 2001, 2002 Swedish Institute of Computer Science and are licensed under the BSD License as described in :component_file:`COPYING file `. + +* `wpa_supplicant`_, Copyright (C) 2003-2022 Jouni Malinen and contributors and licensed under the BSD License. + +* :component_file:`Fast PBKDF2 `, Copyright (C) 2015 Joseph Birr-Pixton and licensed under CC0 Public Domain Dedication License. + +* `FreeBSD net80211`_, Copyright (C) 2004-2008 Sam Leffler, Errno Consulting and licensed under the BSD License. + +* `argtable3`_ argument parsing library, Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann and licensed under 3-clause BSD license. argtable3 also includes the following software components. For details, please see argtable3 :component_file:`LICENSE file `. + + * C Hash Table library, Copyright (C) 2002 Christopher Clark and licensed under 3-clause BSD License. + * The Better String library, Copyright (C) 2014 Paul Hsieh and licensed under 3-clause BSD License. + * TCL library, Copyright the Regents of the University of California, Sun Microsystems, Inc., Scriptics Corporation, ActiveState Corporation and other parties, and licensed under TCL/TK License. + +* `linenoise`_ line editing library, Copyright (C) 2010-2014 Salvatore Sanfilippo, Copyright (C) 2010-2013 Pieter Noordhuis, licensed under 2-clause BSD License. + +* `FatFS`_ library, Copyright (C) 2017 ChaN, is licensed under :component_file:`a BSD-style license `. + +* `cJSON`_ library, Copyright (C) 2009-2017 Dave Gamble and cJSON contributors, is licensed under MIT License as described in :component_file:`LICENSE file `. + +* `micro-ecc`_ library, Copyright (C) 2014 Kenneth MacKay, is licensed under 2-clause BSD License. + +* `Mbed TLS`_ library, Copyright (C) 2006-2018 ARM Limited, is licensed under Apache License 2.0 as described in :component_file:`LICENSE file `. + +* `SPIFFS`_ library, Copyright (C) 2013-2017 Peter Andersson, is licensed under MIT License as described in :component_file:`LICENSE file `. + +* :component_file:`SD/MMC driver ` is derived from `OpenBSD SD/MMC driver`_, Copyright (C) 2006 Uwe Stuehler, and is licensed under BSD License. + +* :component:`ESP-MQTT ` Package (contiki-mqtt), Copyright (C) 2014 Stephen Robinson, MQTT-ESP - Tuan PM is licensed under Apache License 2.0 as described in :component_file:`LICENSE file `. + +* :component:`BLE Mesh ` is adapted from Zephyr Project, Copyright (C) 2017-2018 Intel Corporation and licensed under Apache License 2.0. + +* `mynewt-nimble`_, Copyright (C) 2015-2018 The Apache Software Foundation, is licensed under Apache License 2.0 as described in :component_file:`LICENSE file `. + +* `TLSF allocator `_, Copyright (C) 2006-2016 Matthew Conte, and licensed under the BSD 3-clause license. + +* :component:`openthread`, Copyright (C) The OpenThread Authors, is licensed under BSD License as described in :component_file:`LICENSE file `. + +* :component_file:`UBSAN runtime `, Copyright (C) 2016 Linaro Limited and Jiří Zárevúcky, licensed under the BSD 2-clause license. + +* :component:`HTTP Parser ` is based on src/http/ngx_http_parse.c from NGINX copyright Igor Sysoev. Additional changes are licensed under the same terms as NGINX and Joyent, Inc. and other Node contributors. For details please check :component_file:`LICENSE file `. + +* `SEGGER SystemView`_ target-side library, Copyright (C) 1995-2024 SEGGER Microcontroller GmbH, is licensed under BSD 1-clause license. + +* `protobuf-c`_ is Protocol Buffers implementation in C, Copyright (C) 2008-2022 Dave Benson and the protobuf-c authors. For details please check :component_file:`LICENSE file `. + +* `CMock`_ mock/stub generator for C, Copyright (C) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams, is licensed under MIT License as described in :component_file:`LICENSE file `. + +* `Unity`_ Simple Unit Testing library, Copyright (C) 2007-23 Mike Karlesky, Mark VanderVoord, Greg Williams, is licensed under MIT License as described in :component_file:`LICENSE file `. + +Documentation +------------- + +* HTML version of the `ESP-IDF Programming Guide`_ uses the Sphinx theme `sphinx_idf_theme`_, which is Copyright (C) 2013-2020 Dave Snider, Read the Docs, Inc. & contributors, and Espressif Systems (Shanghai) CO., LTD. It is based on `sphinx_rtd_theme`_. Both are licensed under MIT License. + +ROM Source Code Copyrights +========================== + +Espressif SoCs mask ROM hardware includes binaries compiled from portions of the following third party software: + +* :component:`Newlib `, licensed under the BSD License and is Copyright of various parties, as described in :component_file:`COPYING.NEWLIB `. + +* Xtensa libhal, Copyright (C) Tensilica Inc and licensed under the MIT License (see below). + +* TinyBasic_ Plus, Copyright (C) Mike Field & Scott Lawrence and licensed under the MIT License (see below). + +* miniz_, by Rich Geldreich - placed into the public domain. + +* TJpgDec_, Copyright (C) 2011 ChaN, all right reserved. See below for license. + +* Parts of Zephyr RTOS USB stack: + * `DesignWare USB device driver`_, Copyright (C) 2016 Intel Corporation and licensed under Apache License 2.0. + * `Generic USB device driver`_, Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl), 2016 Intel Corporation and licensed under BSD 3-clause license. + * `USB descriptors functionality`_, Copyright (C) 2017 PHYTEC Messtechnik GmbH, 2017-2018 Intel Corporation and licensed under Apache License 2.0. + * `USB DFU class driver`_, Copyright (C) 2015-2016 Intel Corporation, 2017 PHYTEC Messtechnik GmbH and licensed under BSD 3-clause license. + * `USB CDC ACM class driver`_, Copyright (C) 2015-2016 Intel Corporation and licensed under Apache License 2.0. + +.. only:: CONFIG_ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB + + * `Mbed TLS`_ library, Copyright (C) 2006-2018 ARM Limited and licensed under Apache 2.0 License. + +Xtensa libhal MIT License +========================= + +Copyright (C) 2003, 2006, 2010 Tensilica Inc. + +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. + +TinyBasic Plus MIT License +========================== + +Copyright (C) 2012-2013 Mike Field & Scott Lawrence. + +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. + +TJpgDec License +=============== + +TJpgDec - Tiny JPEG Decompressor R0.01 (C) 2011 ChaN, is a generic JPEG decompressor module for tiny embedded systems.This is a free software that opened for education, research and commercial developments under license policy of following terms: + +Copyright (C) 2011 ChaN, all right reserved. + +* The TJpgDec module is a free software and there is NO WARRANTY. +* No restriction on use. You can use, modify and redistribute it for personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY. +* Redistributions of source code must retain the above copyright notice. + + +.. _Newlib: https://sourceware.org/newlib/ +.. _Picolibc: https://keithp.com/picolibc/ +.. _FreeRTOS: https://freertos.org/ +.. _esptool.py: https://github.com/espressif/esptool +.. _LWIP: https://savannah.nongnu.org/projects/lwip/ +.. _TinyBasic: https://github.com/BleuLlama/TinyBasicPlus +.. _miniz: https://code.google.com/archive/p/miniz/ +.. _wpa_supplicant: https://w1.fi/wpa_supplicant/ +.. _FreeBSD net80211: https://github.com/freebsd/freebsd-src/tree/master/sys/net80211 +.. _TJpgDec: http://elm-chan.org/fsw/tjpgd/00index.html +.. _argtable3: https://github.com/argtable/argtable3 +.. _linenoise: https://github.com/antirez/linenoise +.. _fatfs: http://elm-chan.org/fsw/ff/00index_e.html +.. _cJSON: https://github.com/DaveGamble/cJSON +.. _micro-ecc: https://github.com/kmackay/micro-ecc +.. _OpenBSD SD/MMC driver: https://github.com/openbsd/src/blob/f303646/sys/dev/sdmmc/sdmmc.c +.. _Mbed TLS: https://github.com/Mbed-TLS/mbedtls +.. _spiffs: https://github.com/pellepl/spiffs +.. _CMock: https://github.com/ThrowTheSwitch/CMock +.. _protobuf-c: https://github.com/protobuf-c/protobuf-c +.. _Unity: https://github.com/ThrowTheSwitch/Unity +.. _asio: https://github.com/chriskohlhoff/asio +.. _mqtt: https://github.com/espressif/esp-mqtt +.. _zephyr: https://github.com/zephyrproject-rtos/zephyr +.. _mynewt-nimble: https://github.com/apache/mynewt-nimble +.. _ESP-IDF Programming Guide: https://docs.espressif.com/projects/esp-idf/en/latest/ +.. _sphinx_idf_theme: https://github.com/espressif/sphinx_idf_theme +.. _sphinx_rtd_theme: https://github.com/readthedocs/sphinx_rtd_theme +.. _SEGGER SystemView: https://www.segger.com/downloads/systemview/ +.. _DesignWare USB device driver: https://github.com/zephyrproject-rtos/zephyr/blob/v1.12-branch/drivers/usb/device/usb_dc_dw.c +.. _Generic USB device driver: https://github.com/zephyrproject-rtos/zephyr/blob/v1.12-branch/subsys/usb/usb_device.c +.. _USB descriptors functionality: https://github.com/zephyrproject-rtos/zephyr/blob/v1.12-branch/subsys/usb/usb_descriptor.c +.. _USB DFU class driver: https://github.com/zephyrproject-rtos/zephyr/blob/v1.12-branch/subsys/usb/class/usb_dfu.c +.. _USB CDC ACM class driver: https://github.com/zephyrproject-rtos/zephyr/blob/v1.12-branch/subsys/usb/class/cdc_acm.c diff --git a/firmware/LICENSES/ESP-IDF-LICENSE-v5.5.1.txt b/firmware/LICENSES/ESP-IDF-LICENSE-v5.5.1.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/firmware/LICENSES/ESP-IDF-LICENSE-v5.5.1.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/firmware/LICENSES/MicroPython-LICENSE-v1.28.0.txt b/firmware/LICENSES/MicroPython-LICENSE-v1.28.0.txt new file mode 100644 index 0000000..28b5239 --- /dev/null +++ b/firmware/LICENSES/MicroPython-LICENSE-v1.28.0.txt @@ -0,0 +1,88 @@ +The MIT License (MIT) + +Copyright (c) 2013-2026 Damien P. George + +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. + +-------------------------------------------------------------------------------- + +Unless specified otherwise (see below), the above license and copyright applies +to all files in this repository. + +Individual files may include additional copyright holders. + +The various ports of MicroPython may include third-party software that is +licensed under different terms. These licenses are summarised in the tree +below, please refer to these files and directories for further license and +copyright information. Note that (L)GPL-licensed code listed below is only +used during the build process and is not part of the compiled source code. + +/ (MIT) + /drivers + /cc3100 (BSD-3-clause) + /lib + /asf4 (Apache-2.0) + /axtls (BSD-3-clause) + /config + /scripts + /config (GPL-2.0-or-later) + /Rules.mak (GPL-2.0) + /berkeley-db-1xx (BSD-4-clause) + /btstack (See btstack/LICENSE) + /cmsis (BSD-3-clause) + /crypto-algorithms (NONE) + /libhydrogen (ISC) + /libmetal (BSD-3-clause) + /littlefs (BSD-3-clause) + /lwip (BSD-3-clause) + /mynewt-nimble (Apache-2.0) + /nrfx (BSD-3-clause) + /nxp_driver (BSD-3-Clause) + /oofatfs (BSD-1-clause) + /open-amp (BSD-3-clause) + /pico-sdk (BSD-3-clause) + /re15 (BSD-3-clause) + /stm32lib (BSD-3-clause) + /tinyusb (MIT) + /uzlib (Zlib) + /wiznet5k (MIT) + /logo (uses OFL-1.1) + /ports + /cc3200 + /hal (BSD-3-clause) + /simplelink (BSD-3-clause) + /FreeRTOS (GPL-2.0 with FreeRTOS exception) + /esp32 + /ppp_set_auth.* (Apache-2.0) + /rp2 + /mutex_extra.c (BSD-3-clause) + /clocks_extra.c (BSD-3-clause) + /stm32 + /usbd*.c (MCD-ST Liberty SW License Agreement V2) + /stm32_it.* (MIT + BSD-3-clause) + /system_stm32*.c (MIT + BSD-3-clause) + /boards + /startup_stm32*.s (BSD-3-clause) + /*/stm32*.h (BSD-3-clause) + /usbdev (MCD-ST Liberty SW License Agreement V2) + /usbhost (MCD-ST Liberty SW License Agreement V2) + /zephyr + /src (Apache-2.0) + /tools + /dfu.py (LGPL-3.0-only) diff --git a/firmware/THIRD_PARTY_NOTICES.md b/firmware/THIRD_PARTY_NOTICES.md new file mode 100644 index 0000000..e11b640 --- /dev/null +++ b/firmware/THIRD_PARTY_NOTICES.md @@ -0,0 +1,24 @@ +# Firmware notices + +`ESP32_GENERIC_C3-20260406-v1.28.0.bin` redistributes the official MicroPython +v1.28.0 ESP32-C3 firmware. The upstream ESP32 port uses Espressif ESP-IDF; its +v1.28.0 port documentation identifies ESP-IDF v5.5.1 as the recommended +version. + +The package includes these upstream notices and licence texts alongside the +firmware binary: + +- `LICENSES/MicroPython-LICENSE-v1.28.0.txt` contains the full MicroPython + MIT licence, copyright notice, and upstream summary of port-specific + third-party licences. +- `LICENSES/ESP-IDF-LICENSE-v5.5.1.txt` contains Espressif's Apache 2.0 + licence. +- `LICENSES/ESP-IDF-COPYRIGHT-v5.5.1.rst` contains Espressif's firmware + component copyright and licence disclosures, including Newlib, FreeRTOS, + lwIP, wpa_supplicant, Mbed TLS, and other components. + +These files are included in the Python wheel and source archive as well as the +desktop application distribution. Upstream references: +[MicroPython v1.28.0 licence](https://github.com/micropython/micropython/blob/v1.28.0/LICENSE), +[ESP-IDF v5.5.1 licence](https://github.com/espressif/esp-idf/blob/v5.5.1/LICENSE), +[ESP-IDF v5.5.1 copyright disclosures](https://github.com/espressif/esp-idf/blob/v5.5.1/docs/en/COPYRIGHT.rst). diff --git a/pyproject.toml b/pyproject.toml index ecfec95..b3122c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,8 @@ requires-python = ">=3.11" authors = [ { name = "Edward Chamberlain" }, ] +license = "MIT" +license-files = ["LICENSE"] dependencies = [ "esptool==5.2.0", "FreeSimpleGUI==5.2.0.post1", @@ -17,6 +19,14 @@ dependencies = [ ] dynamic = ["version"] +[project.urls] +Homepage = "https://github.com/EdwardChamberlain/Bambutton" +Repository = "https://github.com/EdwardChamberlain/Bambutton" +Documentation = "https://github.com/EdwardChamberlain/Bambutton/blob/main/README.md" +Issues = "https://github.com/EdwardChamberlain/Bambutton/issues" +Support = "https://github.com/EdwardChamberlain/Bambutton/issues" +Changelog = "https://github.com/EdwardChamberlain/Bambutton/releases" + [project.scripts] bambutton = "bambutton.gui:main" @@ -40,6 +50,9 @@ local_scheme = "no-local-version" packages = ["src/bambutton"] [tool.hatch.build.targets.wheel.force-include] +"LICENSE" = "bambutton/LICENSE" +"THIRD_PARTY_NOTICES.md" = "bambutton/THIRD_PARTY_NOTICES.md" +"THIRD_PARTY_LICENSES" = "bambutton/third_party_licenses" "micro/api.py" = "bambutton/micro/api.py" "micro/app_main.py" = "bambutton/micro/app_main.py" "micro/bambuddy_api.py" = "bambutton/micro/bambuddy_api.py" @@ -57,6 +70,9 @@ packages = ["src/bambutton"] [tool.hatch.build.targets.sdist] include = [ + "/LICENSE", + "/THIRD_PARTY_NOTICES.md", + "/THIRD_PARTY_LICENSES", "/README.md", "/pyproject.toml", "/src", diff --git a/scripts/build_gui.py b/scripts/build_gui.py index b610105..afa0b0d 100755 --- a/scripts/build_gui.py +++ b/scripts/build_gui.py @@ -1,15 +1,26 @@ #!/usr/bin/env python3 import os +import re import subprocess import sys +from importlib import metadata from pathlib import Path +from pathlib import PurePosixPath + +from packaging.requirements import Requirement PROJECT_ROOT = Path(__file__).resolve().parents[1] ENTRYPOINT = PROJECT_ROOT / "src" / "bambutton" / "gui.py" MICRO_DIR = PROJECT_ROOT / "micro" FIRMWARE_DIR = PROJECT_ROOT / "firmware" +PROJECT_LICENSE = PROJECT_ROOT / "LICENSE" +THIRD_PARTY_NOTICES = PROJECT_ROOT / "THIRD_PARTY_NOTICES.md" PYINSTALLER_CONFIG_DIR = PROJECT_ROOT / ".pyinstaller-cache" +RUNTIME_DISTRIBUTIONS = ("esptool", "FreeSimpleGUI", "mpremote") +REPOSITORY_LICENSES = { + "pyserial": PROJECT_ROOT / "THIRD_PARTY_LICENSES" / "pyserial-3.5-LICENSE.txt", +} MICRO_FILES = [ "api.py", "app_main.py", @@ -50,6 +61,11 @@ def main(): if not sys.platform.startswith("darwin"): command.append("--onefile") + for path in (PROJECT_LICENSE, THIRD_PARTY_NOTICES): + command.extend(["--add-data", data_arg(path, "bambutton")]) + + command.extend(third_party_license_data_args()) + for filename in MICRO_FILES: command.extend( [ @@ -73,6 +89,95 @@ def main(): subprocess.run(command, check=True, env=env) +def third_party_license_data_args(): + """Bundle licence texts for active runtime dependencies and requirements.""" + pending = list(RUNTIME_DISTRIBUTIONS) + seen = set() + destinations = set() + license_args = [] + + while pending: + name = pending.pop(0) + normalized = re.sub(r"[-_.]+", "-", name).lower() + if normalized in seen: + continue + seen.add(normalized) + try: + distribution = metadata.distribution(name) + except metadata.PackageNotFoundError: + continue + + for requirement_text in distribution.requires or (): + requirement = Requirement(requirement_text) + if requirement.marker and not requirement.marker.evaluate(): + continue + pending.append(requirement.name) + + found_license = False + license_contents = [] + for file in distribution.files or (): + relative = PurePosixPath(str(file)) + if not _is_license_document(relative.name): + continue + + source = Path(distribution.locate_file(file)) + if not source.is_file(): + continue + found_license = True + try: + license_contents.append(source.read_text(encoding="utf-8")) + except (OSError, UnicodeError): + pass + destination_dir = _third_party_destination(normalized, relative.parent) + _append_data_arg(license_args, destinations, source, destination_dir) + + metadata_license = getattr(distribution, "metadata", {}).get("License", "") + metadata_license = metadata_license.strip() + if len(metadata_license) >= 512 and not any( + metadata_license in content for content in license_contents + ): + source = PYINSTALLER_CONFIG_DIR / "licenses" / normalized / "LICENSE-METADATA.txt" + source.parent.mkdir(parents=True, exist_ok=True) + source.write_text(metadata_license + "\n", encoding="utf-8") + destination_dir = _third_party_destination( + normalized, PurePosixPath(".") + ) + _append_data_arg(license_args, destinations, source, destination_dir) + + fallback = REPOSITORY_LICENSES.get(normalized) + if fallback and fallback.is_file() and not found_license: + _append_data_arg( + license_args, + destinations, + fallback, + _third_party_destination(normalized, PurePosixPath(".")), + ) + + return license_args + + +def _is_license_document(filename): + lowered = filename.lower() + if lowered.endswith((".py", ".pyc", ".pyo", ".json", ".toml", ".yaml", ".yml")): + return False + return lowered.startswith(("license", "licence", "copying", "notice", "copyright")) + + +def _third_party_destination(distribution, relative_parent): + base = PurePosixPath("bambutton/third_party_licenses") / distribution + if str(relative_parent) in ("", "."): + return base.as_posix() + return (base / relative_parent).as_posix() + + +def _append_data_arg(arguments, destinations, source, destination_dir): + output = (destination_dir, source.name) + if output in destinations: + return + destinations.add(output) + arguments.extend(["--add-data", data_arg(source, destination_dir)]) + + def data_arg(source, destination): separator = ";" if sys.platform.startswith("win") else ":" return "{}{}{}".format(source, separator, destination) diff --git a/scripts/smoke_installed_package.py b/scripts/smoke_installed_package.py index 4ebd89c..748dc42 100644 --- a/scripts/smoke_installed_package.py +++ b/scripts/smoke_installed_package.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 """Smoke-test runtime resources in an installed wheel or source distribution.""" +from importlib import metadata from pathlib import Path +from urllib.parse import urlsplit def check_installed_package(): @@ -9,21 +11,74 @@ def check_installed_package(): package_root = Path(bambutton.__file__).resolve().parent required_files = ( + "LICENSE", + "THIRD_PARTY_NOTICES.md", "micro/app_main.py", "micro/boot.py", "micro/config_example.json", "micro/ota_manager.py", "micro/web_config.py", "firmware/ESP32_GENERIC_C3-20260406-v1.28.0.bin", + "firmware/LICENSES/MicroPython-LICENSE-v1.28.0.txt", + "firmware/LICENSES/ESP-IDF-LICENSE-v5.5.1.txt", + "firmware/LICENSES/ESP-IDF-COPYRIGHT-v5.5.1.rst", + "third_party_licenses/pyserial-3.5-LICENSE.txt", ) missing = [name for name in required_files if not (package_root / name).is_file()] if missing: raise RuntimeError( "Installed package is missing: {}".format(", ".join(missing)) ) + + check_distribution_metadata() return package_root +def check_distribution_metadata(): + distribution = metadata.distribution("bambutton") + package_metadata = distribution.metadata + if package_metadata.get("License-Expression") != "MIT": + raise RuntimeError("Installed package metadata must declare the MIT licence") + + required_urls = { + "Homepage", + "Repository", + "Documentation", + "Issues", + "Support", + "Changelog", + } + project_urls = {} + for entry in package_metadata.get_all("Project-URL", []): + name, separator, url = entry.partition(",") + if separator: + project_urls[name.strip()] = url.strip() + + missing_urls = sorted(required_urls - project_urls.keys()) + invalid_urls = sorted( + name + for name in required_urls & project_urls.keys() + if urlsplit(project_urls[name]).scheme != "https" + or urlsplit(project_urls[name]).netloc != "github.com" + ) + if missing_urls or invalid_urls: + details = [] + if missing_urls: + details.append("missing project URLs: {}".format(", ".join(missing_urls))) + if invalid_urls: + details.append("invalid project URLs: {}".format(", ".join(invalid_urls))) + raise RuntimeError("Installed package metadata has " + "; ".join(details)) + + license_files = [ + Path(str(file)) + for file in (distribution.files or ()) + if "licenses" in [part.lower() for part in Path(str(file)).parts[:-1]] + and Path(str(file)).name.lower() == "license" + ] + if not license_files: + raise RuntimeError("Installed package metadata is missing its licence file") + + def main(): package_root = check_installed_package() print("Installed Bambutton package is ready:", package_root) diff --git a/src/bambutton/gui.py b/src/bambutton/gui.py index ea8ada4..a32a168 100755 --- a/src/bambutton/gui.py +++ b/src/bambutton/gui.py @@ -6,6 +6,7 @@ import sys import tempfile import time +import webbrowser from pathlib import Path try: @@ -22,6 +23,8 @@ else: RESOURCE_ROOT = SOURCE_ROOT if (SOURCE_ROOT / "micro").exists() else PACKAGE_ROOT +LICENSE_PATH = RESOURCE_ROOT / "LICENSE" +THIRD_PARTY_NOTICES_PATH = RESOURCE_ROOT / "THIRD_PARTY_NOTICES.md" MICRO_DIR = RESOURCE_ROOT / "micro" CONFIG_EXAMPLE_PATH = MICRO_DIR / "config_example.json" DEFAULT_FIRMWARE_DIR = RESOURCE_ROOT / "firmware" @@ -194,6 +197,12 @@ def main(): if event == "-FLASH-": handle_flash(window, values) + + if event == "-LICENSE-": + open_legal_document(window, LICENSE_PATH) + + if event == "-THIRD_PARTY_NOTICES-": + open_legal_document(window, THIRD_PARTY_NOTICES_PATH) finally: window.close() @@ -393,6 +402,14 @@ def build_window(): font=("Helvetica", 10, "bold"), ) ], + [ + sg.Button("View licence", key="-LICENSE-", size=(14, 1)), + sg.Button( + "Third-party notices", + key="-THIRD_PARTY_NOTICES-", + size=(20, 1), + ), + ], ] window = sg.Window("Bambutton Setup", layout, finalize=True) @@ -401,6 +418,16 @@ def build_window(): return window +def open_legal_document(window, path): + try: + document = Path(path).resolve(strict=True) + if not webbrowser.open(document.as_uri()): + raise OSError("No application accepted the document") + except OSError as exc: + window["-STATUS-"].update(value="Could not open the licence information.") + sg.popup_error("Could not open document", str(exc)) + + def match_config_input_height(window): """Make the single-line path input as tall as the adjacent buttons.""" window.TKroot.update_idletasks() diff --git a/tests/test_license_packaging.py b/tests/test_license_packaging.py new file mode 100644 index 0000000..33ce51e --- /dev/null +++ b/tests/test_license_packaging.py @@ -0,0 +1,147 @@ +from pathlib import Path, PurePosixPath +import tomllib + +from scripts import build_gui + + +PROJECT_ROOT = Path(__file__).parents[1] + + +def test_project_metadata_and_archives_declare_and_include_licence(): + with (PROJECT_ROOT / "pyproject.toml").open("rb") as source: + project = tomllib.load(source) + + metadata = project["project"] + assert metadata["license"] == "MIT" + assert "LICENSE" in metadata["license-files"] + urls = metadata["urls"] + url_keys = ( + "Homepage", + "Repository", + "Documentation", + "Issues", + "Support", + "Changelog", + ) + for key in url_keys: + assert urls[key].startswith("https://github.com/EdwardChamberlain/Bambutton") + + wheel_files = project["tool"]["hatch"]["build"]["targets"]["wheel"][ + "force-include" + ] + assert wheel_files["LICENSE"] == "bambutton/LICENSE" + assert wheel_files["THIRD_PARTY_NOTICES.md"] == "bambutton/THIRD_PARTY_NOTICES.md" + assert wheel_files["THIRD_PARTY_LICENSES"] == "bambutton/third_party_licenses" + assert wheel_files["firmware"] == "bambutton/firmware" + + source_files = project["tool"]["hatch"]["build"]["targets"]["sdist"]["include"] + assert "/LICENSE" in source_files + assert "/THIRD_PARTY_NOTICES.md" in source_files + assert "/THIRD_PARTY_LICENSES" in source_files + assert "/firmware" in source_files + + +def test_desktop_build_collects_actual_runtime_dependency_licences(tmp_path, monkeypatch): + class Distribution: + def __init__(self, name, files=(), requires=(), license_text=""): + self.root = tmp_path / name + self.root.mkdir() + self.files = [] + for relative, content in files: + file_path = self.root / relative + file_path.parent.mkdir(parents=True, exist_ok=True) + file_path.write_text(content, encoding="utf-8") + self.files.append(PurePosixPath(relative)) + self.requires = list(requires) + self.metadata = {"License": license_text} + + def locate_file(self, file): + return self.root / str(file) + + distributions = { + "esptool": Distribution( + "esptool", + files=(("esptool-5.2.0.dist-info/licenses/LICENSE.txt", "GPL terms"),), + requires=( + "pyserial>=3.3; python_version >= '3.11'", + "dev-only; extra == 'dev'", + ), + ), + "freesimplegui": Distribution( + "freesimplegui", + files=(("NOTICE", "FreeSimpleGUI attribution"),), + license_text="Full LGPL terms " + ("L" * 900), + ), + "mpremote": Distribution( + "mpremote", files=(("licenses/LICENSE.txt", "mpremote MIT terms"),) + ), + "pyserial": Distribution("pyserial", license_text="BSD License"), + "dev-only": Distribution("dev-only"), + } + + def get_distribution(name): + try: + return distributions[name.lower().replace("_", "-")] + except KeyError as exc: + raise build_gui.metadata.PackageNotFoundError(name) from exc + + monkeypatch.setattr(build_gui.metadata, "distribution", get_distribution) + monkeypatch.setattr( + build_gui, + "RUNTIME_DISTRIBUTIONS", + ("esptool", "FreeSimpleGUI", "mpremote"), + ) + monkeypatch.setattr(build_gui, "PYINSTALLER_CONFIG_DIR", tmp_path / "cache") + + args = build_gui.third_party_license_data_args() + + joined_args = "\n".join(args) + assert "bambutton/third_party_licenses/esptool/esptool-5.2.0.dist-info/licenses" in joined_args + assert "bambutton/third_party_licenses/freesimplegui" in joined_args + assert "bambutton/third_party_licenses/mpremote/licenses" in joined_args + assert "bambutton/third_party_licenses/pyserial" in joined_args + assert "dev-only" not in joined_args + generated_license = ( + tmp_path / "cache" / "licenses" / "freesimplegui" / "LICENSE-METADATA.txt" + ) + assert generated_license.read_text(encoding="utf-8").startswith("Full LGPL terms") + assert "pyserial-3.5-LICENSE.txt" in joined_args + + +def test_firmware_and_application_notice_files_exist(): + assert (PROJECT_ROOT / "LICENSE").read_text().startswith("MIT License\n") + notices = (PROJECT_ROOT / "THIRD_PARTY_NOTICES.md").read_text() + assert "GPL-2.0-or-later" in notices + assert "pyserial" in notices + firmware_notices = (PROJECT_ROOT / "firmware" / "THIRD_PARTY_NOTICES.md").read_text() + assert "v1.28.0" in firmware_notices + assert "v5.5.1" in firmware_notices + assert "Firmware Components" in ( + PROJECT_ROOT + / "firmware" + / "LICENSES" + / "ESP-IDF-COPYRIGHT-v5.5.1.rst" + ).read_text() + assert "Copyright (c) 2001-2020 Chris Liechti" in ( + PROJECT_ROOT / "THIRD_PARTY_LICENSES" / "pyserial-3.5-LICENSE.txt" + ).read_text() + + +def test_release_workflow_publishes_matching_esptool_source_archive(): + workflow = (PROJECT_ROOT / ".github" / "workflows" / "release.yml").read_text() + assert "Download corresponding esptool source archive" in workflow + assert "--no-binary=:all:" in workflow + assert "esptool==" in workflow + + +def test_open_legal_document_uses_the_default_browser(tmp_path, monkeypatch): + path = tmp_path / "LICENSE" + path.write_text("terms") + opened = [] + import bambutton.gui as gui + + monkeypatch.setattr(gui.webbrowser, "open", lambda uri: opened.append(uri) or True) + + gui.open_legal_document({}, path) + + assert opened == [path.resolve().as_uri()] diff --git a/tests/test_package_smoke.py b/tests/test_package_smoke.py index 323ac9d..b71e14d 100644 --- a/tests/test_package_smoke.py +++ b/tests/test_package_smoke.py @@ -1,5 +1,7 @@ import runpy import sys +from email.message import Message +from pathlib import PurePosixPath from pathlib import Path from types import SimpleNamespace @@ -8,15 +10,42 @@ SMOKE_PATH = Path(__file__).parents[1] / "scripts" / "smoke_installed_package.py" REQUIRED_FILES = ( + "LICENSE", + "THIRD_PARTY_NOTICES.md", "micro/app_main.py", "micro/boot.py", "micro/config_example.json", "micro/ota_manager.py", "micro/web_config.py", "firmware/ESP32_GENERIC_C3-20260406-v1.28.0.bin", + "firmware/LICENSES/MicroPython-LICENSE-v1.28.0.txt", + "firmware/LICENSES/ESP-IDF-LICENSE-v5.5.1.txt", + "firmware/LICENSES/ESP-IDF-COPYRIGHT-v5.5.1.rst", + "third_party_licenses/pyserial-3.5-LICENSE.txt", ) +def fake_distribution(): + package_metadata = Message() + package_metadata["License-Expression"] = "MIT" + package_metadata["License-File"] = "LICENSE" + for name in ( + "Homepage", + "Repository", + "Documentation", + "Issues", + "Support", + "Changelog", + ): + package_metadata["Project-URL"] = ( + "{}, https://github.com/EdwardChamberlain/Bambutton".format(name) + ) + return SimpleNamespace( + metadata=package_metadata, + files=[PurePosixPath("bambutton-1.0.dist-info/licenses/LICENSE")], + ) + + def fake_package(tmp_path, include_all=True): package_root = tmp_path / "site-packages" / "bambutton" for filename in REQUIRED_FILES if include_all else REQUIRED_FILES[:-1]: @@ -30,6 +59,7 @@ def test_installed_package_smoke_finds_wheel_resources(tmp_path, monkeypatch): package = fake_package(tmp_path) monkeypatch.setitem(sys.modules, "bambutton", package) module = runpy.run_path(str(SMOKE_PATH), run_name="installed_package_smoke") + monkeypatch.setattr(module["metadata"], "distribution", lambda name: fake_distribution()) assert module["check_installed_package"]() == Path(package.__file__).parent @@ -37,6 +67,7 @@ def test_installed_package_smoke_finds_wheel_resources(tmp_path, monkeypatch): def test_installed_package_smoke_rejects_missing_resource(tmp_path, monkeypatch): monkeypatch.setitem(sys.modules, "bambutton", fake_package(tmp_path, False)) module = runpy.run_path(str(SMOKE_PATH), run_name="installed_package_smoke") + monkeypatch.setattr(module["metadata"], "distribution", lambda name: fake_distribution()) with pytest.raises(RuntimeError, match="Installed package is missing"): module["check_installed_package"]() @@ -45,6 +76,8 @@ def test_installed_package_smoke_rejects_missing_resource(tmp_path, monkeypatch) def test_smoke_script_entrypoint_prints_success(tmp_path, monkeypatch, capsys): package = fake_package(tmp_path) monkeypatch.setitem(sys.modules, "bambutton", package) + module = runpy.run_path(str(SMOKE_PATH), run_name="installed_package_smoke") + monkeypatch.setattr(module["metadata"], "distribution", lambda name: fake_distribution()) runpy.run_path(str(SMOKE_PATH), run_name="__main__") diff --git a/tests/test_script_entrypoints.py b/tests/test_script_entrypoints.py index e7c506e..b61d58f 100644 --- a/tests/test_script_entrypoints.py +++ b/tests/test_script_entrypoints.py @@ -22,6 +22,11 @@ def test_build_gui_main_invokes_pyinstaller_with_bundled_resources( monkeypatch.setattr(build_gui, "ENTRYPOINT", entrypoint) monkeypatch.setattr(build_gui, "MICRO_DIR", micro_dir) monkeypatch.setattr(build_gui, "FIRMWARE_DIR", firmware_dir) + monkeypatch.setattr(build_gui, "PROJECT_LICENSE", tmp_path / "LICENSE") + monkeypatch.setattr( + build_gui, "THIRD_PARTY_NOTICES", tmp_path / "THIRD_PARTY_NOTICES.md" + ) + monkeypatch.setattr(build_gui, "third_party_license_data_args", lambda: []) monkeypatch.setattr(build_gui.subprocess, "run", lambda *args, **kwargs: calls.append(args)) build_gui.main() @@ -32,6 +37,8 @@ def test_build_gui_main_invokes_pyinstaller_with_bundled_resources( assert str(entrypoint) == command[-1] assert any("bambutton/micro" in item for item in command) assert any("bambutton/firmware" in item for item in command) + assert any(str(tmp_path / "LICENSE") in item for item in command) + assert any(str(tmp_path / "THIRD_PARTY_NOTICES.md") in item for item in command) def test_run_main_passes_selected_device_to_mpremote(tmp_path, monkeypatch):