diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f0e931ec32..d9a2aa1890 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,6 +38,12 @@ repos: entry: python utils/logging/generate_overview.py language: python language_version: python3 + - id: python3-requirements + name: python3-requirements + description: Check if requirements.txt matches the buildsystem. + entry: 'utils/check-requirements.py' + language: script + files: requirements\.txt$ - repo: https://github.com/pre-commit/pre-commit-hooks rev: 'v2.4.0' hooks: diff --git a/CMakeLists.txt b/CMakeLists.txt index 94cfcc555a..a8bf133cf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,6 @@ include(ExternalProject) include(cmake/Utilities.cmake) include(cmake/GetGitRevisionDescription.cmake) include(cmake/ProjectVersion.cmake) -include(cmake/CheckRemotes.cmake) include(cmake/Littlefs.cmake) include(cmake/Options.cmake) diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 62ebb3376e..0000000000 --- a/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM python:3.8 - -WORKDIR /buddy - -COPY ./utils/bootstrap.py /buddy/utils/bootstrap.py -RUN python /buddy/utils/bootstrap.py && (cd .dependencies && find . -type f -executable | xargs echo chmod +x) diff --git a/cmake/CheckRemotes.cmake b/cmake/CheckRemotes.cmake deleted file mode 100644 index 8a6b396787..0000000000 --- a/cmake/CheckRemotes.cmake +++ /dev/null @@ -1,47 +0,0 @@ -find_package(Git QUIET) - -if(NOT GIT_FOUND) - message(STATUS "Not Git Executable found. Skipping check for dangerous Git remotes.") - return() -endif() - -function(check_git_repo_for_dangerous_remotes repo_dir) - execute_process( - COMMAND "${GIT_EXECUTABLE}" remote - WORKING_DIRECTORY "${repo_dir}" - RESULT_VARIABLE res - OUTPUT_VARIABLE lst - ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - if(NOT res STREQUAL "0") - message(WARNING "Failed to check dangerousness of your Git remotes!") - return() - endif() - - string(REPLACE "\n" ";" lst ${lst}) - foreach(item ${lst}) - execute_process( - COMMAND "${GIT_EXECUTABLE}" remote get-url --push ${item} - WORKING_DIRECTORY "${repo_dir}" - RESULT_VARIABLE res - OUTPUT_VARIABLE url - ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - if(NOT res STREQUAL 0) - message(WARNING "Failed to check dangerousness of remote '${item}'!") - endif() - - if(url MATCHES "Prusa\-Firmware\-Buddy.git" OR url MATCHES "Marlin.git") - message( - FATAL_ERROR - "Oh, your remote '${item}' appears to have its push URL set to a public repository! Let me say, that this is a bad, bad idea! You are \"one push\" away from mistakenly publishing private things. Please remove this remote or set its push url to some nonsense (see below).\n git -C \"${repo_dir}\" remote set-url --push ${item} DISABLED\n" - ) - endif() - - endforeach() -endfunction() - -check_git_repo_for_dangerous_remotes("${CMAKE_SOURCE_DIR}") -check_git_repo_for_dangerous_remotes("${CMAKE_SOURCE_DIR}/lib/Marlin") diff --git a/requirements.txt b/requirements.txt index 12e47fe378..171eee34f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,14 @@ -pip~=23.0 +aiohttp~=3.8 +click~=8.1.3 +easyocr~=1.7 ecdsa~=0.18 -polib~=1.2 -pyyaml~=6.0 littlefs-python==0.8 numpy~=1.26.4 pillow~=9.5 -qoi~=0.5.0 -click~=8.1.3 -pytest~=7.3.2 -pytest-asyncio~=0.21 -easyocr~=1.7 -aiohttp~=3.8 +pip~=23.0 +polib~=1.2 pre-commit +pytest-asyncio~=0.21 +pytest~=7.3.2 +pyyaml~=6.0 +qoi~=0.5.0 diff --git a/utils/build.py b/utils/build.py index ff7c64a50a..c1eb2f0df3 100755 --- a/utils/build.py +++ b/utils/build.py @@ -709,6 +709,11 @@ def main(): action='store_true', help='Do not build, configure the build only.' ) + parser.add_argument( + '--skip-bootstrap', + action='store_true', + help='Skip bootstrap, useful if dependencies are already installed.' + ) parser.add_argument( '--no-store-output', dest='store_output', @@ -789,8 +794,9 @@ def main(): CMakePresetsGenerator.generate(configurations) sys.exit(0) - # check all dependencis are installed - bootstrap.bootstrap() + if not args.skip_bootstrap: + # check all dependencis are installed + bootstrap.bootstrap() # build everything results: Dict[BuildConfiguration, BuildResult] = dict() diff --git a/utils/check-requirements.py b/utils/check-requirements.py new file mode 100755 index 0000000000..a1ab347481 --- /dev/null +++ b/utils/check-requirements.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import sys +import itertools + + +def get_lines(path): + with open(path, 'r') as file: + return file.readlines() + + +def main(): + try: + expected_lines = sorted( + itertools.chain(get_lines('utils/holly/build-requirements.txt'), + get_lines('utils/holly/heavy-requirements.txt'))) + actual_lines = get_lines('requirements.txt') + + if actual_lines == expected_lines: + return 0 + else: + with open('requirements.txt', 'w') as file: + file.writelines(expected_lines) + return 1 + + except Exception as ex: + print(ex) + return 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/utils/holly/Dockerfile b/utils/holly/Dockerfile index 0a23a19026..a1c48c9b8d 100644 --- a/utils/holly/Dockerfile +++ b/utils/holly/Dockerfile @@ -1,10 +1,9 @@ FROM ubuntu:22.04 RUN apt-get clean && \ apt-get update -qq -y && \ - apt-get install git curl python3 python3-pip python3-venv libncurses5 g++-multilib -y + apt-get install git python3 python3-pip python3-venv -y WORKDIR /work ADD utils/bootstrap.py utils/bootstrap.py ADD utils/debug/10_custom_config_template.cfg utils/debug/10_custom_config_template.cfg -ADD requirements.txt requirements.txt -ADD utils/debug utils/debug +ADD utils/holly/build-requirements.txt requirements.txt RUN python3 utils/bootstrap.py && (cd .dependencies && find . -type f -executable | xargs chmod +x) && rm -rf utils diff --git a/utils/holly/build-pr.jenkins b/utils/holly/build-pr.jenkins index cc6447b776..d2d7a99333 100644 --- a/utils/holly/build-pr.jenkins +++ b/utils/holly/build-pr.jenkins @@ -50,6 +50,11 @@ pipeline { stages { stage('Create Git Tag') { + when { + expression { + return env.GIT_URL == 'git@github.com:prusa3d/Prusa-Firmware-Buddy-Private.git'; + } + } agent any steps { script { @@ -94,10 +99,9 @@ pipeline { sh """ ln -fs /work/.dependencies ln -fs /work/.venv + . .venv/bin/activate export XDG_CACHE_HOME=\$PWD/.precommit - . .venv/bin/activate - python3 utils/bootstrap.py git config --unset-all core.hooksPath pre-commit install pre-commit run \ @@ -176,6 +180,7 @@ pipeline { export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" ln -fs /work/.dependencies ln -fs /work/.venv + . .venv/bin/activate rm -rf build python3 utils/build.py \ --preset ${config.preset} \ @@ -184,6 +189,7 @@ pipeline { --generate-bbf \ --generate-dfu \ --no-store-output \ + --skip-bootstrap \ --version-suffix=${version.suffix_full} \ --version-suffix-short=${version.suffix_short} \ -DCUSTOM_COMPILE_OPTIONS:STRING="-Werror" \ @@ -245,6 +251,11 @@ pipeline { } stage('Integration Tests') { + when { + expression { + return env.GIT_URL == 'git@github.com:prusa3d/Prusa-Firmware-Buddy-Private.git'; + } + } agent { dockerfile { label 'integrationtests' diff --git a/utils/holly/build-requirements.txt b/utils/holly/build-requirements.txt new file mode 100644 index 0000000000..95dfa40e35 --- /dev/null +++ b/utils/holly/build-requirements.txt @@ -0,0 +1,9 @@ +ecdsa~=0.18 +littlefs-python==0.8 +pillow~=9.5 +pip~=23.0 +polib~=1.2 +pre-commit +pytest~=7.3.2 +pyyaml~=6.0 +qoi~=0.5.0 diff --git a/utils/holly/heavy-requirements.txt b/utils/holly/heavy-requirements.txt new file mode 100644 index 0000000000..260143dc66 --- /dev/null +++ b/utils/holly/heavy-requirements.txt @@ -0,0 +1,5 @@ +aiohttp~=3.8 +click~=8.1.3 +easyocr~=1.7 +numpy~=1.26.4 +pytest-asyncio~=0.21