-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
232 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
.idea | ||
*.iml | ||
*.pyc | ||
*.pyc | ||
.pytest_cache | ||
*.egg-info | ||
tests/**/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
import pytest | ||
from databricks.sdk.service.workspace import ImportFormat | ||
|
||
from pathlib import Path | ||
from typing import Optional | ||
|
||
|
||
def find_dir_with_leaf(folder: Path, leaf: str) -> Optional[Path]: | ||
root = folder.root | ||
while str(folder.absolute()) != root: | ||
if (folder / leaf).exists(): | ||
return folder | ||
folder = folder.parent | ||
return None | ||
|
||
|
||
def find_project_root(folder: Path) -> Optional[Path]: | ||
for leaf in ['pyproject.toml', 'setup.py']: | ||
root = find_dir_with_leaf(folder, leaf) | ||
if root is not None: | ||
return root | ||
return None | ||
|
||
|
||
def build_wheel_in(project_path: Path, out_path: Path) -> Path: | ||
try: | ||
subprocess.run( | ||
[sys.executable, "-m", "build", "--wheel", "--outdir", | ||
out_path.absolute(), project_path.absolute()], | ||
capture_output=True, | ||
check=True, | ||
) | ||
except subprocess.CalledProcessError as e: | ||
if e.stderr is not None: | ||
sys.stderr.write(e.stderr.decode()) | ||
raise RuntimeError(e.output.decode().strip()) from None | ||
|
||
found_wheels = list(out_path.glob(f"*.whl")) | ||
if not found_wheels: | ||
msg = f"cannot find *.whl in {out_path}" | ||
raise RuntimeError(msg) | ||
if len(found_wheels) > 1: | ||
conflicts = ", ".join(str(whl) for whl in found_wheels) | ||
msg = f"more than one wheel match: {conflicts}" | ||
raise RuntimeError(msg) | ||
wheel_file = found_wheels[0] | ||
|
||
return wheel_file | ||
|
||
|
||
@pytest.fixture | ||
def fresh_local_wheel_file(tmp_path) -> Path: | ||
project_root = find_project_root(Path(os.getcwd())) | ||
build_root = tmp_path / fresh_local_wheel_file.__name__ | ||
shutil.copytree(project_root, build_root) | ||
|
||
return build_wheel_in(build_root, tmp_path / 'dist') | ||
|
||
|
||
@pytest.fixture | ||
def workspace_library(ws, fresh_local_wheel_file, make_random): | ||
my_user = ws.current_user.me().user_name | ||
workspace_folder = f"/Users/{my_user}/wheels/{make_random(10)}" | ||
ws.workspace.mkdirs(workspace_folder) | ||
|
||
wheel_path = f"{workspace_folder}/{fresh_local_wheel_file.name}" | ||
with fresh_local_wheel_file.open("rb") as f: | ||
ws.workspace.upload(wheel_path, f, format=ImportFormat.AUTO) | ||
|
||
yield f'/Workspace/{wheel_path}' | ||
|
||
ws.workspace.delete(workspace_folder, recursive=True) |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "hatchling-whl" | ||
dynamic = ["version"] | ||
description = 'dummy' | ||
requires-python = ">=3.7" | ||
license = "MIT" | ||
keywords = [] | ||
authors = [ | ||
{ name = "Jonh Doe", email = "john@example.com" }, | ||
] | ||
dependencies = [] | ||
|
||
[tool.hatch.version] | ||
path = "src/hatchling_whl/__about__.py" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def main(): | ||
print('it works') | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def main(): | ||
print('it works') | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[tool.poetry] | ||
name = "poetry_whl" | ||
version = "0.0.1" | ||
description = "dummy project" | ||
authors = ["John Doe <john@example.com>"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.11" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import io | ||
import pathlib | ||
|
||
from setuptools import setup, find_packages | ||
|
||
setup(name="setuppy-whl", | ||
version="0.0.1", | ||
packages=find_packages(exclude=["tests", "*tests.*", "*tests"]), | ||
python_requires=">=3.7", | ||
author="John Doe", | ||
author_email="john@example.com") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def main(): | ||
print('it works') | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[build-system] | ||
requires = ["setuptools>=61.0"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "setuptools-whl" | ||
version = "0.0.1" | ||
description = "dummy" | ||
|
||
[tool.distutils.bdist_wheel] | ||
universal = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def main(): | ||
print('it works') | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from databricks.labs.pytester.fixtures.wheel import build_wheel_in, find_dir_with_leaf, fresh_local_wheel_file, workspace_library | ||
|
||
__folder__ = Path(__file__).parent | ||
|
||
|
||
def test_find_dir_with_leaf(): | ||
x = find_dir_with_leaf(Path(__file__), '.gitignore') | ||
assert x is not None | ||
|
||
|
||
def test_find_dir_with_leaf_missing(): | ||
x = find_dir_with_leaf(Path(__file__), '.nothing') | ||
assert x is None | ||
|
||
|
||
@pytest.mark.parametrize("build_system", ['hatchling', 'poetry', 'setuppy', 'setuptools']) | ||
def test_building_wheels(tmp_path, build_system): | ||
whl = build_wheel_in(__folder__ / f'resources/{build_system}-whl', tmp_path) | ||
assert whl.exists() | ||
|
||
|
||
def test_fresh_wheel_file(fresh_local_wheel_file): | ||
assert fresh_local_wheel_file is not None |