Skip to content

Commit

Permalink
feat: get-app ln -s
Browse files Browse the repository at this point in the history
  • Loading branch information
dj12djdjs committed Jun 3, 2022
1 parent 593c7b7 commit e69b612
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 14 additions & 3 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from urllib.parse import urlparse
import os

from markupsafe import soft_str

# imports - third party imports
import click
from git import Repo
Expand Down Expand Up @@ -158,8 +160,9 @@ def get_ssh_url(self):

@functools.lru_cache(maxsize=None)
class App(AppMeta):
def __init__(self, name: str, branch: str = None, bench: "Bench" = None, *args, **kwargs):
def __init__(self, name: str, branch: str = None, bench: "Bench" = None, soft_link : bool = False, *args, **kwargs):
self.bench = bench
self.soft_link = soft_link
self.required_by = None
self.local_resolution = []
super().__init__(name, branch, *args, **kwargs)
Expand All @@ -169,12 +172,19 @@ def get(self):
branch = f"--branch {self.tag}" if self.tag else ""
shallow = "--depth 1" if self.bench.shallow_clone else ""

if not self.soft_link:
cmd = "git clone"
args = f"{self.url} {branch} {shallow} --origin upstream"
else:
cmd = "ln -s"
args = f"{self.name}"

fetch_txt = f"Getting {self.repo}"
click.secho(fetch_txt, fg="yellow")
logger.log(fetch_txt)

self.bench.run(
f"git clone {self.url} {branch} {shallow} --origin upstream",
f"{cmd} {args}",
cwd=os.path.join(self.bench.name, "apps"),
)

Expand Down Expand Up @@ -338,6 +348,7 @@ def get_app(
skip_assets=False,
verbose=False,
overwrite=False,
soft_link=False,
init_bench=False,
resolve_deps=False,
):
Expand All @@ -354,7 +365,7 @@ def get_app(
from bench.utils.app import check_existing_dir

bench = Bench(bench_path)
app = App(git_url, branch=branch, bench=bench)
app = App(git_url, branch=branch, bench=bench, soft_link=soft_link)
git_url = app.url
repo_name = app.repo
branch = app.tag
Expand Down
3 changes: 3 additions & 0 deletions bench/commands/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def drop(path):
@click.option("--branch", default=None, help="branch to checkout")
@click.option("--overwrite", is_flag=True, default=False)
@click.option("--skip-assets", is_flag=True, default=False, help="Do not build assets")
@click.option("--soft-link", is_flag=True, default=False, help="Create a soft link to git repo instead of clone.")
@click.option(
"--init-bench", is_flag=True, default=False, help="Initialize Bench if not in one"
)
Expand All @@ -145,6 +146,7 @@ def get_app(
name=None,
overwrite=False,
skip_assets=False,
soft_link=False,
init_bench=False,
resolve_deps=False,
):
Expand All @@ -156,6 +158,7 @@ def get_app(
branch=branch,
skip_assets=skip_assets,
overwrite=overwrite,
soft_link=soft_link,
init_bench=init_bench,
resolve_deps=resolve_deps,
)
Expand Down

0 comments on commit e69b612

Please sign in to comment.