Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stefan6419846 opened this issue Oct 4, 2024 · 1 comment

Comments

@stefan6419846
Copy link

stefan6419846 commented Oct 4, 2024

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.

@stefan6419846 stefan6419846 changed the title Side effects when importing extractcode.libarchive2 as library Side effects on locale and timezone when importing extractcode.libarchive2 as library Oct 4, 2024
@pombredanne
Copy link
Member

Thanks. This is unfortunate as setting the UTC timezone was done to get a better time from archives across test runners at least. We should avoid this but I still may want that at least for tests? Outside of tests, this may be less critical

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants