Bug 87920 - SCons scripts identified as Matlab
Summary: SCons scripts identified as Matlab
Status: RESOLVED FIXED
Alias: None
Product: shared-mime-info
Classification: Unclassified
Component: freedesktop.org.xml (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Shared Mime Info group
QA Contact:
URL:
Whiteboard:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2014-12-31 18:32 UTC by Carnë Draug
Modified: 2015-01-28 11:26 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
adds new mimetype for scons (77.86 KB, patch)
2015-01-21 17:58 UTC, Carnë Draug
Details | Splinter Review

Description Carnë Draug 2014-12-31 18:32:07 UTC
SCons scripts (named SConscripts) and input files (name Sconstruct) are python scripts.  However, they are incorrectly identified as Matlab scripts when they start with '##' (which is required to define enconding in python scripts). Example:

  ## coding: utf-8
  import os
  
  env = Environment(ENV = os.environ)
  thesis = env.PDF(target = "thesis.pdf", source = "thesis.tex")

This simple file is identified as Matlab but it is incorrect Matlab from the very first line ('#' is not a valid comment character in Matlab).

Looking at the git logs, I found "a1f1b88f" which added the magic:

      <match type="string" value="##" offset="0"/>

The log message mentions this is to identify Octave scripts as Matlab (I'll arguee this is also incorrect since such file would never run on Matlab, there should be a separate mime for Octave).

I would suggest the following fixes:

* add a 'SConscript' and 'SConstruct' magic for filenames to be identified as Python

* add the Python magic coding comments as magic to identify Python. These are detailed on PEP 263 (https://www.python.org/dev/peps/pep-0263/) and pretty much are "coding=" or "coding:" in a comment on the first or second line of a file

* remove '##' as magic for Matlab (have it as a separate one for Octave)
Comment 1 Carnë Draug 2015-01-21 17:58:30 UTC
Created attachment 112613 [details] [review]
adds new mimetype for scons

As discussed on the xdg mailing list, I am adding a patch that creates a new mimetype for scons. It also adds 3 new test files.
Comment 2 Bastien Nocera 2015-01-28 11:26:00 UTC
commit 29c2eab964cfd8c45fd8a7f5d8407bbc94222095
Author: Carnë Draug <carandraug+dev@gmail.com>
Date:   Wed Jan 21 17:45:51 2015 +0000

    New mimetype for SCons scripts as subclass of x-python.
    
    Scons is a build-system whose recipes/build rules are python scripts.
    As such its files are also valid python scripts (why it is subclassing
    x-python). The configuration files are pretty much always named
    "SConstruct". In addition, "SConscript" files can also exist to extend
    an existing SConstruct file.  They can be named anything but by convention
    they are named SConscript or SConscript.build_name.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=87920


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.