Skip to content

Commit 2af99c0

Browse files
committed
Narrowed scope of programming-languages to actual programming ones
1 parent bb057ce commit 2af99c0

6 files changed

Lines changed: 604 additions & 922 deletions

File tree

programming-languages/docs/README.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
> ### _File extensions for programming languages._
1515
16-
It's just a [JSON file](https://github.com/adamlui/python-utils/blob/programming-languages-1.0.0/programming-languages/src/programming_languages/languages.json), so you can use it in any environment. Sourced from GitHub's [Linguist](https://github.com/github-linguist/linguist) project (defines all 700+ languages known to GitHub). Data is updated via script and released via new package version.
16+
It's just a [JSON file](https://github.com/adamlui/python-utils/blob/programming-languages-1.0.0/programming-languages/src/programming_languages/programming_languages.json), so you can use it in any environment. Sourced from GitHub's [Linguist](https://github.com/github-linguist/linguist) project (defines all 500+ programming languages known to GitHub). Data is updated via script and released via new package version.
1717

1818
## Installation
1919

@@ -36,14 +36,6 @@ _Note: Most type checkers will falsely warn_ `programming_languages` _is not sub
3636

3737
## Examples
3838

39-
List all extensions for a language:
40-
41-
```py
42-
js_exts = programming_languages['JavaScript']['extensions']
43-
44-
print(js_exts) # => ['._js', '.bones', '.cjs', '.es', ...]
45-
```
46-
4739
Get language from an extension:
4840

4941
```py
@@ -52,19 +44,22 @@ def get_lang(file_ext):
5244
if file_ext in data['extensions']:
5345
return lang
5446

55-
print(get_lang('.rs')) # => 'Rust'
47+
print(get_lang('.al')) # => 'AL'
5648
```
5749

58-
Filter by language type:
50+
Get language from a file path:
5951

6052
```py
61-
markup_langs = [
62-
lang for lang, data in programming_languages.items()
63-
if data['type'] == 'markup'
64-
]
53+
def get_lang_from_path(filepath):
54+
from pathlib import Path
55+
file_ext = Path(filepath).suffix
56+
for lang, data in programming_languages.items():
57+
if file_ext in data['extensions']:
58+
return lang
6559

66-
print(markup_langs) # => ['Antlers', 'API Blueprint', 'Astro', 'BibTeX', ...]
67-
print(f'{len(markup_langs)} markup languages') # -> '69 markup languages'
60+
print(get_lang_from_path('main.rs')) # => 'Rust'
61+
print(get_lang_from_path('script.kt')) # => 'Kotlin'
62+
print(get_lang_from_path('data.avsc')) # => None (use data-languages pkg)
6863
```
6964

7065
## MIT License
@@ -73,9 +68,9 @@ Copyright © 2026 [Adam Lui](https://github.com/adamlui).
7368

7469
## Related
7570

76-
🇨🇳 [non-latin-locales](https://github.com/adamlui/python-utils/tree/main/non-latin-locales/#readme) - ISO 639-1 (2-letter) codes for non-Latin locales.
77-
<br>📟 [is-unicode-supported](https://github.com/adamlui/python-utils/tree/main/is-unicode-supported/#readme) - Detect whether the terminal supports advanced Unicode.
78-
<br>🏷️ [project-markers](https://github.com/adamlui/python-utils/tree/main/project-markers/#readme) - Common project root markers.
71+
</> [markup-languages](https://github.com/adamlui/python-utils/tree/main/markup-languages/#readme) - File extensions for markup languages.
72+
<br>## [prose-languages](https://github.com/adamlui/python-utils/tree/main/prose-languages/#readme) - File extensions for prose languages.
73+
<br>{ } [data-languages](https://github.com/adamlui/python-utils/tree/main/data-languages/#readme) - File extensions for data languages.
7974

8075
#
8176

programming-languages/pyproject.toml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,36 @@ license-files = [
1919
]
2020
requires-python = ">=2.6,<4"
2121
keywords = [
22+
"bash",
23+
"c",
24+
"c#",
25+
"c++",
2226
"code-languages",
2327
"computer-languages",
28+
"dart",
2429
"extensions",
25-
"file-extensions",
2630
"file‑type-detection",
31+
"file-extensions",
2732
"filenames",
2833
"github",
34+
"go",
35+
"java",
36+
"javascript",
37+
"kotlin",
2938
"language-detection",
3039
"languages",
3140
"linguist",
41+
"php",
42+
"powershell",
3243
"programming-languages",
44+
"python",
45+
"ruby",
46+
"rust",
47+
"shell",
48+
"sql",
49+
"swift",
3350
"syntax-highlighting",
51+
"typescript",
3452
]
3553
classifiers = [
3654
"Development Status :: 5 - Production/Stable",
@@ -87,5 +105,5 @@ where = [
87105

88106
[tool.setuptools.package-data]
89107
programming_languages = [
90-
"languages.json",
108+
"programming_languages.json",
91109
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json, os, sys
22

3-
with open(os.path.join(os.path.dirname(__file__), 'languages.json')) as file:
3+
with open(os.path.join(os.path.dirname(__file__), 'programming_languages.json')) as file:
44
programming_languages = json.load(file)
55

66
sys.modules[__name__] = programming_languages

0 commit comments

Comments
 (0)