How would you compare two version numbers when they are provided as strings? Implement a function that returns -1 if the first version is smaller, 1 if it is larger, and 0 if they are equal. Versions contain one or more nonnegative integer components separated by periods; leading zeros do not affect numeric value, and missing trailing components count as zero. For example, 1.01 equals 1.001, while 1.0.1 is greater than 1.
def compare_version(version1, version2):