Skip to content

Commit

Permalink
refactor: introduce bundled/libs/tool folders and move python source …
Browse files Browse the repository at this point in the history
…to src folder

this is to prepare the splitting of one big python package to several smaller packages, i.e. to install the robotcode.debugger standalone without other dependencies
  • Loading branch information
d-biehl committed Feb 27, 2023
1 parent c464edc commit 478c93a
Show file tree
Hide file tree
Showing 131 changed files with 310 additions and 123 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,6 @@ report.html
.robotcode_cache/

# ruff
.ruff_cache/
.ruff_cache/

bundled/libs
3 changes: 3 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ doc

.pre-commit-config.yaml
.devcontainer

src
bundled/libs/bin
29 changes: 29 additions & 0 deletions bundled/tool/check_robot_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import pathlib
import site
import sys


def update_sys_path(path_to_add: str, strategy: str) -> None:
if path_to_add not in sys.path and pathlib.Path(path_to_add).is_dir():
if any(p for p in pathlib.Path(path_to_add).iterdir() if p.suffix == ".pth"):
site.addsitedir(path_to_add)
return

if strategy == "useBundled":
sys.path.insert(0, path_to_add)
elif strategy == "fromEnvironment":
sys.path.append(path_to_add)


if __name__ == "__main__":
# Ensure that we can import LSP libraries, and other bundled libraries.
update_sys_path(
os.fspath(pathlib.Path(__file__).parent.parent / "libs"),
os.getenv("LS_IMPORT_STRATEGY", "useBundled"),
)

# Run the language server.
from robotcode.language_server.robotframework.utils.version import get_robot_version

print(get_robot_version() >= (4, 0))
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions bundled/tool/debugger/launcher/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import pathlib
import site
import sys


def update_sys_path(path_to_add: str, strategy: str) -> None:
if path_to_add not in sys.path and pathlib.Path(path_to_add).is_dir():
if any(p for p in pathlib.Path(path_to_add).iterdir() if p.suffix == ".pth"):
site.addsitedir(path_to_add)
return

if strategy == "useBundled":
sys.path.insert(0, path_to_add)
elif strategy == "fromEnvironment":
sys.path.append(path_to_add)


if __name__ == "__main__":
# Ensure that we can import LSP libraries, and other bundled libraries.
update_sys_path(
os.fspath(pathlib.Path(__file__).parent.parent.parent.parent / "libs"),
os.getenv("LS_IMPORT_STRATEGY", "useBundled"),
)

from robotcode.debugger.launcher.cli import main

main()
File renamed without changes.
29 changes: 29 additions & 0 deletions bundled/tool/language_server/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import pathlib
import site
import sys


def update_sys_path(path_to_add: str, strategy: str) -> None:
if path_to_add not in sys.path and pathlib.Path(path_to_add).is_dir():
if any(p for p in pathlib.Path(path_to_add).iterdir() if p.suffix == ".pth"):
site.addsitedir(path_to_add)
return

if strategy == "useBundled":
sys.path.insert(0, path_to_add)
elif strategy == "fromEnvironment":
sys.path.append(path_to_add)


if __name__ == "__main__":
# Ensure that we can import LSP libraries, and other bundled libraries.
update_sys_path(
os.fspath(pathlib.Path(__file__).parent.parent.parent / "libs"),
os.getenv("LS_IMPORT_STRATEGY", "useBundled"),
)

# Run the language server.
from robotcode.language_server.cli import main

main()
44 changes: 9 additions & 35 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ rest = ["docutils"]


[tool.hatch.version]
path = "robotcode/__version__.py"
path = "src/robotcode/__version__.py"


[tool.hatch.build.targets.sdist]
only-include = ["robotcode", "CHANGELOG.md"]
only-include = ["src", "CHANGELOG.md"]


[tool.hatch.envs.default]
Expand Down Expand Up @@ -177,19 +177,10 @@ build_command = "pip install hatch && hatch build"
[tool.black]
line-length = 120
target-version = ['py38']
exclude = '''
extend-exclude = '''
(
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.mypy_cache
| \.tox
| \.venv
| \.hatch
| build
| dist
| out
| playground
| bundled/libs
)/
)
'''
Expand Down Expand Up @@ -225,27 +216,9 @@ fail_under = 40
[tool.ruff]
line-length = 120
target-version = "py38"
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
".hatch",
src = ["src"]
extend-exclude = [
"bundled/libs",
]
ignore = ["E741", "N805", "N999"]
select = [
Expand Down Expand Up @@ -295,7 +268,7 @@ select = [

[tool.mypy]
python_version = 3.8

pretty = true
strict = true
warn_redundant_casts = true
warn_unused_ignores = true
Expand All @@ -314,6 +287,7 @@ exclude = [
"out",
"playground",
"scripts",
"bundled/libs",
]


Expand Down
31 changes: 0 additions & 31 deletions robotcode/analyzer/__main__.py

This file was deleted.

19 changes: 19 additions & 0 deletions scripts/devel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import shutil
from pathlib import Path
from subprocess import run


def main() -> None:
dist_path = Path("./dist")
if not dist_path.exists():
dist_path.mkdir()

shutil.rmtree("./bundled/libs", ignore_errors=True)

run(
"pip install -U -t ./bundled/libs --no-cache-dir --implementation py --no-deps -e .", shell=True
).check_returncode()


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions scripts/package.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
import shutil
import sys
from pathlib import Path
from subprocess import run
Expand Down Expand Up @@ -26,6 +27,12 @@ def main() -> None:

run("hatch -e build build", shell=True).check_returncode()

shutil.rmtree("./bundled/libs", ignore_errors=True)

run(
"pip install -U -t ./bundled/libs --no-cache-dir --implementation py --no-deps .", shell=True
).check_returncode()

run(
f"npx vsce package {'--pre-release' if get_version().prerelease else ''} -o ./dist", shell=True
).check_returncode()
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_git_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def replace_in_file(filename: Path, pattern: "re.Pattern[str]", to: str) -> None
def main() -> None:
version = get_version()

for f in ["robotcode/__version__.py"]:
for f in ["src/robotcode/__version__.py"]:
replace_in_file(
Path(f),
re.compile(r"""(^_*version_*\s*=\s*['"])([^'"]*)(['"])""", re.MULTILINE),
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main() -> None:

preview = version.minor % 2 != 0

for f in ["robotcode/__version__.py", "pyproject.toml"]:
for f in ["src/robotcode/__version__.py", "pyproject.toml"]:
replace_in_file(
Path(f),
re.compile(r"""(^_*version_*\s*=\s*['"])([^'"]*)(['"])""", re.MULTILINE),
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 478c93a

Please sign in to comment.