Should punishment fit the crime or the criminal?

Should judges be required to take into account extra-legal factors such as race, socioeconomic status, lifestyle exposure to violence and drugs, and if allowed should this promote leniency on an offender’s sentence if it can be proven hat these factors have contributed to their creminality?