From 97cfe933760118d7e52f94f87937adcdb8db2ec5 Mon Sep 17 00:00:00 2001 From: bagel897 Date: Wed, 31 Jan 2024 22:23:45 -0600 Subject: [PATCH] restore files from master --- docs/configuration.rst | 6 +- rope/base/prefs.py | 97 +++++++++++-------------------- rope/contrib/autoimport/sqlite.py | 9 +-- 3 files changed, 41 insertions(+), 71 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index f98a489c..b7735976 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -53,15 +53,15 @@ Additionally, you can run an executable function at startup of rope. pytool.toml ----------- If neither a config.py or a pyproject.toml is present, rope will use a pytool.toml. -It follows the exact same syntax of the pyproject.toml. +It follows the exact same syntax as ``pyproject.toml``. -- Mac OS X: ``~/Library/Application Support/pytool.toml.`` +- Mac OS X: ``~/Library/Application Support/pytool.toml``. - Unix: ``~/.config/pytool.toml``` or in $XDG_CONFIG_HOME, if defined - Windows: ``C:\Users\\AppData\Local\pytool.toml`` Options -======= +------- .. autopytoolconfigtable:: rope.base.prefs.Prefs Autoimport Options diff --git a/rope/base/prefs.py b/rope/base/prefs.py index 2d04fc5b..49174657 100644 --- a/rope/base/prefs.py +++ b/rope/base/prefs.py @@ -15,10 +15,10 @@ @dataclass class AutoimportPrefs: underlined: bool = field( - default=False, description="Cache underlined (private) modules" - ) + default=False, description="Cache underlined (private) modules") # memory: bool = field(default=None, description="Cache in memory instead of disk") # parallel: bool = field(default=True, description="Use multiple processes to parse") + aliases: List[Tuple[str, str]] = field( default_factory=lambda: [ ("np", "numpy"), @@ -29,12 +29,10 @@ class AutoimportPrefs: ("sk", "sklearn"), ("sm", "statsmodels"), ], - description=dedent( - """ + description=dedent(""" Aliases for module names. For example, `[('np', 'numpy')]` makes rope recommend ``import numpy as np``. - """ - ), + """), ) @@ -57,8 +55,7 @@ class Prefs: ".mypy_cache", ".pytest_cache", ], - description=dedent( - """ + description=dedent(""" Specify which files and folders to ignore in the project. Changes to ignored resources are not added to the history and VCSs. Also they are not returned in `Project.get_files()`. @@ -68,23 +65,19 @@ class Prefs: '.svn': matches 'pkg/.svn' and all of its children 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o' 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o' - """ - ), + """), ) python_files: List[str] = field( default_factory=lambda: ["*.py"], - description=dedent( - """ + description=dedent(""" Specifies which files should be considered python files. It is useful when you have scripts inside your project. Only files ending with ``.py`` are considered to be python files by default. - """ - ), + """), ) source_folders: List[str] = field( - description=dedent( - """ + description=dedent(""" Custom source folders: By default rope searches the project for finding source folders (folders that should be searched for finding modules). You can add paths to that list. Note @@ -93,8 +86,7 @@ class Prefs: The folders should be relative to project root and use '/' for separating folders regardless of the platform rope is running on. 'src/my_source_folder' for instance. - """ - ), + """), default_factory=lambda: [], ) python_path: List[str] = field( @@ -116,12 +108,10 @@ class Prefs: ) perform_doa: bool = field( default=True, - description=dedent( - """ + description=dedent(""" If `False` when running modules or unit tests 'dynamic object analysis' is turned off. This makes them much faster. - """ - ), + """), ) validate_objectdb: bool = field( default=False, @@ -139,13 +129,11 @@ class Prefs: indent_size: int = field( default=4, - description=dedent( - """ + description=dedent(""" Set the number spaces used for indenting. According to :PEP:`8`, it is best to use 4 spaces. Since most of rope's unit-tests use 4 spaces it is more reliable, too. - """ - ), + """), ) extension_modules: List[str] = field( @@ -161,68 +149,55 @@ class Prefs: ) ignore_syntax_errors: bool = field( default=False, - description=dedent( - """ + description=dedent(""" If `True` modules with syntax errors are considered to be empty. The default value is `False`; When `False` syntax errors raise `rope.base.exceptions.ModuleSyntaxError` exception. - """ - ), + """), ) ignore_bad_imports: bool = field( default=False, - description=dedent( - """ + description=dedent(""" If `True`, rope ignores unresolvable imports. Otherwise, they appear in the importing namespace. - """ - ), + """), ) prefer_module_from_imports: bool = field( default=False, - description=dedent( - """ + description=dedent(""" If `True`, rope will insert new module imports as `from import `by default. - """ - ), + """), ) split_imports: bool = field( default=False, - description=dedent( - """ + description=dedent(""" If `True`, rope will transform a comma list of imports into multiple separate import statements when organizing imports. - """ - ), + """), ) pull_imports_to_top: bool = field( default=True, - description=dedent( - """ + description=dedent(""" If `True`, rope will remove all top-level import statements and reinsert them at the top of the module when making changes. - """ - ), + """), ) sort_imports_alphabetically: bool = field( default=False, - description=dedent( - """ + description=dedent(""" If `True`, rope will sort imports alphabetically by module name instead of alphabetically by import statement, with from imports after normal imports. - """ - ), + """), ) type_hinting_factory: str = field( "rope.base.oi.type_hinting.factory.default_type_hinting_factory", - description=dedent( - """ + description=dedent(""" Location of implementation of rope.base.oi.type_hinting.interfaces.ITypeHintingFactory In general case, you don't have to change this value, unless you're an rope expert. @@ -230,17 +205,14 @@ class Prefs: listed in module rope.base.oi.type_hinting.providers.interfaces For example, you can add you own providers for Django Models, or disable the search type-hinting in a class hierarchy, etc. - """ - ), + """), ) project_opened: Optional[Callable] = field( None, - description=dedent( - """ + description=dedent(""" This function is called after opening the project. Can only be set in config.py. - """ - ), + """), ) py_version: Optional[Tuple[int, int]] = field( default=None, @@ -252,16 +224,13 @@ class Prefs: ) callbacks: Dict[str, Callable[[Any], None]] = field( default_factory=lambda: {}, - description=dedent( - """ + description=dedent(""" Callbacks run when configuration values are changed. Can only be set in config.py. - """ - ), + """), ) autoimport: AutoimportPrefs = field( - default_factory=AutoimportPrefs, description="Preferences for Autoimport" - ) + default_factory=AutoimportPrefs, description="Preferences for Autoimport") def set(self, key: str, value: Any): """Set the value of `key` preference to `value`.""" diff --git a/rope/contrib/autoimport/sqlite.py b/rope/contrib/autoimport/sqlite.py index f18878f3..bdec6fb5 100644 --- a/rope/contrib/autoimport/sqlite.py +++ b/rope/contrib/autoimport/sqlite.py @@ -2,30 +2,31 @@ import contextlib import json -from hashlib import sha256 -import secrets import re +import secrets import sqlite3 import sys import warnings from collections import OrderedDict from concurrent.futures import Future, ProcessPoolExecutor, as_completed +from copy import deepcopy from datetime import datetime +from hashlib import sha256 from itertools import chain from pathlib import Path from threading import local from typing import Generator, Iterable, Iterator, List, Optional, Set, Tuple from packaging.requirements import Requirement -from copy import deepcopy + from rope.base import exceptions, libutils, resourceobserver, taskhandle, versioning from rope.base.prefs import AutoimportPrefs from rope.base.project import Project from rope.base.resources import Resource from rope.contrib.autoimport import models from rope.contrib.autoimport.defs import ( - ModuleFile, Alias, + ModuleFile, Name, NameType, Package,