Format: application/x-python-code
1 o
2
3 �h�~ � @ s� d Z ddlZddlmZ ddlZddlmZ ddlmZ ddl m
4 Z
5 ddl mZ ddl mZ dd l
6 mZ dd
7 lmZ ddlmZ ddlmZ dd
8 lmZ ddlmZmZ ddlmZ ddlmZ ddlmZmZ ddlm Z ddlm!Z! ddl"m#Z#m$Z$ ddl%m&Z& ddl%m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: dd l;m<Z< dd!l=m>Z> e�?d"� G d#d$� d$�Z@G d%d&� d&e@�ZAd'd(� ZBe
9 jCd)d)d)fd*d+�ZDdS ),aQ
10 The API basically only provides one class. You can create a :class:`Script` and
11 use its methods.
12
13 Additionally you can add a debug function with :func:`set_debug_function`.
14 Alternatively, if you don't need a custom function and are happy with printing
15 debug messages to stdout, simply call :func:`set_debug_function` without
16 arguments.
17 � N)�Path)�tree)�get_executable_nodes)�debug)�settings)�cache)�KnownContentFileIO)�classes)�interpreter)�helpers)�validate_line_column)�
18 Completion�search_in_module)�KeywordName)�InterpreterEnvironment)�get_default_project�Project)�parso_to_jedi_errors)�refactoring)�extract_function�extract_variable)�InferenceState)�imports)�find_references)�try_iter_content)�infer_call_of_leaf)�transform_path_to_dotted)�tree_name_to_values)�ModuleValue)�ValueSet)�unpack_tuple_to_dict)�
19 convert_names�convert_values)�load_proper_stub_module)�to_listi� c @ s@ e Zd ZdZd7dddd�dd�Zejdd� �Zdd � Zd
20 d� Z e
21 d8dd
22 �dd��Ze
23 d8ddd�dd��Ze
24 d8ddddd�dd��Z
25 dd�dd�Zed9dd��Zdd� Ze
26 d8dd��Ze
27 d8dd ��Ze
28 d8d!d"��Ze
29 d8d#d$��Zd%d&� Zd'd(� Zd)d*� Zd:d,d-�Zd8d.d/�Ze
30 ddd0�d1d2��Ze
31 ddd0�d3d4��Zd8d5d6�ZdS );�ScriptaK
32
33 A Script is the base for completions, goto or whatever you want to do with
34 Jedi. The counter part of this class is :class:`Interpreter`, which works
35 with actual dictionaries and can work with a REPL. This class
36 should be used when a user edits code in an editor.
37
38 You can either use the ``code`` parameter or ``path`` to read a file.
39 Usually you're going to want to use both of them (in an editor).
40
41 The Script's ``sys.path`` is very customizable:
42
43 - If `project` is provided with a ``sys_path``, that is going to be used.
44 - If `environment` is provided, its ``sys.path`` will be used
45 (see :func:`Environment.get_sys_path <jedi.api.environment.Environment.get_sys_path>`);
46 - Otherwise ``sys.path`` will match that of the default environment of
47 Jedi, which typically matches the sys path that was used at the time
48 when Jedi was imported.
49
50 Most methods have a ``line`` and a ``column`` parameter. Lines in Jedi are
51 always 1-based and columns are always zero based. To avoid repetition they
52 are not always documented. You can omit both line and column. Jedi will
53 then just do whatever action you are calling at the end of the file. If you
54 provide only the line, just will complete at the end of that line.
55
56 .. warning:: By default :attr:`jedi.settings.fast_parser` is enabled, which means
57 that parso reuses modules (i.e. they are not immutable). With this setting
58 Jedi is **not thread safe** and it is also not safe to use multiple
59 :class:`.Script` instances and its definitions at the same time.
60
61 If you are a normal plugin developer this should not be an issue. It is
62 an issue for people that do more complex stuff with Jedi.
63
64 This is purely a performance optimization and works pretty well for all
65 typical usages, however consider to turn the setting off if it causes
66 you problems. See also
67 `this discussion <https://github.com/davidhalter/jedi/issues/1240>`_.
68
69 :param code: The source code of the current file, separated by newlines.
70 :type code: str
71 :param path: The path of the file in the file system, or ``''`` if
72 it hasn't been saved yet.
73 :type path: str or pathlib.Path or None
74 :param Environment environment: Provide a predefined :ref:`Environment <environments>`
75 to work with a specific Python version or virtualenv.
76 :param Project project: Provide a :class:`.Project` to make sure finding
77 references works well, because the right folder is searched. There are
78 also ways to modify the sys path and other things.
79 N)�path�environment�projectc C s || _ t|t�rt|�}|r|�� nd | _|d u r:|d u r!td��t|d��}|�� }W d � n1 s5w Y |d u rKt | jd u rFd n| jj
80 �}t||| jd�| _t
81 �d� | jj|| j|oe|jdkdtjtjd�\| _}t
82 �d� tj|d d
83 �| _|| _t�� t
84 �� d S )Nz)Must provide at least one of code or path�rb)r'