Debian Codegraph @

docs/quick_start/0.-try.md

raw
1 # Try isort from your browser!
2
3 Use our live isort editor to see how isort can help improve the formatting of your Python imports.
4
5 !!! important - "Safe to use. No code is transmitted."
6 The below live isort tester doesn't transmit any of the code you paste to our server or anyone else's. Instead, this page runs a complete Python3 installation with isort installed entirely within your browser. To accomplish this, it utilizes the [pyodide](https://github.com/iodide-project/pyodide) project.
7
8 <head>
9 <script
10 src="https://cdn.jsdelivr.net/pyodide/v0.29.3/full/pyodide.js"
11 integrity="sha256-cY1A8cAV3SXsckzI/E4jJdakWpKuIlEh/2lT8iShb3I="
12 type="text/javascript"
13 crossorigin="anonymous"
14 >
15 </script>
16 <script
17 src="https://cdn.jsdelivr.net/npm/[email protected]/src-min-noconflict/ace.min.js"
18 >
19 </script>
20 <style>
21 .editor {
22 height: 400px;
23 width: 49.7%;
24 display: inline-block;
25 }
26 .configurator {
27 height: 200px;
28 width: 100%;
29 clear: both;
30 float: left;
31 }
32 #liveTester {
33 background: black;
34 color: white;
35 }
36 #sideBySide {
37 white-space: nowrap;
38 }
39 #liveTester.fullscreen {
40 position: absolute;
41 top: 0px;
42 left: 0px;
43 right: 0px;
44 z-index: 99;
45 bottom: 0px;
46 }
47 </style>
48 <title>Try isort</title>
49 </head>
50
51 <div id="liveTester">
52 <div id="sideBySide">
53 <div id="inputEditor" class="editor">from future import braces
54 import b
55 import b
56 import os
57 import a
58 from future import braces
59 import b
60 import a
61 import b, a
62 </div>
63 <div id="outputEditor" class="editor">Installing isort with Pyodide...</div>
64 <div>
65
66 &nbsp;Configuration (Note: the below must follow JSON format). Full configuration guide is <a href="../configuration/options.html">here</a>:
67
68 <div id="configEditor" class="configurator">{"line_length": 80,
69 "profile": "black",
70 "atomic": true
71 }
72 </div>
73 </div>
74 </div>
75 </div>
76
77 <script type="text/javascript">
78 window.addEventListener("load", () => {
79 var input = ace.edit("inputEditor");
80 var output = ace.edit("outputEditor");
81 var configurator = ace.edit("configEditor");
82
83 [input, output, configurator].forEach((editor) => {
84 editor.setTheme("ace/theme/monokai");
85 editor.session.setMode("ace/mode/python");
86 editor.resize();
87 });
88
89 configurator.session.setMode("ace/mode/json");
90
91 function updateOutput() {
92 output.setValue(document.sort_code(input.getValue(), configurator.getValue()));
93 }
94
95 output.setReadOnly(true);
96 input.session.on("change", updateOutput);
97 configurator.session.on("change", updateOutput);
98
99 document.updateOutput = updateOutput;
100 });
101
102 async function main() {
103 let pyodide = await loadPyodide();
104 await pyodide.loadPackage("micropip");
105 const micropip = pyodide.pyimport("micropip");
106 await micropip.install("isort");
107 await pyodide.runPython(`
108 from js import document
109
110 import isort
111 import json
112 import textwrap
113
114 def sort_code(code, configuration):
115 try:
116 configuration = json.loads(configuration or "{}")
117 except Exception as configuration_error:
118 return "\\n".join(textwrap.wrap(f"Exception thrown trying to read given configuration {configuration_error}", 40))
119 try:
120 return f"# Using {isort.__version__} of isort." + "\\n\\n" + isort.code(code, **configuration)
121 except Exception as isort_error:
122 return "\\n".join(textwrap.wrap(f"Exception thrown trying to sort given imports {isort_error}", 40))
123
124 document.sort_code = sort_code
125 document.updateOutput()
126 `);
127 }
128 main();
129 </script>
130 <div style="clear:both;"></div>
131 Like what you saw? Installing isort to use locally is as simple as `pip install isort`.
132
133 [Click here for full installation instructions.](./1.-install.md)