Skip to content

Commit

Permalink
feat: upgrade wrgl version
Browse files Browse the repository at this point in the history
  • Loading branch information
pckhoi committed Mar 29, 2022
1 parent b3b26c9 commit 4a88659
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 63 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -3,4 +3,6 @@ __pycache__
build
dist
*.pyc
*.egg-info
*.egg-info

_build
3 changes: 2 additions & 1 deletion .vscode/settings.json
Expand Up @@ -10,5 +10,6 @@
"# Copyright © 2021 Wrangle Ltd"
]
}
}
},
"esbonio.sphinx.confDir": "${workspaceFolder}/doc"
}
2 changes: 1 addition & 1 deletion doc/conf.py
Expand Up @@ -22,7 +22,7 @@
author = 'Khoi Pham'

# The full version, including alpha/beta/rc tags
release = '0.9.0'
release = '0.10.2'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = wrgl
version = 0.9.0
version = 0.10.2
author = Khoi Pham
author_email = pckhoi@gmail.com
description = Data matching utilities
Expand Down
17 changes: 0 additions & 17 deletions wrgl/repository.py
Expand Up @@ -91,23 +91,6 @@ def _post_json(self, path, obj):
r.raise_for_status()
return r

def get_config(self) -> Config:
"""Get configurations
:rtype: Config
"""
r = self._get("/config/")
return json_loads(r.content, Config)

def put_config(self, config: Config) -> None:
"""Updates configurations
:param Config config: the entire configurations
"""
if not isinstance(config, Config):
raise TypeError('config argument must be instance of %s' % Config)
self._put_json("/config/", config)

def get_refs(self) -> dict:
"""Get references as a mapping of reference name and commit checksum
Expand Down
76 changes: 34 additions & 42 deletions wrgl/repository_test.py
Expand Up @@ -40,13 +40,16 @@ def download_wrgl(version):
OS = platform.system().lower()
if not ver_dir.exists():
ver_dir.mkdir(parents=True)
url = "https://github.com/wrgl/wrgl/releases/download/v%s/wrgl-%s-amd64.tar.gz" % (
version, OS
)
with requests.get(url, stream=True) as r:
with tarfile.open(mode='r:gz', fileobj=r.raw) as tar:
tar.extractall(ver_dir)
return ver_dir / ('wrgl-%s-amd64' % OS) / 'bin'
for url in [
"https://github.com/wrgl/wrgl/releases/download/v%s/wrgl-%s-amd64.tar.gz" % (
version, OS
), "https://github.com/wrgl/wrgl/releases/download/v%s/wrgld-%s-amd64.tar.gz" % (
version, OS
)]:
with requests.get(url, stream=True) as r:
with tarfile.open(mode='r:gz', fileobj=r.raw) as tar:
tar.extractall(ver_dir)
return ver_dir / ('wrgl-%s-amd64' % OS) / 'bin' / 'wrgl', ver_dir / ('wrgld-%s-amd64' % OS) / 'bin' / 'wrgld'


def get_open_port():
Expand All @@ -64,23 +67,29 @@ class RepositoryTestCase(TestCase):
@classmethod
def setUpClass(cls):
cls.version = read_version()
cls.bin_dir = download_wrgl(cls.version)
cls.wrgl_bin, cls.wrgld_bin = download_wrgl(cls.version)

def wrgl(self, *args):
def wrgl(self, args, print_result=False):
try:
result = subprocess.run(
[self.bin_dir / 'wrgl']+list(args)+["--wrgl-dir", self.repo_dir.name], check=True)
[str(self.wrgl_bin)]+list(args) +
["--wrgl-dir", self.repo_dir.name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True)
except subprocess.CalledProcessError as e:
print(e.stdout)
print(e.stderr)
raise
raise Exception("%s: %s\n stdout: %s\n stderr: %s" %
(type(e).__name__, e.args, e.stdout, e.stderr))
if print_result:
print("%s\n stdout: %s\n stderr: %s" %
(" ".join(result.args), result.stdout, result.stderr))
return result

@contextmanager
def run_wrgld(self) -> typing.Iterator[str]:
port = get_open_port()
proc = subprocess.Popen(
[self.bin_dir / 'wrgld', self.repo_dir.name, "-p", port], stdout=subprocess.PIPE)
[str(self.wrgld_bin), self.repo_dir.name, "-p", port], stdout=subprocess.PIPE)
time.sleep(1)
yield "http://localhost:%s" % port
proc.stdout.close()
Expand All @@ -90,25 +99,28 @@ def run_wrgld(self) -> typing.Iterator[str]:
def setUp(self):
super().setUp()
self.repo_dir = tempfile.TemporaryDirectory()
self.wrgl("init")
self.wrgl(["init"])
self.email = "johndoe@domain.com"
self.name = "John Doe"
self.password = "password"
self.wrgl(
"config", "set", "receive.denyNonFastForwards", "true"
["config", "set", "receive.denyNonFastForwards", "true"]
)
self.wrgl(
"config", "set", "user.email", self.email
["config", "set", "user.email", self.email]
)
self.wrgl(
"config", "set", "user.name", self.name
["config", "set", "user.name", self.name]
)
self.wrgl(
"auth", "add-user", self.email, "--name", self.name, "--password", self.password
["auth", "add-user", self.email, "--name",
self.name, "--password", self.password]
)
self.wrgl(
"auth", "add-scope", self.email, "--all"
["auth", "add-scope", self.email, "--all"]
)
self.wrgl(["config", "set", "auth.type", "legacy"])
self.wrgl(["config", "get", "auth.type"], print_result=True)

def tearDown(self) -> None:
self.repo_dir.cleanup()
Expand All @@ -121,7 +133,8 @@ def commit(self, branch: str, message: str, primary_key: typing.List[str]) -> ty
yield writer
try:
self.wrgl(
"commit", branch, f.name, message, "-p", ",".join(primary_key)
["commit", branch, f.name, message,
"-p", ",".join(primary_key)]
)
finally:
os.remove(f.name)
Expand All @@ -135,27 +148,6 @@ def test_commit(self):
with self.run_wrgld() as url:
repo = Repository(url)
repo.authenticate(self.email, self.password)
cfg = repo.get_config()
self.assertEqual(cfg, Config(
receive=Receive(deny_non_fast_forwards=True),
user=User(
name=self.name,
email=self.email
)
))
cfg.receive.deny_deletes = True
repo.put_config(cfg)
cfg = repo.get_config()
self.assertEqual(cfg, Config(
receive=Receive(
deny_non_fast_forwards=True,
deny_deletes=True
),
user=User(
name=self.name,
email=self.email
)
))

refs = repo.get_refs()
self.assertEqual(len(refs), 1)
Expand Down

0 comments on commit 4a88659

Please sign in to comment.