Linguist: Python (3) code files with .py3 extensions are not detected or highlighted

Created on 10 Nov 2016  路  8Comments  路  Source: github/linguist

Problem: the repo contains several code files in both Python2 and Python3. To distinguish between them we use .py extension for py2 and .py3 extension for py3. But GitHub doesn't highlight syntax in .py3 files and doesn't count them as code in python language (or any language in fact). This should be fixed.

Most helpful comment

Hey there,

There aren't too many files on GitHub that use the .py3 extension, so I'm afraid its usage isn't widespread enough for it to be added as a recognised Python extension.

However, you can tell GitHub those files are Python by using your repository's .gitattributes file:

*.py3 linguist-language=Python

Syntax highlighting can also be set using Vim or Emacs modelines. =)

# vim: ft=python
# -*- python -*-

All 8 comments

Hey there,

There aren't too many files on GitHub that use the .py3 extension, so I'm afraid its usage isn't widespread enough for it to be added as a recognised Python extension.

However, you can tell GitHub those files are Python by using your repository's .gitattributes file:

*.py3 linguist-language=Python

Syntax highlighting can also be set using Vim or Emacs modelines. =)

# vim: ft=python
# -*- python -*-

@Alhadis unfortunately, it's not proper solution, at least for my case. These files shouldn't contain any extra comments (for the purpose they are used), and there probably will be quite a few of them in the future.
.gitattibutes solution would be OK, if it affected the highlighting, since it's the main thing that is lacking.

I've seen some PRs/discussions that involve some heuristics to determine the language in the file in this repo, but my problem doesn't require such hackery.
As demonstrated by the github search .py3 is used, although not that frequent, for the sole purpose of python code files. So there shouldn't be any conflict which may cause wrong detection. IIUC, all that's needed is too add it to known python language extensions list (which is already quite large and pervasive if I found the right place to look).

@Alhadis Do you have an estimate of the number of repositories using the .py3 extension?

Sorry, I meant to address this earlier today, but got distracted.

The 1895 py3 files on GitHub are distributed among 392 repositories by 366 users. On second thought, I'd say that's adequate enough distribution to warrant being included as an extension.

Search results are here, BTW.

@danilaml You can open a pull request by following the guidelines. There seem to be enough usage on github.com to warrant support of the extension. That being said, we'll still need a :+1: on the pull request from one GitHub's maintainers to confirm.

I was just wondering - how long does it usually take for changes to apply (i.e. when it'll start indexing .py3 files as python)?

It'll be visible in the next release of Linguist. =) New releases are cut every few weeks, so it might be a week or two before you see changes. I'm not sure exactly when the next release is due, however.

Thanks, good to know.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

d4nyll picture d4nyll  路  3Comments

GabLeRoux picture GabLeRoux  路  6Comments

henrywright picture henrywright  路  6Comments

RafaelPAndrade picture RafaelPAndrade  路  4Comments

BnSalahFahmi picture BnSalahFahmi  路  3Comments