Skip to content

Commit 7d5eefa

Browse files
committed
Created programming-languages pkg
1 parent 62a9222 commit 7d5eefa

22 files changed

Lines changed: 1620 additions & 0 deletions

File tree

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ updates:
1414
- /is-unicode-supported
1515
- /latin-locales
1616
- /non-latin-locales
17+
- /programming-languages
1718
- /project-markers
1819
- /remove-json-keys
1920
- /translate-messages

docs/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@
5757
[API usage](https://github.com/adamlui/python-utils/tree/main/non-latin-locales/#usage) /
5858
[Discuss](https://github.com/adamlui/python-utils/discussions)
5959

60+
### <a href="https://github.com/adamlui/python-utils/tree/main/programming-languages/#readme"></> programming-languages</a>
61+
62+
> File extensions for programming languages.
63+
<br>[Install](https://github.com/adamlui/python-utils/tree/main/programming-languages/#installation) /
64+
[Readme](https://github.com/adamlui/python-utils/tree/main/programming-languages/#readme) /
65+
[API usage](https://github.com/adamlui/python-utils/tree/main/programming-languages/#usage) /
66+
[Discuss](https://github.com/adamlui/python-utils/discussions)
67+
6068
### <a href="https://github.com/adamlui/python-utils/tree/main/project-markers/#readme">🏷️ project-markers</a>
6169

6270
> Common project root markers.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 🏛️ MIT License
2+
3+
**Copyright © 2026 [Adam Lui](https://github.com/adamlui)**
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<a id="top"></a>
2+
3+
# > programming-languages
4+
5+
<a href="https://github.com/adamlui/python-utils/releases/tag/programming-languages-1.0.0">
6+
<img height=31 src="https://img.shields.io/badge/Latest_Build-1.0.0-32fcee.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
7+
<a href="https://github.com/adamlui/python-utils/blob/main/programming-languages/docs/LICENSE.md">
8+
<img height=31 src="https://img.shields.io/badge/License-MIT-f99b27.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
9+
<a href="https://www.codefactor.io/repository/github/adamlui/python-utils">
10+
<img height=31 src="https://img.shields.io/codefactor/grade/github/adamlui/python-utils?label=Code+Quality&logo=codefactor&logoColor=white&labelColor=464646&color=a0fc55&style=for-the-badge"></a>
11+
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_python-utils">
12+
<img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_python-utils%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=fafc74"></a>
13+
14+
> ### _File extensions for programming languages._
15+
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), the data is updated via script and released w/ each new version.
17+
18+
## Installation
19+
20+
```bash
21+
pip install programming-languages
22+
```
23+
24+
## Usage
25+
26+
```py
27+
import programming_languages
28+
29+
py_lang_data = programming_languages['Python']
30+
31+
print(py_lang_data['extensions']) # => ['.py', '.cgi', '.fcgi', ...]
32+
print(py_lang_data['type']) # => 'programming'
33+
```
34+
35+
_Note: Most type checkers will falsely warn_ `programming_languages` _is not subscriptable because they are incapable of analyzing runtime behavior (where the module is replaced w/ a dictionary for cleaner, direct access). You can safely suppress such warnings using_ `# type: ignore`.
36+
37+
## Examples
38+
39+
List all extensions for a language:
40+
41+
```py
42+
js_exts = programming_languages['JavaScript']['extensions']
43+
44+
print(js_exts) # => ['.js', '._js', '.bones', '.cjs', ...]
45+
```
46+
47+
Get language from an extension:
48+
49+
```py
50+
def get_lang(file_ext):
51+
for lang, data in programming_languages.items():
52+
if file_ext in data['extensions']:
53+
return lang
54+
55+
print(get_lang('.rs')) # => 'Rust'
56+
```
57+
58+
Filter by language type:
59+
60+
```py
61+
markup_langs = {
62+
lang for lang, data in programming_languages.items()
63+
if data['type'] == 'markup'
64+
}
65+
66+
print(markup_langs) # => ['HTML+ECR', 'PostCSS', 'Go Template', 'SCSS', ...]
67+
print(f'{len(markup_langs)} markup languages') # -> '69 markup languages'
68+
```
69+
70+
## MIT License
71+
72+
Copyright © 2026 [Adam Lui](https://github.com/adamlui).
73+
74+
## Related
75+
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.
79+
80+
#
81+
82+
<a href="#top">Back to top ↑</a>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 🛡️ Security Policy
2+
3+
If you find a vulnerability, please e-mail security@tidelift.com and a fix will be coordinated within 2 business days.

programming-languages/noxfile.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from pathlib import Path
2+
from types import SimpleNamespace as sn
3+
4+
import nox
5+
6+
pkg = sn(dir=Path(__file__).parent.name)
7+
pkg.name = pkg.dir.replace('-', '_')
8+
paths = sn(
9+
utils=sn(bump='utils/bump.py', clean='utils/clean.py', publish='utils/publish.sh', update='utils/update_langs.py'))
10+
11+
def session(func) : return nox.session(venv_backend='none', name=func.__name__.replace('_', '-'))(func)
12+
13+
# SESSIONS
14+
15+
@session
16+
def dev(session) : session.run('pip', 'install', '-e', '.')
17+
18+
@session
19+
def lint(session) : session.run('ruff', 'check', '.', *session.posargs)
20+
@session
21+
def lint_fix(session) : session.run('ruff', 'check', '.', '--fix', *session.posargs)
22+
23+
@session
24+
def update(session, *args) : session.run('py', paths.utils.update, *args)
25+
26+
@session
27+
def bump_patch(session, no_push=True):
28+
cmd = ['py', paths.utils.bump, '--patch']
29+
if no_push : cmd.append('--no-push')
30+
session.run(*cmd, *session.posargs)
31+
@session
32+
def bump_minor(session, no_push=True):
33+
cmd = ['py', paths.utils.bump, '--minor']
34+
if no_push : cmd.append('--no-push')
35+
session.run(*cmd, *session.posargs)
36+
@session
37+
def bump_feat(session, no_push=True):
38+
bump_minor(session, no_push)
39+
@session
40+
def bump_major(session, no_push=True):
41+
cmd = ['py', paths.utils.bump, '--major']
42+
if no_push : cmd.append('--no-push')
43+
session.run(*cmd, *session.posargs)
44+
45+
@session
46+
def build(session) : clean(session) ; session.run('py', '-m', 'build') ; print('Build complete!')
47+
@session
48+
def publish(session) : session.run('bash', paths.utils.publish, *session.posargs)
49+
50+
@session
51+
def deploy_patch(session) : bump_patch(session, no_push=False) ; build(session) ; publish(session)
52+
@session
53+
def deploy_minor(session) : bump_minor(session, no_push=False) ; build(session) ; publish(session)
54+
@session
55+
def deploy_feat(session) : deploy_minor(session)
56+
@session
57+
def deploy_major(session) : bump_major(session, no_push=False) ; build(session) ; publish(session)
58+
59+
@session
60+
def clean(session, *args) : session.run('py', paths.utils.clean, *args)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[build-system]
2+
requires = [
3+
"setuptools~=82.0.0",
4+
"wheel",
5+
]
6+
build-backend = "setuptools.build_meta"
7+
8+
[project]
9+
name = "programming-languages"
10+
version = "1.0.0"
11+
description = "File extensions for programming languages."
12+
authors = [
13+
{ name = "Adam Lui", email = "adam@kudoai.com" },
14+
]
15+
readme = "docs/README.md"
16+
license = "MIT"
17+
license-files = [
18+
"docs/LICENSE.md",
19+
]
20+
requires-python = ">=2.6,<4"
21+
keywords = [
22+
"code-languages",
23+
"computer-languages",
24+
"extensions",
25+
"file-extensions",
26+
"file‑type-detection",
27+
"filenames",
28+
"github",
29+
"language-detection",
30+
"languages",
31+
"linguist",
32+
"programming-languages",
33+
"syntax-highlighting",
34+
]
35+
classifiers = [
36+
"Development Status :: 5 - Production/Stable",
37+
"Intended Audience :: Developers",
38+
"Intended Audience :: Education",
39+
"Intended Audience :: Information Technology",
40+
"Intended Audience :: Science/Research",
41+
"Intended Audience :: System Administrators",
42+
"Natural Language :: English",
43+
"Operating System :: OS Independent",
44+
"Programming Language :: Python",
45+
"Programming Language :: Python :: 2",
46+
"Programming Language :: Python :: 2.6",
47+
"Programming Language :: Python :: 2.7",
48+
"Programming Language :: Python :: 3",
49+
"Programming Language :: Python :: 3.8",
50+
"Programming Language :: Python :: 3.9",
51+
"Programming Language :: Python :: 3.10",
52+
"Programming Language :: Python :: 3.11",
53+
"Programming Language :: Python :: 3.12",
54+
"Programming Language :: Python :: 3.13",
55+
"Programming Language :: Python :: 3.14",
56+
"Programming Language :: Python :: 3.15",
57+
"Topic :: Education",
58+
"Topic :: Scientific/Engineering",
59+
"Topic :: Scientific/Engineering :: Information Analysis",
60+
"Topic :: Software Development",
61+
"Topic :: Software Development :: Libraries",
62+
"Topic :: Software Development :: Libraries :: Python Modules",
63+
"Topic :: Text Processing :: Linguistic",
64+
"Topic :: Utilities",
65+
]
66+
67+
[project.urls]
68+
Changelog = "https://github.com/adamlui/python-utils/releases/tag/programming-languages-1.0.0"
69+
Documentation = "https://github.com/adamlui/python-utils/tree/main/programming-languages/docs"
70+
Funding = "https://github.com/sponsors/adamlui"
71+
Homepage = "https://github.com/adamlui/python-utils/tree/main/programming-languages/#readme"
72+
Issues = "https://github.com/adamlui/python-utils/issues"
73+
"PyPI Stats" = "https://pepy.tech/projects/programming-languages"
74+
Releases = "https://github.com/adamlui/python-utils/releases"
75+
Repository = "https://github.com/adamlui/python-utils"
76+
77+
[project.optional-dependencies]
78+
dev = [
79+
"nox>=2026.2.9",
80+
"tomli~=2.4.0",
81+
"tomli-w~=1.2.0",
82+
]
83+
84+
[tool.setuptools.packages.find]
85+
where = [
86+
"src",
87+
]
88+
89+
[tool.setuptools.package-data]
90+
programming_languages = [
91+
"languages.json",
92+
]

programming-languages/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[bdist_wheel]
2+
universal = 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import json, os, sys
2+
3+
with open(os.path.join(os.path.dirname(__file__), 'languages.json')) as file:
4+
programming_languages = json.load(file)
5+
6+
sys.modules[__name__] = programming_languages

0 commit comments

Comments
 (0)