Skip to content

Commit

Permalink
[ADD] godoo source get: stub downloading for odoo IDE extension
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkreud committed Jul 17, 2023
1 parent b942f33 commit cfa75fd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import
pyrightconfig.json
config/odoo.conf
*.pass
*.nogit.*
Expand Down
3 changes: 3 additions & 0 deletions odoo_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
odoo:
url: https://github.com/odoo/odoo/
branch: 16.0 # Branch is mandatory on Odoo Repo but not on OCA Repos
stubs: # This will all becomme uneccessary, when the vscode extension includes the stubs in the extension.
url: https://github.com/odoo-ide/odoo-stubs.git
pyright_conf: pyrightconfig.json # Autogenerate pyrightconfig.json with stubs path
# In the thirdparty section we can add more Repos to download.
# This can also be an ssh style Url for Odoo Enterprise for example.
thirdparty:
Expand Down
44 changes: 44 additions & 0 deletions src/godoo_cli/git/git_odoo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
from pathlib import Path

Expand Down Expand Up @@ -26,6 +27,9 @@ def git_ensure_odoo_repo(
odoo_url = odoo_data["url"]
odoo_branch = odoo_data.get("branch", "master")
odoo_commit = odoo_data.get("commit", "")

download_stubs(target_folder, force_fetch, download_archive, odoo_data, odoo_branch)

if add_compare_comment:
yaml_add_compare_commit(odoo_data, odoo_branch)
else:
Expand All @@ -43,3 +47,43 @@ def git_ensure_odoo_repo(
)

yaml.dump(git_repos, manifest_file)


def download_stubs(
target_folder: Path,
force_fetch: bool,
download_archive: bool,
odoo_data,
odoo_branch: str,
):
"""Download Odoo stubs for https://github.com/odoo-ide/vscode-odoo
Hopefully this Method will become obsolete in the future, when the vscode-odoo extension includes stubs in the extension itself.
Parameters
----------
target_folder : Path
Stubs will be downloaded to target_folder.parent/odoo-stubs
force_fetch : bool
passed down to git_ensure_repo
download_archive : bool
passed down to git_ensure_repo
odoo_data : Dict
odoo_data from manifest.yml
odoo_branch : str
branch to download stubs from
"""
odoo_stubs = odoo_data.get("stubs")
if odoo_stubs:
stub_target_path = target_folder.parent / "odoo-stubs"
git_ensure_repo(
target_folder=stub_target_path,
repo_src=odoo_stubs["url"],
branch=odoo_branch,
pull=force_fetch,
zip_mode=download_archive,
filter="blob:none",
single_branch=True,
)
if pyright_path := odoo_stubs.get("pyright_conf"):
json.dump({"stubPath": str(stub_target_path.absolute())}, Path(pyright_path).open("w"))

0 comments on commit cfa75fd

Please sign in to comment.