0
# Console Scripts and Entry Points
1
2
Command-line utilities for running Julia through PyJulia (`julia-py`) and Python within Julia processes (`python-jl`), providing seamless integration for shell-based workflows and cross-language development.
3
4
## Capabilities
5
6
### Julia-Py Console Script
7
8
Launch Julia interpreter through PyJulia with Python integration enabled.
9
10
```python { .api }
11
def julia_py(julia: str, pyjulia_debug: bool, jl_args: list):
12
"""
13
Launch Julia interpreter through PyJulia.
14
15
Parameters:
16
- julia: Path to Julia executable
17
- pyjulia_debug: Enable PyJulia debugging output
18
- jl_args: Arguments to pass to Julia
19
"""
20
21
def main(args=None, **kwargs):
22
"""
23
Command line interface for julia-py script.
24
25
Parameters:
26
- args: Command line arguments (default: sys.argv)
27
- **kwargs: Additional configuration options
28
"""
29
30
def parse_args(args: list, **kwargs) -> argparse.Namespace:
31
"""
32
Parse command line arguments for julia-py.
33
34
Parameters:
35
- args: Command line arguments to parse
36
- **kwargs: Parser configuration options
37
38
Returns:
39
- Parsed arguments namespace
40
"""
41
42
def is_pyjulia_in_julia_debug(julia_debug: bool) -> bool:
43
"""
44
Check if PyJulia debugging is enabled.
45
46
Parameters:
47
- julia_debug: Julia debug flag
48
49
Returns:
50
- True if PyJulia debugging should be enabled
51
"""
52
```
53
54
### Python-JL Console Script
55
56
Run Python interpreter inside Julia process for enhanced integration.
57
58
```python { .api }
59
def main(args=None):
60
"""
61
Python interpreter running inside Julia process.
62
63
Parameters:
64
- args: Command line arguments (default: sys.argv)
65
"""
66
67
def remove_julia_options(args: list) -> list:
68
"""
69
Remove Julia-specific options from argument list.
70
71
Parameters:
72
- args: Original argument list
73
74
Returns:
75
- Filtered argument list with Julia options removed
76
"""
77
78
def parse_pyjl_args(args: list):
79
"""
80
Parse arguments for python-jl script.
81
82
Parameters:
83
- args: Command line arguments to parse
84
85
Returns:
86
- Parsed configuration for python-jl execution
87
"""
88
```
89
90
### Pseudo Python CLI
91
92
Python-like command line interface with Julia integration.
93
94
```python { .api }
95
class PyArgumentParser:
96
"""Argument parser that mimics Python's argparse behavior."""
97
98
def python(module: str = None, command: str = None, script: str = None,
99
args: list = None, interactive: bool = False):
100
"""
101
Execute Python-like commands with Julia integration.
102
103
Parameters:
104
- module: Python module to run (-m option)
105
- command: Python command to execute (-c option)
106
- script: Python script file to run
107
- args: Arguments to pass to script/module
108
- interactive: Enable interactive mode (-i option)
109
"""
110
111
def make_parser(description: str) -> PyArgumentParser:
112
"""
113
Create argument parser with description.
114
115
Parameters:
116
- description: Parser description text
117
118
Returns:
119
- Configured PyArgumentParser instance
120
"""
121
122
def parse_args_with(parser: PyArgumentParser, args: list):
123
"""
124
Parse arguments using given parser.
125
126
Parameters:
127
- parser: PyArgumentParser instance
128
- args: Arguments to parse
129
130
Returns:
131
- Parsed arguments
132
"""
133
134
def parse_args(args: list):
135
"""
136
Parse command line arguments for pseudo Python CLI.
137
138
Parameters:
139
- args: Command line arguments
140
141
Returns:
142
- Parsed configuration
143
"""
144
```
145
146
## Usage Examples
147
148
### Using julia-py Console Script
149
150
```bash
151
# Basic usage - start Julia with PyJulia integration
152
julia-py
153
154
# Run Julia script through PyJulia
155
julia-py my_script.jl
156
157
# Pass arguments to Julia script
158
julia-py my_script.jl arg1 arg2 arg3
159
160
# Enable PyJulia debugging
161
julia-py --pyjulia-debug
162
163
# Use specific Julia executable
164
julia-py --julia /path/to/julia
165
166
# Pass Julia-specific options
167
julia-py --julia-args "--threads=4 --optimize=2"
168
169
# Execute Julia code directly
170
julia-py -e "println(\"Hello from Julia-Py!\")"
171
172
# Interactive Julia session with PyJulia
173
julia-py -i
174
```
175
176
### Using python-jl Console Script
177
178
```bash
179
# Run Python inside Julia process
180
python-jl
181
182
# Execute Python script in Julia process
183
python-jl my_script.py
184
185
# Pass arguments to Python script
186
python-jl my_script.py arg1 arg2
187
188
# Execute Python code directly
189
python-jl -c "print('Hello from Python-JL!')"
190
191
# Interactive Python in Julia
192
python-jl -i
193
194
# Run Python module
195
python-jl -m module_name
196
197
# Combine Julia and Python options
198
python-jl --julia-args "--threads=4" -c "import julia; print('Integrated!')"
199
```
200
201
### Programmatic Usage
202
203
```python
204
from julia.julia_py import main as julia_py_main
205
from julia.python_jl import main as python_jl_main
206
207
# Launch julia-py programmatically
208
julia_py_main([
209
"--pyjulia-debug",
210
"-e",
211
"println(\"Programmatic launch\")"
212
])
213
214
# Launch python-jl programmatically
215
python_jl_main([
216
"-c",
217
"print('Python in Julia process')"
218
])
219
```
220
221
### Advanced Configuration
222
223
```python
224
from julia.julia_py import parse_args, julia_py
225
226
# Parse custom arguments
227
args = parse_args([
228
"--julia", "/custom/julia",
229
"--pyjulia-debug",
230
"script.jl", "arg1", "arg2"
231
])
232
233
# Launch with parsed configuration
234
julia_py(
235
julia=args.julia,
236
pyjulia_debug=args.pyjulia_debug,
237
jl_args=args.remaining_args
238
)
239
```
240
241
### Integration in Shell Scripts
242
243
```bash
244
#!/bin/bash
245
246
# Shell script using PyJulia console scripts
247
248
# Set up environment
249
export JULIA_NUM_THREADS=4
250
export PYTHON_PATH="/path/to/python/env"
251
252
# Run data processing in Julia with Python integration
253
julia-py --pyjulia-debug data_processing.jl input.csv output.csv
254
255
# Post-process results with Python in Julia context
256
python-jl -c "
257
import pandas as pd
258
import julia
259
jl = julia.Julia()
260
261
# Access Julia variables from Python
262
result = jl.eval('result_data')
263
df = pd.DataFrame(result)
264
df.to_csv('final_output.csv')
265
print('Processing complete!')
266
"
267
```
268
269
### Cross-Language Development Workflow
270
271
```python
272
# Development script using both console entry points
273
274
import subprocess
275
import os
276
277
def run_julia_analysis():
278
"""Run Julia analysis using julia-py."""
279
cmd = [
280
"julia-py",
281
"--pyjulia-debug",
282
"analysis.jl",
283
"--input", "data.csv",
284
"--output", "results.json"
285
]
286
subprocess.run(cmd, check=True)
287
288
def run_python_visualization():
289
"""Run Python visualization in Julia context."""
290
cmd = [
291
"python-jl",
292
"visualize.py",
293
"results.json",
294
"plots/"
295
]
296
subprocess.run(cmd, check=True)
297
298
def integrated_workflow():
299
"""Complete analysis and visualization workflow."""
300
print("Running Julia analysis...")
301
run_julia_analysis()
302
303
print("Creating Python visualizations...")
304
run_python_visualization()
305
306
print("Workflow complete!")
307
308
if __name__ == "__main__":
309
integrated_workflow()
310
```
311
312
### Pseudo Python CLI Usage
313
314
```python
315
from julia.pseudo_python_cli import python, main as pseudo_main
316
317
# Execute module through pseudo CLI
318
python(module="my_module", args=["arg1", "arg2"])
319
320
# Execute command through pseudo CLI
321
python(command="print('Hello world!')")
322
323
# Execute script with interactive mode
324
python(script="my_script.py", interactive=True)
325
326
# Command line interface
327
pseudo_main(["-m", "my_module", "arg1", "arg2"])
328
```
329
330
### Environment Integration
331
332
```bash
333
# Add PyJulia console scripts to system PATH
334
export PATH="$PATH:$(python -c 'import julia; print(julia.__path__[0])')/bin"
335
336
# Create aliases for common operations
337
alias jpy="julia-py --pyjulia-debug"
338
alias pyjl="python-jl"
339
340
# Use in pipelines
341
data_generator.py | julia-py process_data.jl | python-jl post_process.py > final_results.txt
342
```
343
344
### IDE and Editor Integration
345
346
```json
347
// VS Code task configuration for PyJulia console scripts
348
{
349
"version": "2.0.0",
350
"tasks": [
351
{
352
"label": "Run Julia with PyJulia",
353
"type": "shell",
354
"command": "julia-py",
355
"args": ["${file}"],
356
"group": "build",
357
"presentation": {
358
"echo": true,
359
"reveal": "always",
360
"focus": false,
361
"panel": "shared"
362
}
363
},
364
{
365
"label": "Run Python in Julia",
366
"type": "shell",
367
"command": "python-jl",
368
"args": ["${file}"],
369
"group": "build"
370
}
371
]
372
}
373
```
374
375
## Error Handling and Debugging
376
377
Console scripts provide detailed error reporting and debugging options:
378
379
```bash
380
# Enable verbose debugging
381
julia-py --pyjulia-debug --verbose script.jl
382
383
# Capture and handle errors in shell scripts
384
if ! julia-py analysis.jl; then
385
echo "Julia analysis failed"
386
exit 1
387
fi
388
389
# Check console script availability
390
command -v julia-py >/dev/null 2>&1 || {
391
echo "julia-py not found. Please install PyJulia."
392
exit 1
393
}
394
```
395
396
## Console Script Options
397
398
### julia-py Options
399
400
- `--julia PATH`: Path to Julia executable
401
- `--pyjulia-debug`: Enable PyJulia debugging output
402
- `--julia-args ARGS`: Arguments to pass to Julia
403
- `-e CODE`: Execute Julia code
404
- `-i`: Interactive mode
405
- `--help`: Show help message
406
407
### python-jl Options
408
409
- `--julia-args ARGS`: Arguments to pass to Julia runtime
410
- `-c CODE`: Execute Python code
411
- `-m MODULE`: Run Python module
412
- `-i`: Interactive mode after script
413
- `--help`: Show help message
414
415
These console scripts provide the foundation for integrating PyJulia into automated workflows, shell scripts, and development environments.