simfile.tidy
Submodules
Classes
A predefined set of behaviors for use with |
|
Normalize all whitespace in the file. |
|
Normalize all line endings in the file. |
|
Add or remove comments from various parts of the simfile. |
|
Fill in any missing properties in the simfile with a default value. |
|
Remove any unknown properties (a destructive operation). |
|
Sort the properties in the simfile. |
Functions
|
Tidy up a simfile for future serialization, mutating it in-memory. |
Package Contents
- class simfile.tidy.Preset(*args, **kwds)
Bases:
enum.EnumA predefined set of behaviors for use with
tidy().- NO_OP
Leave all optional behaviors off by default.
This is equivalent to not specifying a preset, except it allows you to leave all optional behaviors
False.
- SM5
Emulate the StepMania 5 editor’s output (nondestructively).
- SM5_DESTRUCTIVE
Emulate the StepMania 5 editor’s output (including removing unknown properties).
- RECOMMENDED
Same as SM5, but keep the preamble & add or update the library version.
- behaviors() DefaultBehaviors
- class simfile.tidy.Whitespace(*args, **kwds)
Bases:
enum.EnumNormalize all whitespace in the file.
- SM5
Normalize whitespace to match StepMania 5’s output:
Properties are separated by a newline.
Each chart is prefixed by a blank line.
Each SM chart property (before note data) is prefixed by 5 spaces.
Currently, this option removes comments inside of SM charts if their whitespace is adjusted. Combine with
ChangeCommentsto regenerate measure comments if desired.
- run(sim: simfile.types.Simfile) bool
- class simfile.tidy.LineEndings(*args, **kwds)
Bases:
enum.EnumNormalize all line endings in the file.
- LF
Normalize all line endings to ‘n’.
- CRLF
Normalize all line endings to ‘rn’.
- HEURISTIC
Use the heuristic-determined line ending.
This typically matches the first line ending seen in the file.
- run(sim: simfile.types.Simfile) bool
- class simfile.tidy.ChangeComments(*args, **kwds)
Bases:
enum.FlagAdd or remove comments from various parts of the simfile.
- REMOVE_PREAMBLE
Remove any preamble (comment at the start of the file).
- REMOVE_CHART_PREAMBLE
Remove any chart preamble (comment before the first property signaling a chart, i.e.
NOTESfor SM andNOTEDATAfor SSC).
- REMOVE_CHART_INNER
Remove any comments inside a chart, such as (but not limited to) measure indicators.
- REMOVE_OTHER
Remove any other comments that don’t match the above definitions.
- REMOVE_ALL
Remove all comments.
This is equivalent to combining all of the above flags using the bitwise
|operator.
- ADD_LIBRARY_VERSION_PREAMBLE
Create a comment at the start of the file with the following string:
// Generated by simfile {VERSION} for Python
{VERSION}is replaced with the library’s version specifier. If such a comment already exists, it will be updated with the library’s current version.
- ADD_CHART_PREAMBLE
Create a comment before each chart with the following string:
//---------------{STEPSTYPE} - {DESCRIPTION}----------------
{STEPSTYPE}is replaced withstepstypeand{DESCRIPTION}is replaced withdescription. If such a comment already exists, it will be updated to reflect the chart’s current properties.
- ADD_CHART_MEASURES
Create comments before each measure to indicate the measure number:
#NOTES: // measure 0 0000 0000 0000 0000 , // measure 1 (etc.)
- ADD_ALL
Create all available types of supported comments.
This is equivalent to combining all of the above flags using the bitwise
|operator.
- run(sim: simfile.types.Simfile) bool
- class simfile.tidy.CreateMissingProperties(*args, **kwds)
Bases:
enum.EnumFill in any missing properties in the simfile with a default value.
- SM5
Create the same default properties that the StepMania 5 editor creates, if they don’t already exist.
Most properties’ default values are an empty string, but some have a specific non-empty default value, such as
OFFSETandBPMS.
- run(sim: simfile.types.Simfile) bool
- class simfile.tidy.DestructivelyRemoveProperties(*args, **kwds)
Bases:
enum.EnumRemove any unknown properties (a destructive operation).
- SM5
Remove all properties that are unknown to the StepMania 5 editor.
- run(sim: simfile.types.Simfile) bool
- class simfile.tidy.SortProperties(*args, **kwds)
Bases:
enum.EnumSort the properties in the simfile.
- SM5
Sort known properties to match the StepMania 5 editor’s output.
Unknown properties, if not removed, are sorted alphabetically after known properties.
- run(sim: simfile.types.Simfile) bool
- simfile.tidy.tidy(sim: simfile.types.Simfile, preset: behaviors.Preset | None = None, *, whitespace: behaviors.Whitespace | Literal[False] | None = None, line_endings: behaviors.LineEndings | Literal[False] | None = None, change_comments: behaviors.ChangeComments | Literal[False] | None = None, create_missing_properties: behaviors.CreateMissingProperties | Literal[False] | None = None, destructively_remove_properties: behaviors.DestructivelyRemoveProperties | Literal[False] | None = None, sort_properties: behaviors.SortProperties | Literal[False] | None = None)
Tidy up a simfile for future serialization, mutating it in-memory.
This function has many optional parameters that toggle various tidying behaviors. The simplest way to call it is to pass a preset as the second argument:
import tidy, Preset from simfile.tidy tidy(sim, Preset.RECOMMENDED) # or Preset.SM5
Without a preset, all behaviors default to off. If you don’t specify a preset, you must set at least one behavior to a non-empty value, or specify the
NO_OPpreset to allow no behaviors.Each optional behavior has an associated enum. Some behaviors’ enums are flags that can be combined using bitwise operators, for example:
import tidy, ChangeComments from simfile.tidy tidy( sim, change_comments=ChangeComments.REMOVE_PREAMBLE | ChangeComments.REMOVE_CHART_PREAMBLE, )
Returns True only if changes were made to the simfile. Raises ValueError if no preset or behaviors are specified.