Skip to content

Commit

Permalink
Use recursive globs to include config files (#200)
Browse files Browse the repository at this point in the history
* Initial Implementation

* Updated Readme

* Added CI tests

* writing the right name for what you want to include actually helps
  • Loading branch information
Zeanon authored Apr 10, 2024
1 parent 2e67d37 commit c906c80
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ If I want my printer to light itself on fire, I should be able to make my printe

- [filament_switch|motion_sensor: runout distance, smart and runout gcode](https://github.com/DangerKlippers/danger-klipper/pull/158)

- [configfile: recursive globs](https://github.com/DangerKlippers/danger-klipper/pull/200) / ([klipper#6375](https://github.com/Klipper3d/klipper/pull/6375))

If you're feeling adventurous, take a peek at the extra features in the bleeding-edge branch [feature documentation](docs/Bleeding_Edge.md)
and [feature configuration reference](docs/Config_Reference_Bleeding_Edge.md):

Expand Down
2 changes: 1 addition & 1 deletion docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@ aliases_<name>:

Include file support. One may include additional config file from the
main printer config file. Wildcards may also be used (eg,
"configs/\*.cfg").
"configs/\*.cfg", or "configs/\*\*/\*.cfg" if using python version >=3.5).

```
[include my_other_config.cfg]
Expand Down
5 changes: 4 additions & 1 deletion klippy/configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ def _resolve_include(
dirname = os.path.dirname(source_filename)
include_spec = include_spec.strip()
include_glob = os.path.join(dirname, include_spec)
include_filenames = glob.glob(include_glob)
if sys.version_info >= (3, 5):
include_filenames = glob.glob(include_glob, recursive=True)
else:
include_filenames = glob.glob(include_glob)
if not include_filenames and not glob.has_magic(include_glob):
# Empty set is OK if wildcard but not for direct file reference
raise error("Include file '%s' does not exist" % (include_glob,))
Expand Down
1 change: 1 addition & 0 deletions test/klippy/recursive_globs.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[include **/recursive_globs.include]
4 changes: 4 additions & 0 deletions test/klippy/recursive_globs.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG recursive_globs.cfg
DICTIONARY atmega2560.dict

G28
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[include ./**/*.cfg]
71 changes: 71 additions & 0 deletions test/klippy/recursive_globs_include/recursive_globs_include.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[stepper_x]
step_pin: PF0
dir_pin: PF1
enable_pin: !PD7
microsteps: 16
rotation_distance: 40
endstop_pin: ^PE5
position_endstop: 0
position_max: 200
homing_speed: 50

[stepper_y]
step_pin: PF6
dir_pin: !PF7
enable_pin: !PF2
microsteps: 16
rotation_distance: 40
endstop_pin: ^PJ1
position_endstop: 0
position_max: 200
homing_speed: 50

[stepper_z]
step_pin: PL3
dir_pin: PL1
enable_pin: !PK0
microsteps: 16
rotation_distance: 8
endstop_pin: probe:z_virtual_endstop
position_max: 200

[extruder]
step_pin: PA4
dir_pin: PA6
enable_pin: !PA2
microsteps: 16
rotation_distance: 33.5
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PB4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK5
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250

[heater_bed]
heater_pin: PH5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK6
control: watermark
min_temp: 0
max_temp: 130

[probe]
pin: PH6
z_offset: 1.15
drop_first_result: true

[mcu]
serial: /dev/ttyACM0

[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

0 comments on commit c906c80

Please sign in to comment.