Skip to content

Commit 24c2b66

Browse files
authored
Introduce pip requirements file highlighting
1 parent 75f66aa commit 24c2b66

File tree

4 files changed

+144
-1
lines changed

4 files changed

+144
-1
lines changed

languages/pip-requirements.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"comments": {
3+
"lineComment": "#"
4+
}
5+
}

package.json

+25-1
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,31 @@
14821482
"description": "Code executed when the kernel starts. Such as the default of '%matplotlib inline'. Individual lines can be placed in separate items of the array."
14831483
}
14841484
}
1485-
}
1485+
},
1486+
"languages": [
1487+
{
1488+
"id": "pip-requirements",
1489+
"aliases": [
1490+
"pip requirements",
1491+
"requirements.txt"
1492+
],
1493+
"filenames": [
1494+
"requirements.txt"
1495+
],
1496+
"filenamePatterns": [
1497+
"*-requirements.txt",
1498+
"requirements-*.txt"
1499+
],
1500+
"configuration": "./languages/pip-requirements.json"
1501+
}
1502+
],
1503+
"grammars": [
1504+
{
1505+
"language": "pip-requirements",
1506+
"scopeName": "source.pip-requirements",
1507+
"path": "./syntaxes/pip-requirements.tmLanguage.json"
1508+
}
1509+
]
14861510
},
14871511
"scripts": {
14881512
"vscode:prepublish": "tsc -p ./ && webpack",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# https://www.python.org/dev/peps/pep-0508/#names
2+
This-name_has.everything42 # End-of-line comment.
3+
4+
# https://www.python.org/dev/peps/pep-0508/#extras
5+
project[extras]
6+
7+
# https://www.python.org/dev/peps/pep-0508/#versions
8+
# https://www.python.org/dev/peps/pep-0440/
9+
project > 2.0.0
10+
project~=1.0.0
11+
project>1.0.0,<2.0.0
12+
project==1.0.0.dev1
13+
14+
# https://www.python.org/dev/peps/pep-0508/#environment-markers
15+
project;python_version>'3.0'
16+
project~=2.0.0;os_name=="linux"
17+
18+
# https://pip.readthedocs.io/en/stable/reference/pip_install/#requirements-file-format
19+
# Continuation line.
20+
project \
21+
>1.0.0
22+
23+
# Options
24+
## Stand-alone w/o argument.
25+
--no-links
26+
## Stand-alone w/ argument.
27+
-c constraints.txt
28+
-e git://git.myproject.org/MyProject#egg=MyProject
29+
## Part of requirement.
30+
FooProject >= 1.2 --global-option="--no-user-cfg"
31+
32+
# File path.
33+
./some/file
34+
some/file
35+
36+
# URL.
37+
https://some-site.ca/project.whl
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"name": "pip requirements",
4+
"scopeName": "source.pip-requirements",
5+
"patterns": [
6+
{
7+
"explanation": "Line continuation",
8+
"match": "\\s*\\\\s*$",
9+
"name": "constant.character.escape"
10+
},
11+
{
12+
"match": "#.*",
13+
"name": "comment.line.number-sign"
14+
},
15+
{
16+
"begin": "'",
17+
"end": "'",
18+
"name": "string.quoted.single"
19+
},
20+
{
21+
"begin": "\"",
22+
"end": "\"",
23+
"name": "string.quoted.double"
24+
},
25+
{
26+
"match": "/?(\\S+/)+\\S*",
27+
"name": "string.path"
28+
},
29+
{
30+
"explanation": "project name",
31+
"match": "^\\s*([A-Za-z0-9][A-Za-z0-9._-]*[A-Za-z0-9]|[A-Za-z0-9])",
32+
"captures": {
33+
"1": {
34+
"name": "entity.name.class"
35+
}
36+
}
37+
},
38+
{
39+
"explanation": "extras",
40+
"match": "\\[([^\\]]+)\\]",
41+
"captures": {
42+
"1": {
43+
"name": "entity.name.tag"
44+
}
45+
}
46+
},
47+
{
48+
"explanation": "version specification",
49+
"match": "(<|<=|!=|==|>=|>|~=|===)\\s*([\\w.*+!-]+)",
50+
"captures": {
51+
"1": {
52+
"name": "keyword.operator.comparison"
53+
},
54+
"2": {
55+
"name": "constant.numeric"
56+
}
57+
}
58+
},
59+
{
60+
"explanation": "environment markers",
61+
"match": ";\\s*(python_version|python_full_version|os_name|sys_platform|platform_release|platform_system|platform_version|platform_machine|platform_python_implementation|implementation_name|implementation_version|extra)\\s*(<|<=|!=|==|>=|>|~=|===)",
62+
"captures":{
63+
"1": {
64+
"name": "entity.name.selector"
65+
},
66+
"2": {
67+
"name": "keyword.operator.comparison"
68+
}
69+
}
70+
},
71+
{
72+
"explanation": "command-line options (e.g. `--no-links` or `-c`)",
73+
"match": "-[^\\s=]+",
74+
"name": "entity.other.attribute-name"
75+
}
76+
]
77+
}

0 commit comments

Comments
 (0)