Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Aug 31, 2023
1 parent 9bceb01 commit 00db08b
Show file tree
Hide file tree
Showing 36 changed files with 10,989 additions and 98 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
python -m pip install -r robocorp-code/tests/test_requirements.txt
python -m pip install -r robocorp-code/dev_requirements.txt
python -m pip install msgspec
python -m pip install robotframework
python -m pip install robotframework-output-stream
Expand Down
5 changes: 0 additions & 5 deletions robocorp-code/.settings/org.python.pydev.analysis.yaml

This file was deleted.

3 changes: 1 addition & 2 deletions robocorp-code/.settings/org.python.pydev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ MYPY_ARGS: --follow-imports=silent --show-column-numbers --namespace-packages --
MYPY_FILE_LOCATION: ''
MYPY_USE_CONSOLE: true
PYDEV_TEST_RUNNER: '2'
PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n
0 --tb=native -vv --force-regen --assert=plain
PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n 0 --tb=native -vv --force-regen --assert=plain
PYDEV_USE_PYUNIT_VIEW: true
RUFF_ARGS: ''
RUFF_FILE_LOCATION: ''
Expand Down
3 changes: 2 additions & 1 deletion robocorp-code/bin/create_env/conda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
- python=3.9.13 # https://pyreadiness.org/3.9/
- pip=22.1.2 # https://pip.pypa.io/en/stable/news/
- pyyaml=6.0
- msgspec=0.18.2
- pip:
- robocorp-inspector==0.10.1 # https://github.com/robocorp/inspector/blob/master/CHANGELOG.md
- robocorp-inspector==0.10.2 # https://github.com/robocorp/inspector/blob/master/CHANGELOG.md
- robotframework==5.0.1 # https://github.com/robotframework/robotframework/blob/master/doc/releasenotes/rf-5.0.1.rst
3 changes: 2 additions & 1 deletion robocorp-code/bin/create_env/conda_vscode_darwin_amd64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- pip=22.1.2 # https://pip.pypa.io/en/stable/news/
- python.app=1.3 # https://anaconda.org/conda-forge/python.app/files
- pyyaml=6.0
- msgspec=0.18.2
- pip:
- robocorp-inspector==0.10.1 # https://github.com/robocorp/inspector/blob/master/CHANGELOG.md
- robocorp-inspector==0.10.2 # https://github.com/robocorp/inspector/blob/master/CHANGELOG.md
- robotframework==5.0.1 # https://github.com/robotframework/robotframework/blob/master/doc/releasenotes/rf-5.0.1.rst
3 changes: 2 additions & 1 deletion robocorp-code/bin/create_env/conda_vscode_linux_amd64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- pyside2=5.15.4 # https://wiki.qt.io/Qt_for_Python
- qtpy=2.3.0 # https://github.com/spyder-ide/qtpy/blob/master/CHANGELOG.md
- pyyaml=6.0
- msgspec=0.18.2
- pip:
- robocorp-inspector==0.10.1 # https://github.com/robocorp/inspector/blob/master/CHANGELOG.md
- robocorp-inspector==0.10.2 # https://github.com/robocorp/inspector/blob/master/CHANGELOG.md
- robotframework==5.0.1 # https://github.com/robotframework/robotframework/blob/master/doc/releasenotes/rf-5.0.1.rst
3 changes: 2 additions & 1 deletion robocorp-code/bin/create_env/conda_vscode_windows_amd64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- pip=22.1.2 # https://pip.pypa.io/en/stable/news/
- pywin32=303 # https://github.com/mhammond/pywin32/blob/main/CHANGES.txt
- pyyaml=6.0
- msgspec=0.18.2
- pip:
- robocorp-inspector==0.10.1 # https://github.com/robocorp/inspector/blob/master/CHANGELOG.md
- robocorp-inspector==0.10.2 # https://github.com/robocorp/inspector/blob/master/CHANGELOG.md
- robotframework==5.0.1 # https://github.com/robotframework/robotframework/blob/master/doc/releasenotes/rf-5.0.1.rst
17 changes: 11 additions & 6 deletions robocorp-code/src/robocorp_code/deps/_conda_deps.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from dataclasses import dataclass
from typing import Dict, Optional
from typing import Dict, Iterator, Optional

from .analyzer import _RangeTypedDict
from ._deps_protocols import _RangeTypedDict
from .conda_impl import conda_match_spec, conda_version


@dataclass
class _CondaDepInfo:
class CondaDepInfo:
name: str # The name of the dep (i.e.: python)
value: str # The full value of the dep (i.e.: python=3.7)
version: str # The version of the dep (as seen by conda: '3.7.*')
Expand All @@ -15,7 +15,7 @@ class _CondaDepInfo:

class CondaDeps:
def __init__(self):
self._deps: Dict[str, _CondaDepInfo] = {}
self._deps: Dict[str, CondaDepInfo] = {}

def add_dep(self, value: str, dep_range: _RangeTypedDict):
"""
Expand All @@ -25,14 +25,16 @@ def add_dep(self, value: str, dep_range: _RangeTypedDict):
"""
try:
spec = conda_match_spec.parse_spec_str(value)
version = spec["version"]

# It may not have a version if it wasn't specified.
version = spec.get("version", "*")
if version.endswith("*"):
version = version[:-1]
name = spec["name"]
except Exception:
pass
else:
self._deps[name] = _CondaDepInfo(name, value, version, dep_range)
self._deps[name] = CondaDepInfo(name, value, version, dep_range)

def get_dep_vspec(self, spec_name: str) -> Optional[conda_version.VersionSpec]:
conda_dep_info = self._deps.get(spec_name)
Expand All @@ -43,3 +45,6 @@ def get_dep_vspec(self, spec_name: str) -> Optional[conda_version.VersionSpec]:

def get_dep_range(self, spec_name: str) -> _RangeTypedDict:
return self._deps[spec_name].dep_range

def iter_conda_dep_infos(self) -> Iterator[CondaDepInfo]:
yield from self._deps.values()
70 changes: 69 additions & 1 deletion robocorp-code/src/robocorp_code/deps/_deps_protocols.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Versions = Union[LegacyVersion, Version]
import datetime
import sys
import typing
from contextlib import contextmanager
from dataclasses import dataclass
from typing import Any, Dict, Iterator, List, Optional, Union
from typing import Any, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Union

# Hack so that we don't break the runtime on versions prior to Python 3.8.
if sys.version_info[:2] < (3, 8):
Expand Down Expand Up @@ -106,6 +108,72 @@ def get_versions_newer_than(
"""


SubdirToBuildAndDependsJsonBytesType = Dict[str, List[Tuple[str, bytes]]]


@dataclass(unsafe_hash=True)
class CondaVersionInfo:
package_name: str
version: str
timestamp: int # Max is given
subdir_to_build_and_depends_json_bytes: SubdirToBuildAndDependsJsonBytesType


if typing.TYPE_CHECKING:
# No need for sqlite3 until it's actually used.
from sqlite3 import Cursor
else:
Cursor = object


class LatestIndexInfoTypedDict(TypedDict):
# The place where the index info is saved.
index_dir: str
timestamp: datetime.datetime


class ISqliteQueries(Protocol):
@contextmanager
def db_cursors(
self, db_cursor: Optional[Sequence[Cursor]] = None
) -> Iterator[Sequence[Cursor]]:
pass

def query_names(self, db_cursors: Optional[Sequence[Cursor]] = None) -> Set[str]:
pass

def query_versions(
self, package_name, db_cursors: Optional[Sequence[Cursor]] = None
) -> Set[str]:
pass

def query_version_info(
self,
package_name: str,
version: str,
db_cursors: Optional[Sequence[Cursor]] = None,
) -> CondaVersionInfo:
pass


class IOnFinished(Protocol):
def __call__(self):
pass


class ICondaCloud(Protocol):
def is_information_cached(self) -> bool:
pass

def sqlite_queries(self) -> Optional[ISqliteQueries]:
pass

def schedule_update(
self, on_finished: Optional[IOnFinished] = None, wait=False, force=False
) -> None:
pass


class _DiagnosticSeverity(object):
Error = 1
Warning = 2
Expand Down
8 changes: 8 additions & 0 deletions robocorp-code/src/robocorp_code/deps/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any, Iterator, List, Optional, Tuple

import yaml
from robocorp_code.deps._conda_deps import CondaDepInfo
from robocorp_code.deps._deps_protocols import (
_DiagnosticSeverity,
_DiagnosticsTypedDict,
Expand Down Expand Up @@ -270,6 +271,13 @@ def find_pip_dep_at(self, line, col) -> Optional[PipDepInfo]:
return dep_info
return None

def find_conda_dep_at(self, line, col) -> Optional[CondaDepInfo]:
self.load_conda_yaml()
for dep_info in self._conda_deps.iter_conda_dep_infos():
if is_inside(dep_info.dep_range, line, col):
return dep_info
return None


def is_inside(range_dct: _RangeTypedDict, line: int, col: int) -> bool:
from robocorp_ls_core.lsp import Position
Expand Down
Loading

0 comments on commit 00db08b

Please sign in to comment.