Instead of copying the whole `css = open...` line, you could do

    path = os.path.dirname(__file__) if css_directory is None else os.getcwd()
    css = open(os.path.join(path, css_directory, fname)).readlines()