[File] Python misdetection with env

Steve Grubb sgrubb at redhat.com
Wed Jun 3 22:43:18 UTC 2020


Hello,

There is a common idiom in python programming with python is invoked via the
env command. I run across some files that are being misdetected as text/plain
when they are python files.

$ file --mime-type /usr/share/doc/gnome-python2-gnomevfs/async-xfer.py
/usr/share/doc/gnome-python2-gnomevfs/async-xfer.py: text/plain

The file starts like this:

#! /usr/bin/env python
import gnomevfs
import gtk
import termios

Looking in magic/Magdir/python, I see this line:

0       search/10       #!\ /usr/bin/env\ python        Python script text executable
!:strength + 15
!:mime text/x-python

Should that really be a '10' ? If I change it to 1, it works fine. And several
other searches nearby add a 'w' to it. Which got me to wondering something.
If I put 3 spaces between #!  and /usr/bin/env  and python in the file, then neither W
or w will cause it to match. Is this expected?

If, however I turn this into a regex, then I can match no matter how many
spaces there are.

0       regex       \^#![[:space:]]*/usr/bin/env[[:space:]]*python        Python script text executable
!:strength + 15
!:mime text/x-python

Best Regards,
-Steve




More information about the File mailing list