Package: dwalk
dwalk: walks directories, merges dictionariesdwalkis a Python package and CLI tool for walking directories and merging dictionaries.Installationdwalkrequires Python 3.8 or later.pip3installdwalkCLI usagedwalk--filenamesFILENAME[FILENAME...][--directoryDIRECTORY][--include-meta]--directory VALUE: Directory to walk to. The files in this directory will take priority over the files in its parent. Optional, and uses the current working directory by default.--filenames LOWEST_PRECEDENCE ... HIGHEST_PRECEDENCE: Files to look for and merge in each walked directory. Files at the end of the list take precedence over files at the beginning.--include-meta: Flag to indicate whether or not to include metadata on each merged property.ExampleMerging via file precedenceSay you have two configuration files:example/foo.ymldescribes the default configuration, and:example/foo.user.ymldescribes a user's personal configuration.# foo.ymlprompts:accessibility:not-askednotifications:not-askedtheme:default# foo.user.ymlaccessibility:high-contrast:trueprompts:accessibility:user-enabledtheme:pinkTo merge these two configurationswith precedence given to the user's configuration:dwalk--directoryexample--filenamesfoo.ymlfoo.user.yml{"accessibility":{"high-contrast":true},"prompts":{"accessibility":"user-enabled","notifications":"not-asked"},"theme":"pink"}Merging via directory precedenceSay you have three configuration files:example/foo.ymldescribes the default configuration, and:example/foo.user.ymldescribes a user's personal configuration, and:example/game/foo.ymldescribes a sub-project's default configuration:# example/foo.ymlprompts:accessibility:not-askednotifications:not-askedtheme:default# example/foo.user.ymlaccessibility:high-contrast:trueprompts:accessibility:user-enabledtheme:pink# game/foo.ymltheme:sci-firequires:-gamepadTo merge these three configurationsin the context of the game directory:dwalk--directoryexample/game--filenamesfoo.ymlfoo.user.yml{"accessibility":{"high-contrast":true},"prompts":{"accessibility":"user-enabled","notifications":"not-asked"},"requires":["gamepad"],"theme":"sci-fi"}MetadataMetdata can be included in the result by adding the--include-metaflag.This will add__dwalk__keys that describe:Thesrcfile whenever a property is merged in.Themost_specific_srcthat properties were merged in from.For example:{"__dwalk__":{"__dwalk__":{"most_specific_src":"/Users/cariad/code/dwalk/example/foo.user.yml"},"accessibility":{"src":"/Users/cariad/code/dwalk/example/foo.user.yml"},"prompts":{"src":"/Users/cariad/code/dwalk/example/foo.yml"},"theme":{"src":"/Users/cariad/code/dwalk/example/foo.user.yml"}},"accessibility":{"high-contrast":true},"prompts":{"__dwalk__":{"accessibility":{"src":"/Users/cariad/code/dwalk/example/foo.user.yml"}},"accessibility":"user-enabled","notifications":"not-asked"},"theme":"pink"}Packagedwalkcan be imported and used in Python scripts:fromdwalkimportdwalkfromloggingimportbasicConfig,getLogger# Log level defaults to INFO; override if you want.# basicConfig()# getLogger("dwalk").setLevel("DEBUG")merged=dwalk(directory="../dwalk/testing/bottom",filenames=["dwalk.2.yml","dwalk.1.yml"],include_meta=False,)print(merged)# {'favourite_colour': 'purple', 'is_top_2': True, 'side_count': {'hexagon': 6,# 'pentagon': 5, 'square': 4, 'triangle': 3}, 'alphabet': {'d': 'delta', 'c':# 'charlie', 'b': 'bravo', 'a': 'alpha'}, 'is_top_1': True, 'is_bottom_2': True,# 'shopping_list': ['atari', 'bismuth', 'cookies'], 'is_bottom_1': True}Directory precedencedwalkalways starts in the current user's home directory, then walks down from the volume root to the specified directory (or the current working directory if one wasn't specified).Thanks!My name isCariad Ecclestonand I'm a freelance DevOps engineer. I appreciate you checking out my projects! I'm available for interesing gigs -- let's talk!