Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

investigate escaping jumping to definition (and other features) with spaces #406

Merged
merged 15 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion atest/00_Smoke.robot
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*** Settings ***
Suite Setup Set Screenshot Directory ${OUTPUT DIR}${/}screenshots${/}smoke
Suite Setup Set Screenshot Directory ${SCREENSHOTS DIR}${/}smoke
Resource Keywords.robot

*** Test Cases ***
Expand Down
2 changes: 1 addition & 1 deletion atest/01_Editor.robot
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*** Settings ***
Suite Setup Setup Suite For Screenshots editor
Force Tags ui:editor
Force Tags ui:editor aspect:ls:features
Resource Keywords.robot
Resource Variables.robot

Expand Down
2 changes: 1 addition & 1 deletion atest/03_Notebook.robot
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Foreign Extractors
Code Overrides
${file} = Set Variable Code overrides.ipynb
Setup Notebook Python ${file}
${virtual_path} = Set Variable ${OUTPUT DIR}${/}home${/}.virtual_documents/Code\ overrides.ipynb
${virtual_path} = Set Variable ${VIRTUALDOCS DIR}${/}Code overrides.ipynb
Wait Until Created ${virtual_path}
${document} = Get File ${virtual_path}
Should Be Equal ${document} get_ipython().run_line_magic("ls", "")\n\n\nget_ipython().run_line_magic("pip", " freeze")\n
1 change: 1 addition & 0 deletions atest/04_Interface/DiagnosticsPanel.robot
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Settings ***
Suite Setup Setup Suite For Screenshots diagnostics_panel
Resource ../Keywords.robot
Force Tags ui:notebook aspect:ls:features
Test Setup Set Up
Test Teardown Clean Up

Expand Down
4 changes: 2 additions & 2 deletions atest/06_Style.robot
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Screenshot Editor Themes with Lab Theme
[Arguments] ${lab theme} ${file}=style.py ${notebook}=Diagnostic.ipynb
${norm lab theme} = Set Variable ${lab theme.lower().replace(" ", "-")}
Set Tags theme:lab:${norm lab theme}
Set Screenshot Directory ${OUTPUT DIR}${/}style${/}${norm lab theme}
Copy File examples${/}${file} ${OUTPUT DIR}${/}home${/}${file}
Set Screenshot Directory ${SCREENSHOTS DIR}${/}style${/}${norm lab theme}
Copy File examples${/}${file} ${NOTEBOOK DIR}${/}${file}
Run Keyword If "${THEME NAMES}" == "" Wait Until Keyword Succeeds 3x 1s Get Theme Names
Lab Command Use ${lab theme} Theme
Try to Close All Tabs
Expand Down
4 changes: 2 additions & 2 deletions atest/07_Configuration.robot
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ LaTeX
*** Keywords ***
Settings Should Change Editor Diagnostics
[Arguments] ${language} ${file} ${server} ${settings} ${before} ${after} ${save command}=${EMPTY} ${needs reload}=${False}
${before diagnostic} = Set Variable ${CSS DIAGNOSTIC}\[title^="${before}"]
${after diagnostic} = Set Variable ${CSS DIAGNOSTIC}\[title^="${after}"]
${before diagnostic} = Set Variable ${CSS DIAGNOSTIC}\[title*="${before}"]
${after diagnostic} = Set Variable ${CSS DIAGNOSTIC}\[title*="${after}"]
krassowski marked this conversation as resolved.
Show resolved Hide resolved
${tab} = Set Variable ${JLAB XP DOCK TAB}\[contains(., '${file}')]
${close icon} = Set Variable *[contains(@class, 'm-TabBar-tabCloseIcon')]
${save command} = Set Variable If "${save command}" ${save command} Save ${language} File
Expand Down
86 changes: 47 additions & 39 deletions atest/Keywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,67 @@ Library SeleniumLibrary
Library OperatingSystem
Library Process
Library String
Library Collections
Library ./logcheck.py
Library ./ports.py
Library ./config.py

*** Keywords ***
Setup Server and Browser
${port} = Get Unused Port
Set Global Variable ${PORT} ${port}
Set Global Variable ${URL} http://localhost:${PORT}${BASE}
Initialize Global Variables
Create Notebok Server Config
Initialize User Settings
${server} = Start Process jupyter-lab
... cwd=${NOTEBOOK DIR}
... stdout=${LAB LOG}
... stderr=STDOUT
... env:HOME=${HOME}
Set Global Variable ${SERVER} ${server}
Open JupyterLab
Read Page Config

Initialize Global Variables
${root} = Normalize Path ${OUTPUT DIR}${/}..${/}..${/}..
Set Global Variable ${ROOT} ${root}
${accel} = Evaluate "COMMAND" if "${OS}" == "Darwin" else "CTRL"
Set Global Variable ${ACCEL} ${accel}
${token} = Generate Random String
Set Global Variable ${TOKEN} ${token}
${home} = Set Variable ${OUTPUT DIR}${/}home
${root} = Normalize Path ${OUTPUT DIR}${/}..${/}..${/}..
Create Directory ${home}
Create Notebok Server Config ${home}
Initialize User Settings
${cmd} = Create Lab Launch Command ${root}
Set Screenshot Directory ${OUTPUT DIR}${/}screenshots
Set Global Variable ${LAB LOG} ${OUTPUT DIR}${/}lab.log
Set Global Variable ${PREVIOUS LAB LOG LENGTH} 0
${server} = Start Process ${cmd} shell=yes env:HOME=${home} cwd=${home} stdout=${LAB LOG}
... stderr=STDOUT
Set Global Variable ${SERVER} ${server}
Open JupyterLab
Set Screenshot Directory ${SCREENSHOTS DIR}

Create Notebok Server Config
[Documentation] Copies in notebook server config file and updates accordingly
${conf} = Set Variable ${NOTEBOOK DIR}${/}${NBSERVER CONF}
${extra_node_roots} = Create List ${ROOT}
${port} = Get Unused Port
Set Global Variable ${PORT} ${port}
Set Global Variable ${URL} http://localhost:${PORT}${BASE URL}
Copy File ${FIXTURES}${/}${NBSERVER CONF} ${conf}
Update Jupyter Config ${conf} LabApp
... base_url=${BASE URL}
... port=${PORT}
... token=${TOKEN}
... user_settings_dir=${SETTINGS DIR}
... workspaces_dir=${WORKSPACES DIR}
Update Jupyter Config ${conf} LanguageServerManager
... extra_node_roots=@{extra_node_roots}

Read Page Config
${script} = Get Element Attribute id:jupyter-config-data innerHTML
${config} = Evaluate __import__("json").loads("""${script}""")
Set Global Variable ${PAGE CONFIG} ${config}
Set Global Variable ${LAB VERSION} ${config["appVersion"]}

Create Lab Launch Command
[Arguments] ${root}
[Documentation] Create a JupyterLab CLI shell string, escaping for traitlets
${WORKSPACES DIR} = Set Variable ${OUTPUT DIR}${/}workspaces
${app args} = Set Variable --no-browser --debug --NotebookApp.base_url\='${BASE}' --port\=${PORT} --NotebookApp.token\='${TOKEN}'
${path args} = Set Variable --LabApp.user_settings_dir='${SETTINGS DIR.replace('\\', '\\\\')}' --LabApp.workspaces_dir\='${WORKSPACES DIR.replace('\\', '\\\\')}'
${ext args} = Set Variable --LanguageServerManager.extra_node_roots\="['${root.replace('\\', '\\\\')}']"
${cmd} = Set Variable jupyter-lab ${app args} ${path args} ${ext args}
[Return] ${cmd}

Create Notebok Server Config
[Arguments] ${home}
[Documentation] Copies in notebook server config file to disables npm/build checks
Copy File ${FIXTURES}${/}${NBSERVER CONF} ${home}${/}${NBSERVER CONF}

Setup Suite For Screenshots
[Arguments] ${folder}
Set Screenshot Directory ${OUTPUT DIR}${/}screenshots${/}${folder}
Set Screenshot Directory ${SCREENSHOTS DIR}${/}${folder}
Set Tags lab:${LAB VERSION}

Initialize User Settings
Set Suite Variable ${SETTINGS DIR} ${OUTPUT DIR}${/}user-settings children=${True}
Create File ${SETTINGS DIR}${/}@jupyterlab${/}codemirror-extension${/}commands.jupyterlab-settings {"styleActiveLine": true}
Create File
... ${SETTINGS DIR}${/}@jupyterlab${/}codemirror-extension${/}commands.jupyterlab-settings
... {"styleActiveLine": true}

Reset Plugin Settings
[Arguments] ${package}=jupyterlab-lsp ${plugin}=plugin
Expand Down Expand Up @@ -91,7 +99,7 @@ Open JupyterLab
Create WebDriver Firefox
... executable_path=${geckodriver}
... firefox_binary=${firefox}
... service_log_path=${OUTPUT DIR}${/}geckodriver.log
... service_log_path=${GECKODRIVER LOG}
... service_args=${service args}
Wait Until Keyword Succeeds 3x 5s Wait For Splash

Expand Down Expand Up @@ -221,15 +229,15 @@ Open ${file} in ${editor}

Clean Up After Working With File
[Arguments] ${file}
Remove File ${OUTPUT DIR}${/}home${/}${file}
Remove File ${NOTEBOOK DIR}${/}${file}
Reset Application State
Lab Log Should Not Contain Known Error Messages

Setup Notebook
[Arguments] ${Language} ${file} ${isolated}=${True}
Set Tags language:${Language.lower()}
Run Keyword If ${isolated} Set Screenshot Directory ${OUTPUT DIR}${/}screenshots${/}notebook${/}${TEST NAME.replace(' ', '_')}
Copy File examples${/}${file} ${OUTPUT DIR}${/}home${/}${file}
Run Keyword If ${isolated} Set Screenshot Directory ${SCREENSHOTS DIR}${/}notebook${/}${TEST NAME.replace(' ', '_')}
Copy File examples${/}${file} ${NOTEBOOK DIR}${/}${file}
Run Keyword If ${isolated} Try to Close All Tabs
Open ${file} in ${MENU NOTEBOOK}
Capture Page Screenshot 00-notebook-opened.png
Expand Down Expand Up @@ -284,13 +292,13 @@ Open Context Menu Over
Prepare File for Editing
[Arguments] ${Language} ${Screenshots} ${file}
Set Tags language:${Language.lower()}
Set Screenshot Directory ${OUTPUT DIR}${/}screenshots${/}${Screenshots}${/}${Language.lower()}
Set Screenshot Directory ${SCREENSHOTS DIR}${/}${Screenshots}${/}${Language.lower()}
Try to Close All Tabs
Open File ${file}

Open File
[Arguments] ${file}
Copy File examples${/}${file} ${OUTPUT DIR}${/}home${/}${file}
Copy File examples${/}${file} ${NOTEBOOK DIR}${/}${file}
Open ${file} in ${MENU EDITOR}
Capture Page Screenshot 00-opened.png

Expand Down
14 changes: 12 additions & 2 deletions atest/Variables.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
${FIXTURES} ${CURDIR}${/}fixtures
${NBSERVER CONF} jupyter_notebook_config.json
${SPLASH} id:jupyterlab-splash
# to help catch hard-coded paths
${BASE} /@est/
# to help catch hard-coded paths and encoding issues
${BASE URL} /@est/
${NOTEBOOK DIR NAME} nöte bòóks
# core paths
${HOME} ${OUTPUT DIR}${/}home
${LAB LOG} ${OUTPUT DIR}${/}lab.log
${GECKODRIVER LOG} ${OUTPUT DIR}${/}geckodriver.log
${SETTINGS DIR} ${OUTPUT DIR}${/}user-settings
${WORKSPACES DIR} ${OUTPUT DIR}${/}workspaces
${NOTEBOOK DIR} ${HOME}${/}${NOTEBOOK DIR NAME}
${VIRTUALDOCS DIR} ${NOTEBOOK DIR}${/}.virtual_documents
${SCREENSHOTS DIR} ${OUTPUT DIR}${/}screenshots
# override with `python scripts/atest.py --variable HEADLESS:0`
${HEADLESS} 1
${CMD PALETTE INPUT} css:#command-palette .lm-CommandPalette-input
Expand Down
17 changes: 17 additions & 0 deletions atest/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""work with jupyter config"""

import json
from pathlib import Path

ENC = dict(encoding="utf-8")


def update_jupyter_config(path, has_traits, **key_values):
"""update an existing jupyter_notebook_config.json"""
p = Path(path)
conf = json.loads(p.read_text(**ENC))

for key, value in key_values.items():
conf.setdefault(has_traits, {})[key] = value

p.write_text(json.dumps(conf, indent=2, sort_keys=True), **ENC)
4 changes: 3 additions & 1 deletion atest/fixtures/jupyter_notebook_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"buildCheck": false,
"buildAvailable": false
}
}
},
"log_level": "DEBUG",
"open_browser": false
}
}
2 changes: 1 addition & 1 deletion py_src/jupyter_lsp/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

HERE = pathlib.Path(__file__).parent
SCHEMA_FILE = HERE / "schema.json"
SCHEMA = json.loads(SCHEMA_FILE.read_text())
SCHEMA = json.loads(SCHEMA_FILE.read_text(encoding="utf-8"))
SPEC_VERSION = SCHEMA["definitions"]["current-version"]["enum"][0]


Expand Down
4 changes: 3 additions & 1 deletion py_src/jupyter_lsp/specs/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

def load_config_schema(key):
"""load a keyed filename"""
return json.loads((CONFIGS / "{}.schema.json".format(key)).read_text())
return json.loads(
(CONFIGS / "{}.schema.json".format(key)).read_text(encoding="utf-8")
)
1 change: 1 addition & 0 deletions py_src/jupyter_lsp/virtual_documents_shadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def read_lines(self):
# empty string required by the assumptions of the gluing algorithm
lines = [""]
try:
# TODO: what to do about bad encoding reads?
lines = self.path.read_text().splitlines()
except FileNotFoundError:
pass
Expand Down
1 change: 1 addition & 0 deletions scripts/atest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def get_stem(attempt, extra_args):
def atest(attempt, extra_args):
"""perform a single attempt of the acceptance tests"""

# TODO: investigate whether this is still required vs geckodriver 0.28
if "FIREFOX_BINARY" not in os.environ:
os.environ["FIREFOX_BINARY"] = shutil.which("firefox")

Expand Down
4 changes: 2 additions & 2 deletions scripts/bump_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def maybe_change_version(self, dry: bool):

def change_version(self, new_version: str, dry: bool):

changelog = CHANGELOG.read_text()
changelog = CHANGELOG.read_text(encoding="utf-8")
if new_version not in changelog:
raise Exception(
(
Expand All @@ -71,7 +71,7 @@ def change_version(self, new_version: str, dry: bool):


def replace_version(path: Path, template: str, old: str, new: str, dry: bool):
old_content = path.read_text()
old_content = path.read_text(encoding="utf-8")
new_content = old_content.replace(
template.format(version=old), template.format(version=new)
)
Expand Down
14 changes: 7 additions & 7 deletions scripts/integrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
PACKAGES = {
package["name"]: [path.parent, package]
for path, package in [
(path, json.loads(path.read_text()))
(path, json.loads(path.read_text(encoding="utf-8")))
for path in ROOT.glob("packages/*/package.json")
]
}
Expand All @@ -63,7 +63,7 @@

# CI stuff
PIPE_FILE = ROOT / ".github/workflows/job.test.yml"
PIPELINES = yaml.safe_load(PIPE_FILE.read_text())
PIPELINES = yaml.safe_load(PIPE_FILE.read_text(encoding="utf-8"))
PIPE_VARS = PIPELINES["env"]
DOCS = ROOT / "docs"

Expand All @@ -82,8 +82,8 @@ def the_meta_package():
return (
meta_path,
meta,
json.loads((meta_path / "tsconfig.json").read_text()),
(meta_path / "src" / "index.ts").read_text(),
json.loads((meta_path / "tsconfig.json").read_text(encoding="utf-8")),
(meta_path / "src" / "index.ts").read_text(encoding="utf-8"),
)


Expand Down Expand Up @@ -139,7 +139,7 @@ def test_ts_package_integrity(name, info, the_meta_package):

if schemas:
for schema in schemas:
schema_instance = json.loads(schema.read_text())
schema_instance = json.loads(schema.read_text(encoding="utf-8"))
jsonschema.validators.Draft7Validator(schema_instance)


Expand All @@ -158,7 +158,7 @@ def test_ts_package_integrity(name, info, the_meta_package):
def test_jlab_versions(path):
"""is the version of jupyterlab consistent?"""
assert (
LAB_SPEC in pathlib.Path(path).read_text().lower()
LAB_SPEC in pathlib.Path(path).read_text(encoding="utf-8").lower()
), "{} lab version is out-of-sync vs {}".format(path, LAB_SPEC)


Expand All @@ -172,7 +172,7 @@ def test_jlab_versions(path):
)
def test_changelog_versions(pkg, version):
"""are the current versions represented in the changelog?"""
assert "## `{} {}`".format(pkg, version) in CHANGELOG.read_text()
assert "## `{} {}`".format(pkg, version) in CHANGELOG.read_text(encoding="utf-8")


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion scripts/nblint.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def blacken(source):
def nblint():
for nb_path in DOCS_IPYNB:
print(".", end="", flush=True)
nb_text = nb_path.read_text()
nb_text = nb_path.read_text(encoding="utf-8")
nb_node = nbformat.reads(nb_text, 4)
changes = 0
has_empty = 0
Expand Down
2 changes: 1 addition & 1 deletion scripts/tectonic_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def tectonic_cache():
"\n".join(
[
line
for line in EXAMPLE.read_text().splitlines()
for line in EXAMPLE.read_text(encoding="utf-8").splitlines()
if "\\foo" not in line
]
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
setuptools.setup(
version=re.findall(
r"""__version__ = "([^"]+)"$""",
(Path(__file__).parent / "py_src" / "jupyter_lsp" / "_version.py").read_text(),
(Path(__file__).parent / "py_src" / "jupyter_lsp" / "_version.py").read_text(encoding="utf-8"),
)[0],
setup_requires=["pytest-runner"] if "test" in sys.argv else [],
# py35 apparently doesn't support putting these in setup.cfg
Expand Down
2 changes: 1 addition & 1 deletion versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


_VERSION_PY = ROOT / "py_src" / "jupyter_lsp" / "_version.py"
JUPYTER_LSP_VERSION = findall(r'= "(.*)"$', (_VERSION_PY).read_text())[0]
JUPYTER_LSP_VERSION = findall(r'= "(.*)"$', (_VERSION_PY).read_text(encoding="utf-8"))[0]

with open(ROOT / "packages/jupyterlab-lsp/package.json") as f:
jupyterlab_lsp_package = json.load(f)
Expand Down