Skip to content

Commit 2d5eb25

Browse files
committed
Add in ability to link to python config files
1 parent 08b13bf commit 2d5eb25

3 files changed

Lines changed: 35 additions & 13 deletions

File tree

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
#github-linkify-cmssw
22

3-
This Chrome extension turns `#include X` in C/C++ files (and in the future `import X`/`from X import Y` in python configs) into hyperlinks when viewing CMSSW files on Github.com, so you can get to the includes easily. (I don't know why this hasn't been done already.)
3+
This Chrome extension turns `#include X` in C/C++ files, and `import X`/`from X import Y`/`process.load(XXX.YYY.ZZZ_cff)` in python config files, into hyperlinks when viewing CMSSW files on Github.com, so you can get to the includes easily. (I don't know why this hasn't been done already.)
44

55
## Instructions
66

77
1) Download the latest release:
88

99
https://github.com/raggleton/github-linkify-cmssw/releases/latest
1010

11-
2) Then install me:
11+
2) Go to [chrome://extensions](chrome://extensions)
1212

13-
- Go to [chrome://extensions](chrome://extensions)
14-
- Drag and drop the `github-linkify-cmssw.crx` package onto the window. Lcick OK when it asks permission to access github.com. This should install it.
13+
3) Drag and drop the `github-linkify-cmssw.crx` package onto the window. Click OK when it asks permission to access github.com. This should install it.
1514

1615
## TODO
17-
- [ ] Do for Python `import`/`from X import Y` statements
18-
- [ ] ignore STL/boost libraries (like `<iostream>`)
1916
- [ ] keep the colour of the links to their original colour
2017

2118
Maybe I'll do a Firefox equivalent some day. If I ever get this one done.

contentscript.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ var cpp_pattern = /#include/;
1616
var cpp_header_pattern = /[<\"].*[>\"]/; // does "myheader.h" or <myheader.h>
1717

1818
// pattern to do python matching
19-
var py_pattern1 = /import/;
20-
var py_pattern2 = /from\s.*\simport\s.*/; // might not need this one
21-
var py_pattern3 = /import.*as.*/;
19+
var py_pattern1 = /from\s.*\simport\s.*/;
20+
var py_pattern2 = /import.*as.*/;
21+
var py_pattern3 = /import/;
2222
var py_pattern4 = /process.load(.*)/;
2323

2424
// loop through all rows <tr>
@@ -48,9 +48,34 @@ for (var i = 0; i < rows.length; i++) {
4848
// }
4949
// }
5050
}
51-
// test for python
52-
else if (py_pattern1.test(line) || py_pattern3.test(line) || py_pattern4.test(line)) {
51+
// tests for python imports/fragments
52+
var config = "";
53+
if (py_pattern1.test(line)) {
54+
config = line.replace(/from\s/,"");
55+
config = config.replace(/\simport.*/,"");
56+
} else if (py_pattern2.test(line)) {
57+
config = line.replace(/import\s/,"");
58+
config = config.replace(/\sas\s.*/,"");
59+
} else if (py_pattern3.test(line)) {
60+
config = line.replace(/import\s/,"");
61+
} else if (py_pattern4.test(line)) {
62+
config = line.replace("process.load(","");
63+
config = config.replace(")","");
64+
}
65+
66+
// if we have a valid python config, turn it into a path
67+
// ensure it has a / in it so it isn't a 3rd party library
68+
if (config != "" && (/\./.test(config))) {
69+
config = config.replace(/['"]/g,"");
70+
var path = config.replace(/\./g,"/");
71+
var parts = path.split("/");
72+
path = path.replace(parts[parts.length-1],"python/"+parts[parts.length-1]+".py")
73+
var link = rootURL.concat(path)
5374

75+
// let's replace the text with a link
76+
// TODO keep same styling as before
77+
var cell_html = cell.innerHTML;
78+
cell.innerHTML = cell_html.replace(config, "<a href=\""+link+"\">"+config+"</a>");
5479
}
5580
}
5681
}

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Github linkify for CMSSW",
3-
"description": "Turns #include statments into links when browing CMSSW on Github.",
4-
"version": "0.1",
3+
"description": "Turns #include statments in C++ files, and import X/from X import Y/process.load(XXX.YYY.ZZZ_cff) in python config files, into links when browing CMSSW on Github.",
4+
"version": "0.2.0",
55
"content_scripts": [
66
{
77
"matches": [

0 commit comments

Comments
 (0)