Skip to content

Commit 478c93a

Browse files
committed
refactor: introduce bundled/libs/tool folders and move python source 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
1 parent c464edc commit 478c93a

File tree

131 files changed

+310
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+310
-123
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,6 @@ report.html
290290
.robotcode_cache/
291291

292292
# ruff
293-
.ruff_cache/
293+
.ruff_cache/
294+
295+
bundled/libs

Diff for: .vscodeignore

+3
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ doc
5454

5555
.pre-commit-config.yaml
5656
.devcontainer
57+
58+
src
59+
bundled/libs/bin

Diff for: bundled/tool/check_robot_version.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import pathlib
3+
import site
4+
import sys
5+
6+
7+
def update_sys_path(path_to_add: str, strategy: str) -> None:
8+
if path_to_add not in sys.path and pathlib.Path(path_to_add).is_dir():
9+
if any(p for p in pathlib.Path(path_to_add).iterdir() if p.suffix == ".pth"):
10+
site.addsitedir(path_to_add)
11+
return
12+
13+
if strategy == "useBundled":
14+
sys.path.insert(0, path_to_add)
15+
elif strategy == "fromEnvironment":
16+
sys.path.append(path_to_add)
17+
18+
19+
if __name__ == "__main__":
20+
# Ensure that we can import LSP libraries, and other bundled libraries.
21+
update_sys_path(
22+
os.fspath(pathlib.Path(__file__).parent.parent / "libs"),
23+
os.getenv("LS_IMPORT_STRATEGY", "useBundled"),
24+
)
25+
26+
# Run the language server.
27+
from robotcode.language_server.robotframework.utils.version import get_robot_version
28+
29+
print(get_robot_version() >= (4, 0))
File renamed without changes.
File renamed without changes.

Diff for: bundled/tool/debugger/launcher/__main__.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
import pathlib
3+
import site
4+
import sys
5+
6+
7+
def update_sys_path(path_to_add: str, strategy: str) -> None:
8+
if path_to_add not in sys.path and pathlib.Path(path_to_add).is_dir():
9+
if any(p for p in pathlib.Path(path_to_add).iterdir() if p.suffix == ".pth"):
10+
site.addsitedir(path_to_add)
11+
return
12+
13+
if strategy == "useBundled":
14+
sys.path.insert(0, path_to_add)
15+
elif strategy == "fromEnvironment":
16+
sys.path.append(path_to_add)
17+
18+
19+
if __name__ == "__main__":
20+
# Ensure that we can import LSP libraries, and other bundled libraries.
21+
update_sys_path(
22+
os.fspath(pathlib.Path(__file__).parent.parent.parent.parent / "libs"),
23+
os.getenv("LS_IMPORT_STRATEGY", "useBundled"),
24+
)
25+
26+
from robotcode.debugger.launcher.cli import main
27+
28+
main()
File renamed without changes.

Diff for: bundled/tool/language_server/__main__.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import pathlib
3+
import site
4+
import sys
5+
6+
7+
def update_sys_path(path_to_add: str, strategy: str) -> None:
8+
if path_to_add not in sys.path and pathlib.Path(path_to_add).is_dir():
9+
if any(p for p in pathlib.Path(path_to_add).iterdir() if p.suffix == ".pth"):
10+
site.addsitedir(path_to_add)
11+
return
12+
13+
if strategy == "useBundled":
14+
sys.path.insert(0, path_to_add)
15+
elif strategy == "fromEnvironment":
16+
sys.path.append(path_to_add)
17+
18+
19+
if __name__ == "__main__":
20+
# Ensure that we can import LSP libraries, and other bundled libraries.
21+
update_sys_path(
22+
os.fspath(pathlib.Path(__file__).parent.parent.parent / "libs"),
23+
os.getenv("LS_IMPORT_STRATEGY", "useBundled"),
24+
)
25+
26+
# Run the language server.
27+
from robotcode.language_server.cli import main
28+
29+
main()

Diff for: pyproject.toml

+9-35
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ rest = ["docutils"]
7272

7373

7474
[tool.hatch.version]
75-
path = "robotcode/__version__.py"
75+
path = "src/robotcode/__version__.py"
7676

7777

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

8181

8282
[tool.hatch.envs.default]
@@ -177,19 +177,10 @@ build_command = "pip install hatch && hatch build"
177177
[tool.black]
178178
line-length = 120
179179
target-version = ['py38']
180-
exclude = '''
180+
extend-exclude = '''
181181
(
182182
/(
183-
\.eggs # exclude a few common directories in the
184-
| \.git # root of the project
185-
| \.mypy_cache
186-
| \.tox
187-
| \.venv
188-
| \.hatch
189-
| build
190-
| dist
191-
| out
192-
| playground
183+
| bundled/libs
193184
)/
194185
)
195186
'''
@@ -225,27 +216,9 @@ fail_under = 40
225216
[tool.ruff]
226217
line-length = 120
227218
target-version = "py38"
228-
exclude = [
229-
".bzr",
230-
".direnv",
231-
".eggs",
232-
".git",
233-
".hg",
234-
".mypy_cache",
235-
".nox",
236-
".pants.d",
237-
".ruff_cache",
238-
".svn",
239-
".tox",
240-
".venv",
241-
"__pypackages__",
242-
"_build",
243-
"buck-out",
244-
"build",
245-
"dist",
246-
"node_modules",
247-
"venv",
248-
".hatch",
219+
src = ["src"]
220+
extend-exclude = [
221+
"bundled/libs",
249222
]
250223
ignore = ["E741", "N805", "N999"]
251224
select = [
@@ -295,7 +268,7 @@ select = [
295268

296269
[tool.mypy]
297270
python_version = 3.8
298-
271+
pretty = true
299272
strict = true
300273
warn_redundant_casts = true
301274
warn_unused_ignores = true
@@ -314,6 +287,7 @@ exclude = [
314287
"out",
315288
"playground",
316289
"scripts",
290+
"bundled/libs",
317291
]
318292

319293

Diff for: robotcode/analyzer/__main__.py

-31
This file was deleted.

Diff for: scripts/devel.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import shutil
2+
from pathlib import Path
3+
from subprocess import run
4+
5+
6+
def main() -> None:
7+
dist_path = Path("./dist")
8+
if not dist_path.exists():
9+
dist_path.mkdir()
10+
11+
shutil.rmtree("./bundled/libs", ignore_errors=True)
12+
13+
run(
14+
"pip install -U -t ./bundled/libs --no-cache-dir --implementation py --no-deps -e .", shell=True
15+
).check_returncode()
16+
17+
18+
if __name__ == "__main__":
19+
main()

Diff for: scripts/package.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import shutil
23
import sys
34
from pathlib import Path
45
from subprocess import run
@@ -26,6 +27,12 @@ def main() -> None:
2627

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

30+
shutil.rmtree("./bundled/libs", ignore_errors=True)
31+
32+
run(
33+
"pip install -U -t ./bundled/libs --no-cache-dir --implementation py --no-deps .", shell=True
34+
).check_returncode()
35+
2936
run(
3037
f"npx vsce package {'--pre-release' if get_version().prerelease else ''} -o ./dist", shell=True
3138
).check_returncode()

Diff for: scripts/update_git_versions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def replace_in_file(filename: Path, pattern: "re.Pattern[str]", to: str) -> None
2828
def main() -> None:
2929
version = get_version()
3030

31-
for f in ["robotcode/__version__.py"]:
31+
for f in ["src/robotcode/__version__.py"]:
3232
replace_in_file(
3333
Path(f),
3434
re.compile(r"""(^_*version_*\s*=\s*['"])([^'"]*)(['"])""", re.MULTILINE),

Diff for: scripts/update_versions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main() -> None:
1616

1717
preview = version.minor % 2 != 0
1818

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

0 commit comments

Comments
 (0)