Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .djlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"profile": "jinja",
"ignore": "H005,H007,H013,H019,H020,H021,H023,H026,H030,H036,H043,H047,H050,J018,T002",
"max_blank_lines": 1,
"use_gitignore": true
}
5 changes: 0 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 90

# Python stays at 88 (black/isort default) until the linters move to 90 too;
# isort reads this value.
[*.py]
max_line_length = 88

[*.{yml,yaml,json,less,md}]
indent_size = 2

Expand Down
65 changes: 24 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:
TEST_DEPS: ""
TEST_PATH: ""
# "pre-commit" once the repo has a hook config, else "ruff" with RUFF_ARGS.
LINT: ruff
LINT: pre-commit
RUFF_ARGS: ""
# setup.py imports octoprint_setuptools, so those builds need OctoPrint installed.
BUILD_ARGS: ""
Expand All @@ -36,26 +36,6 @@ jobs:
with:
python-version: "3.13"

# Hooks with `language: system` need the node packages and ShellCheck 0.11.
- name: Set up Node.js
if: env.LINT == 'pre-commit' && hashFiles('package.json') != ''
uses: actions/setup-node@v7
with:
node-version: "22"

- name: Install node packages
if: env.LINT == 'pre-commit' && hashFiles('package.json') != ''
run: |
if [ -f package-lock.json ]; then npm ci --no-audit --no-fund
else npm install --no-audit --no-fund; fi

- name: Install ShellCheck
if: env.LINT == 'pre-commit' && hashFiles('.githooks/shellcheck-hook.sh') != ''
run: |
url=https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.x86_64.tar.xz
curl -fsSL "$url" | tar -xJ -C "$RUNNER_TEMP"
sudo install "$RUNNER_TEMP/shellcheck-v0.11.0/shellcheck" /usr/local/bin/shellcheck

- name: Cache pre-commit hook environments
if: env.LINT == 'pre-commit'
uses: actions/cache@v6
Expand All @@ -65,9 +45,6 @@ jobs:

- name: Run pre-commit
if: env.LINT == 'pre-commit'
# The translations hook needs a local venv; the Translations job covers it.
env:
SKIP: check-translations
run: |
python -m pip install pre-commit
pre-commit run --all-files --show-diff-on-failure
Expand All @@ -88,20 +65,20 @@ jobs:
matrix:
include:
# Every Python version each OctoPrint generation supports.
- { octoprint: "1.x", python: "3.9", runner: ubuntu-24.04 }
- { octoprint: "1.x", python: "3.10", runner: ubuntu-latest }
- { octoprint: "1.x", python: "3.11", runner: ubuntu-latest }
- { octoprint: "1.x", python: "3.12", runner: ubuntu-latest }
- { octoprint: "1.x", python: "3.13", runner: ubuntu-latest }
- { octoprint: "2.x", python: "3.9", runner: ubuntu-24.04 }
- { octoprint: "2.x", python: "3.10", runner: ubuntu-latest }
- { octoprint: "2.x", python: "3.11", runner: ubuntu-latest }
- { octoprint: "2.x", python: "3.12", runner: ubuntu-latest }
- { octoprint: "2.x", python: "3.13", runner: ubuntu-latest, coverage: true }
- { octoprint: "2.x", python: "3.14", runner: ubuntu-latest }
- { octoprint: "2.x", python: "3.15", runner: ubuntu-latest }
- {octoprint: "1.x", python: "3.9", runner: ubuntu-24.04}
- {octoprint: "1.x", python: "3.10", runner: ubuntu-latest}
- {octoprint: "1.x", python: "3.11", runner: ubuntu-latest}
- {octoprint: "1.x", python: "3.12", runner: ubuntu-latest}
- {octoprint: "1.x", python: "3.13", runner: ubuntu-latest}
- {octoprint: "2.x", python: "3.9", runner: ubuntu-24.04}
- {octoprint: "2.x", python: "3.10", runner: ubuntu-latest}
- {octoprint: "2.x", python: "3.11", runner: ubuntu-latest}
- {octoprint: "2.x", python: "3.12", runner: ubuntu-latest}
- {octoprint: "2.x", python: "3.13", runner: ubuntu-latest, coverage: true}
- {octoprint: "2.x", python: "3.14", runner: ubuntu-latest}
- {octoprint: "2.x", python: "3.15", runner: ubuntu-latest}
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_API_TOKEN }}
CODACY_API_TOKEN: ${{ secrets.CODACY_API_TOKEN }}
steps:
- uses: actions/checkout@v7

Expand Down Expand Up @@ -141,9 +118,15 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false

# Skipped until the repo has a CODACY_API_TOKEN secret.
# Needs the Codacy account API token as CODACY_API_TOKEN; skipped without it.
# Like Codecov, a failed upload must not turn a passing test run red.
- name: Upload coverage to Codacy
if: matrix.coverage && env.CODACY_PROJECT_TOKEN != ''
if: matrix.coverage && env.CODACY_API_TOKEN != ''
continue-on-error: true
env:
CODACY_ORGANIZATION_PROVIDER: gh
CODACY_USERNAME: ${{ github.repository_owner }}
CODACY_PROJECT_NAME: ${{ github.event.repository.name }}
run: bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage.xml

build:
Expand All @@ -153,8 +136,8 @@ jobs:
fail-fast: false
matrix:
include:
- { octoprint: "1.x", python: "3.9", runner: ubuntu-24.04, disabled: false }
- { octoprint: "2.x", python: "3.13", runner: ubuntu-latest, disabled: false }
- {octoprint: "1.x", python: "3.9", runner: ubuntu-24.04, disabled: false}
- {octoprint: "2.x", python: "3.13", runner: ubuntu-latest, disabled: false}
steps:
- uses: actions/checkout@v7

Expand Down
5 changes: 5 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Import order shared by all plugin repos; compatible with ruff format.
[settings]
profile = black
line_length = 90
extend_skip_glob = **/vendor/*,3rdPartySoftware/*,archive/*
48 changes: 48 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Same hooks in every plugin repo, following OctoPrint core's setup.
# Set up once with `pre-commit install`; CI runs them on every push.
exclude: (^|/)(translations|vendor)/|^(docs|scripts|archive|3rdPartySoftware)/|\.(css|svg|map|gcode)$|\.min\.js$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- id: check-json
- id: check-yaml
# mkdocs.yml uses custom tags; only the syntax is checked.
args: [--unsafe]
- id: check-toml
- id: check-merge-conflict
- repo: https://github.com/PyCQA/isort
rev: 9.0.2
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.17.6
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format
- repo: https://github.com/djlint/djlint
rev: v1.54.2
hooks:
- id: djlint-reformat-jinja
- id: djlint-jinja
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.10.1
hooks:
- id: prettier
files: \.(js|json|less|ya?ml)$
- repo: https://github.com/codespell-project/codespell
rev: v2.4.3
hooks:
- id: codespell
# Identifiers, config keys and product names, not typos.
args:
- --ignore-words-list
- commitish,offsetp,colorfull,basf,paht,sme,unparseable,pre-selected
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.11.0.1-1
hooks:
- id: shellcheck
12 changes: 12 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Same scope as the prettier hook in .pre-commit-config.yaml.
*.md
*.css
*.min.js
**/package.json
**/package-lock.json
**/translations/
**/vendor/
docs/
scripts/
archive/
3rdPartySoftware/
12 changes: 12 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Prettier settings shared by all plugin repos, taken from OctoPrint core.
printWidth: 90
tabWidth: 4
semi: true
trailingComma: "none"
singleQuote: false
quoteProps: consistent
bracketSpacing: false
overrides:
- files: ["*.yaml", "*.yml", "*.json", "*.less"]
options:
tabWidth: 2
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ git clone https://github.com/ajimaru/OctoPrint-AutoConnectPlus.git
cd OctoPrint-AutoConnectPlus
python -m venv .venv && source .venv/bin/activate
pip install "OctoPrint>=1.11" -e ".[dev]"
pre-commit install # lint and format hooks, the same ones CI runs

pytest # run the unit tests
ruff check . # lint
pytest # run the unit tests
```

The tests mock OctoPrint's printer and the connector framework, so they run against
Expand Down
51 changes: 18 additions & 33 deletions octoprint_autoconnectplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,7 @@ def do_auto_connect(self):
if attempted:
self._register_failure()
except Exception: # pylint: disable=broad-exception-caught
self._logger.error(
f"Exception in do_auto_connect {get_exception_string()}"
)
self._logger.error(f"Exception in do_auto_connect {get_exception_string()}")
self._register_failure()

def _connect_serial(self, profile: str) -> bool:
Expand All @@ -315,9 +313,7 @@ def _connect_serial(self, profile: str) -> bool:
self._logger.debug(f"Port {port} not present yet, waiting")
return False

self._logger.info(
f"Attempting to connect to {port} with profile {profile}"
)
self._logger.info(f"Attempting to connect to {port} with profile {profile}")
self._printer.connect(port=port, profile=profile)
return True

Expand Down Expand Up @@ -379,26 +375,21 @@ def _connect_connector(self, connector: str, profile: str) -> bool:
return False
except Exception: # pylint: disable=broad-exception-caught
self._logger.debug(
f"Precondition check for '{connector}' raised, "
f"attempting connect anyway"
f"Precondition check for '{connector}' raised, attempting connect anyway"
)

# Connector preconditions only resolve the hostname, so a literal IP
# passes even when the printer is off and connect() then floods the log
# with "No route to host". Probe the TCP port first and just wait if
# unreachable, keeping the retry quiet.
if not self._host_reachable(connector, parameters):
self._logger.debug(
f"Host for '{connector}' not reachable yet, waiting"
)
self._logger.debug(f"Host for '{connector}' not reachable yet, waiting")
return False

self._logger.info(
f"Attempting to connect via '{connector}' with profile {profile}"
)
self._printer.connect(
connector=connector, parameters=parameters, profile=profile
)
self._printer.connect(connector=connector, parameters=parameters, profile=profile)
return True

def _host_reachable(self, connector: str, parameters: dict) -> bool:
Expand All @@ -420,9 +411,7 @@ def _host_reachable(self, connector: str, parameters: dict) -> bool:
return True

try:
with socket.create_connection(
(host, port), timeout=REACHABILITY_TIMEOUT
):
with socket.create_connection((host, port), timeout=REACHABILITY_TIMEOUT):
return True
except OSError:
return False
Expand All @@ -442,9 +431,7 @@ def _portretry_plugins_enabled(self) -> list[str]:
return [
name
for identifier, name in plugin_names.items()
if plugin_manager.get_plugin_info(
identifier, require_enabled=True
)
if plugin_manager.get_plugin_info(identifier, require_enabled=True)
is not None
]
except Exception: # pylint: disable=broad-exception-caught
Expand All @@ -461,9 +448,13 @@ def _detected_connection(self) -> dict[str, Any]:

if self._is_serial_connector(connector):
target = self.serial_port or ""
warning = "" if target else (
"No serial port detected yet; set one in OctoPrint's "
"connection dialog or configure a forced port below."
warning = (
""
if target
else (
"No serial port detected yet; set one in OctoPrint's "
"connection dialog or configure a forced port below."
)
)
return {
"label": label,
Expand All @@ -483,9 +474,7 @@ def _detected_connection(self) -> dict[str, Any]:
"No preferred connection stored. Connect once via OctoPrint's "
"connection dialog so AutoConnectPlus knows what to reconnect."
)
elif ConnectedPrinter is not None and (
ConnectedPrinter.find(connector) is None
):
elif ConnectedPrinter is not None and (ConnectedPrinter.find(connector) is None):
warning = (
f"Connector '{connector}' is not installed. Install the "
"matching connector plugin."
Expand Down Expand Up @@ -589,12 +578,9 @@ def on_settings_save(self, data) -> dict[Any, Any]:
# Match the entry-point key so the runtime identifier is explicit (otherwise
# defaults to the package name).
__plugin_identifier__ = "autoconnectplus"
__plugin_author__ = (
"ajimaru, based on work from vehystrix and hprombex"
)
__plugin_author__ = "ajimaru, based on work from vehystrix and hprombex"
__plugin_description__ = (
"Automatically reconnects the printer over serial, Moonraker or Bambu "
"connectors"
"Automatically reconnects the printer over serial, Moonraker or Bambu connectors"
)
__plugin_url__ = "https://github.com/ajimaru/OctoPrint-AutoConnectPlus"
__plugin_license__ = "AGPL-3.0-or-later"
Expand All @@ -619,6 +605,5 @@ def __plugin_load__():
module_globals = globals()
module_globals["__plugin_implementation__"] = plugin
module_globals["__plugin_hooks__"] = {
"octoprint.plugin.softwareupdate.check_config":
plugin.get_update_information,
"octoprint.plugin.softwareupdate.check_config": plugin.get_update_information,
}
8 changes: 5 additions & 3 deletions octoprint_autoconnectplus/static/js/autoconnectplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ $(function () {

new PNotify({
title: "AutoConnectPlus error",
text: plugins.join(" and ") + " is also enabled. Disable " +
text:
plugins.join(" and ") +
" is also enabled. Disable " +
"one of the reconnect plugins to prevent competing " +
"reconnect attempts.",
type: "error",
hide: false,
hide: false
});
portRetryWarningShown = true;
}
Expand Down Expand Up @@ -69,6 +71,6 @@ $(function () {
OCTOPRINT_VIEWMODELS.push({
construct: AutoConnectPlusViewModel,
dependencies: ["settingsViewModel"],
elements: ["#settings_plugin_autoconnectplus"],
elements: ["#settings_plugin_autoconnectplus"]
});
});
Loading