Skip to content

Commit 5a64b0c

Browse files
Added Visual Studio Code tutorial, and updated README (#961)
* Added Visual Studio Code tutorial, and updated README * merged and reformatted * added missing line break * moved vscode setup instructions to docs root * added VS code instructions to leftnav below Overview section * moved docs/vscode/vscode_debugger.png -> docs/images/vscode_debugger.png
1 parent bb98a38 commit 5a64b0c

File tree

4 files changed

+151
-24
lines changed

4 files changed

+151
-24
lines changed

README.md

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ be located by python.
195195
Development of tensorflow-io on Linux is similiar to development on macOS. The required packages
196196
are gcc, g++, git, bazel, and python 3. Newer versions of gcc or python than default system installed
197197
versions might be required though.
198+
For instructions how to configure Visual Studio code to be able to build and debug TensorFlow I/O see
199+
https://github.com/tensorflow/io/blob/master/docs/vscode.md
198200

199201
##### Ubuntu 18.04/20.04
200202

@@ -309,7 +311,7 @@ TFIO_DATAPATH=bazel-bin python3 -m pip install .
309311
```
310312
with `TFIO_DATAPATH=bazel-bin` passed for the same readon.
311313

312-
Note installing with `-e` is different from the above. The
314+
Note installing with `-e` is different from the above. The
313315
```
314316
TFIO_DATAPATH=bazel-bin python3 -m pip install -e .
315317
```
@@ -363,24 +365,6 @@ $ bash -x -e tests/test_kafka/kafka_test.sh start kafka
363365
$ bash -x -e tests/test_kinesis/kinesis_test.sh start kinesis
364366
```
365367

366-
#### Running Python and Bazel Style Checks
367-
368-
Style checks for Python and Bazel can be run with the following commands
369-
(docker has to be available):
370-
371-
```sh
372-
$ bash -x -e .travis/lint.sh
373-
```
374-
375-
In case there are any Bazel style errors, the following command could be invoked
376-
to fix and Bazel style issues:
377-
378-
```sh
379-
$ docker run -i -t --rm -v $PWD:/v -w /v --net=host golang:1.12 bash -x -e -c 'go get github.com/bazelbuild/buildtools/buildifier && buildifier $(find . -type f \( -name WORKSPACE -or -name BUILD -or -name *.BUILD \))'
380-
```
381-
382-
After the command is run, any Bazel files with style issues will have been modified and corrected.
383-
384368
### R
385369

386370
We provide a reference Dockerfile [here](R-package/scripts/Dockerfile) for you
@@ -431,22 +415,28 @@ If the system have docker installed, then the following command
431415
will automatically build manylinux2010 compatible whl package:
432416

433417
```sh
434-
bash -x -e .travis/python.release.sh
418+
ls dist/*
419+
for f in dist/*.whl; do
420+
docker run -i --rm -v $PWD:/v -w /v --net=host quay.io/pypa/manylinux2010_x86_64 bash -x -e /v/tools/build/auditwheel repair --plat manylinux2010_x86_64 $f
421+
done
422+
sudo chown -R $(id -nu):$(id -ng) .
423+
ls wheelhouse/*
435424
```
436425

437426
It takes some time to build, but once complete, there will be python
438-
`2.7`, `3.5`, `3.6`, `3.7` compatible whl packages available in `wheelhouse`
427+
`3.5`, `3.6`, `3.7` compatible whl packages available in `wheelhouse`
439428
directory.
440429

441430
On macOS, the same command could be used though the script expect `python` in shell
442431
and will only generate a whl package that matches the version of `python` in shell. If
443432
you want to build a whl package for a specific python then you have to alias this version
444-
of python to `python` in shell.
433+
of python to `python` in shell. See [.github/workflows/build.yml](.github/workflows/build.yml)
434+
Auditwheel step for instructions how to do that.
445435

446436
Note the above command is also the command we use when releasing packages for Linux and macOS.
447437

448-
TensorFlow I/O uses both Travis CI and Google CI (Kokoro) for continuous integration.
449-
Travis CI is used for macOS build and test. Kokoro is used for Linux build and test.
438+
TensorFlow I/O uses both GitHub Workflows and Google CI (Kokoro) for continuous integration.
439+
GitHub Workflows is used for macOS build and test. Kokoro is used for Linux build and test.
450440
Again, because of the manylinux2010 requirement, on Linux whl packages are always
451441
built with Ubuntu 16.04 + Developer Toolset 7. Tests are done on a variatiy of systems
452442
with different python version to ensure a good coverage:

docs/_toc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@
1616
toc:
1717
- title: Overview
1818
path: /io/overview
19+
- title: "Configuring Visual Studio Code"
20+
path: /io/vscode

docs/images/vscode_debugger.png

181 KB
Loading

docs/vscode.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Configuring Visual Studio Code
2+
3+
Visual Studio is a free code editor, which runs on the macOS, Linux, and Windows operating systems.
4+
5+
It has nice tooling for Python and C++ development, visual debugger, git integration, and many more
6+
useful features. It is a great editor to use for TensorFlow IO development, but it takes some effort
7+
to configure it properly. VSCode configuration is very flexible, it allows compiling project using
8+
bazel, and running code under Python and C++ debuggers. This manual is for Linux, other OSes
9+
might have specifics, but approach should be similar.
10+
11+
12+
## Extensions
13+
To install an extension click the extensions view icon (Extensions) on the Sidebar, or use the shortcut Ctrl+Shift+X.
14+
Then searh for keyword below.
15+
16+
- [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) - Official C++ extension from Microsoft
17+
- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) - Official Python extension from Microsoft
18+
- [Python Extension Pack](https://marketplace.visualstudio.com/items?itemName=donjayamanne.python-extension-pack) - another useful extension for Python development
19+
20+
## Compiling projects
21+
TensorFlow IO is compiled using bazel build command:
22+
23+
```sh
24+
bazel build -s --verbose_failures --compilation_mode dbg //tensorflow_io/...
25+
```
26+
27+
See project [README](https://github.com/tensorflow/io#ubuntu-18042004) file for details on how to setup development environment in Ubuntu.
28+
--compilation_mode dbg flag here indicates that produced binary should have debug symbols.
29+
Once you can compile project from command line, you can also configure VSCode to be able to invoke same command.
30+
31+
Open View->Command Pallete (Ctrl+Shift+P) and start typing: "Tasks: Configure Build Task".
32+
If you are doing this for the first time, editor is going to suggest creating tasks.json file.
33+
Once you have it, paste following json:
34+
35+
```jsonc
36+
{
37+
"version": "2.0.0",
38+
"tasks": [
39+
{
40+
"label": "Build TF.IO (Debug)",
41+
"type": "shell",
42+
"command": "bazel build -s --verbose_failures --compilation_mode dbg //tensorflow_io/...",
43+
"group": {
44+
"kind": "build",
45+
"isDefault": true
46+
},
47+
"problemMatcher": []
48+
}
49+
]
50+
}
51+
```
52+
53+
Now, you can press "Ctrl+Shift+B", and VSCode is going to use the command above to build the project.
54+
It uses its own terminal window, where all links are clickable. So when compilation error occurs, you can
55+
just click the link, and editor will open corresponding file and navigate to the line.
56+
57+
## Debugging projects
58+
Debugging Python code is trivial, follow official documentation to figure out how to configure VSCode to enable that: https://code.visualstudio.com/docs/python/debugging
59+
Debugging C++ code requires GDB to be installed on your system.
60+
If you have a bq_sample_read.py python script that is using tensorflow-io library that is normally
61+
executed like:
62+
```sh
63+
python3 bq_sample_read.py --gcp_project_id=...
64+
```
65+
66+
In order to execute it under GDB, run following:
67+
```sh
68+
gdb -ex r --args python3 bq_sample_read.py --gcp_project_id=...
69+
```
70+
71+
If application crashes in C++ code, you can run ```backtrace``` in GDB console to get stacktrace.
72+
73+
VSCode also has GDB debugger support, it allows adding breakpoints, see values of variables and step through the code.
74+
To add debug configuration press the Debug View icon (Debug) on the Sidebar, or use the shortcut Ctrl+Shift+D. Here press the little down arrow next to the play button and select "Add Configuration...".
75+
It will create launch.json file, add following config here:
76+
77+
```jsonc
78+
{
79+
"name": "(gdb) Launch",
80+
"type": "cppdbg",
81+
"request": "launch",
82+
"program": "/usr/bin/python3",
83+
"args": ["bq_sample_read.py", "--gcp_project_id=..."],
84+
"stopAtEntry": false,
85+
"cwd": "${workspaceFolder}",
86+
"environment": [
87+
{
88+
/* path to your bazel-bin folder */
89+
"name": "TFIO_DATAPATH",
90+
"value": "/usr/local/google/home/io/bazel-bin"
91+
},
92+
{
93+
/* other env variables to use */
94+
"name": "GOOGLE_APPLICATION_CREDENTIALS",
95+
"value": "..."
96+
}
97+
],
98+
"externalConsole": false,
99+
"MIMode": "gdb",
100+
"setupCommands": [
101+
{
102+
"description": "Enable pretty-printing for gdb",
103+
"text": "-enable-pretty-printing",
104+
"ignoreFailures": true
105+
}
106+
]
107+
}
108+
```
109+
110+
If everything is configured correctly, you should be able to do Run -> Start Debugging (F5) or Run -> Run Without Debugging (Ctrl + F5). This will run your code under debugger:
111+
112+
![VSCode debugger](./images/vscode_debugger.png)
113+
114+
One other thing worth doing to simplify debugging experience is configuting GDB to skip standard C++ libraries, so you don't step into code you don't care about. In order to do this, create ```~/.gdbinit``` file with following content:
115+
```
116+
skip -gfi /usr/include/c++/*/*/*
117+
skip -gfi /usr/include/c++/*/*
118+
skip -gfi /usr/include/c++/*
119+
```
120+
121+
## Formatting files
122+
You can always reformat C++ or Python file by Right Click -> Format Document (Ctrl + Shift + I), but VSCode uses different style conention. Luckily it is easy to change.
123+
124+
For Python formatting, see https://donjayamanne.github.io/pythonVSCodeDocs/docs/formatting/
125+
126+
To configure C++ formatter, do following:
127+
128+
- Go Preferences -> Settings
129+
- Search C_Cpp.clang_format_fallbackStyle
130+
- Modify the file:setting.json directly
131+
- Add following
132+
133+
```
134+
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google}"
135+
```

0 commit comments

Comments
 (0)