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

Adding zip_safe flag to setuptools prevent "module references __file__" warnings #272

Merged
merged 1 commit into from
Dec 30, 2022

Conversation

phutelmyer
Copy link
Contributor

@phutelmyer phutelmyer commented Dec 30, 2022

Describe the change
Referenced in #249, the following warnings were thrown upon build:

docker-compose build

...

strelka.tests.__pycache__.test_scan_docx.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_gif.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_html.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_iso.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_jpeg.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_msi.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_pe.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_png_eof.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_vhd.cpython-310: module references __file__

...

These warning messages indicate that the package contains Python modules that reference the special variable __file__. The __file__ variable is a built-in variable that holds the name of the file that the currently executing code is located in.

When a Python module references the __file__ variable, setuptools will emit a warning message to inform you that the module may not work correctly when the package is installed as a zip file. This is because the file variable will not contain the correct value when the module is executed from within a zip file.
This warning can be silenced by adding zip_safe=True to setuptools.py

import setuptools

setuptools.setup(
    name='strelka',
    author='Target Brands, Inc.',
    description='strelka: container-based file analysis at scale',
    license='Apache 2.0',
    packages=setuptools.find_packages(),
    scripts=['bin/strelka-backend'],
    zip_safe=True
)

This flag has been added to the project's setuptools.py files, although is really only necessary for the Backend.

Describe testing procedures
Added flag and rebuilt without a cache.

Sample output
N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of and tested my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

@phutelmyer phutelmyer added the bug Something isn't working label Dec 30, 2022
@phutelmyer phutelmyer merged commit 5aa4d99 into master Dec 30, 2022
@phutelmyer phutelmyer deleted the test-warning-fix branch December 30, 2022 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant