Skip to content

Side effects on locale and timezone when importing extractcode.libarchive2 as library #65

Open
@stefan6419846

Description

@stefan6419846

Importing extractcode.libarchive2 has unexpected side effects on the caller, especially when used as a library inside a larger project.

In my specific case, the base application is running with the Europe/Berlin timezone, as this is my local time. After having executed some extraction code involving the aforementioned module, my timezone is set to UTC. This only became obvious because my logging showed that processing the archive finished nearly two hours before starting the process.

The reason is

def set_env_with_tz():
# NOTE: this is important to avoid timezone differences
os.environ['TZ'] = 'UTC'
set_env_with_tz()
# NOTE: this is important to avoid locale-specific errors on various OS
locale.setlocale(locale.LC_ALL, '')
In my opinion, libraries should not change such stuff globally without any warning.

Edit: It seems like these aspects are not covered by unit tests as well, which makes evaluating alternatives or removing these lines harder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions