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

WIP: Add script to import languages from linguist #97

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ install:

script:
- coala --ci
- python tools/import_from_linguist.py
1 change: 1 addition & 0 deletions data/LanguageType/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language_type: data
1 change: 1 addition & 0 deletions data/LanguageType/markup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language_type: markup
1 change: 1 addition & 0 deletions data/LanguageType/programming.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language_type: programming
1 change: 1 addition & 0 deletions data/LanguageType/prose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language_type: prose
3 changes: 3 additions & 0 deletions models/Language.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
identifier: String
type: LanguageType
creation_date: Integer
# wikidata should be Qid only
wikidata: String
github_language_id: Integer
full_name: String
# versions is a comma separated list, as normalising it has no benefit
# given that two languages with the same version identifier are completely
Expand All @@ -13,6 +15,7 @@ versions: String
grammar_file: String
aliases: Alias[]
extensions: FileExtension[]
interpreters: Array
line_continuation: LineCont[]
delimiters: Delimiter[]
datatypes: DataType[]
Expand Down
1 change: 1 addition & 0 deletions models/LanguageType.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language_type: String
28 changes: 28 additions & 0 deletions tools/import_from_linguist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import requests
import yaml
import os

req = requests.get('https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml')

languages_yml = yaml.safe_load(req.text)

for language in languages_yml:
if language[0].upper()+language[1:].replace(' ', '')+'.yaml' not in os.listdir('data/Language'):
# This language doesn't have a data file yet
language_yml = languages_yml[language]
new_language = {
'identifier': language[0].upper()+language[1:].replace(' ', ''),
'github_language_id': language_yml['language_id']
}

if 'aliases' in language_yml:
new_language['aliases'] = language_yml['aliases']
if 'extensions' in language_yml:
new_language['extensions'] = language_yml['extensions']
if 'type' in language_yml:
new_language['type'] = language_yml['type']
if 'interpreters' in language_yml:
new_language['interpreters'] = language_yml['interpreters']

stream = open('data/Language/'+language[0].upper()+language[1:].replace(' ', '')+'.yaml', 'w')
yaml.dump(new_language, stream)