Skip to content

added mac and windows runner to ci #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
68 changes: 57 additions & 11 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ on:

jobs:

test_empack:
runs-on: ubuntu-latest
env:
TARGET_PLATFORM: emscripten-32
GITHUB_OWNER: "emscripten-forge"
test_empack_unix:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]

env:
TARGET_PLATFORM: emscripten-32
GITHUB_OWNER: "emscripten-forge"

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
with:
access_token: ${{ github.token }}

- name: Checkout repo
uses: actions/checkout@v2
Expand All @@ -48,7 +47,7 @@ jobs:
- name: Install pyjs-code-runner
shell: bash -l {0}
run: |
python -m pip install git+https://github.com/DerThorsten/pyjs-code-runner@relocate_env --no-deps --ignore-installed
python -m pip install git+https://github.com/emscripten-forge/pyjs-code-runner@main --no-deps --ignore-installed

- name: Run pytest
shell: bash -l {0}
Expand All @@ -59,4 +58,51 @@ jobs:
shell: bash -l {0}
run: |
empack --help
empack pack --help
empack pack --help

test_empack_windows:

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [windows-2022]

steps:
- uses: actions/checkout@v2

- name: Install mamba and dependencies
uses: mamba-org/provision-with-micromamba@main
with:
environment-file: ci_env.yml
environment-name: ci-env
micromamba-version: '1.4.1'



- name: Install empack
shell: powershell
run: |
python -m pip install .

- name: Install Playwright
shell: powershell
run: |
playwright install

- name: Install pyjs-code-runner
shell: powershell
run: |
python -m pip install git+https://github.com/emscripten-forge/pyjs-code-runner@main --no-deps --ignore-installed

- name: Run pytest
shell: powershell
run: |
python -m pytest -v -s tests/

- name: Run cli from terminal
shell: powershell
run: |
empack pack --help

6 changes: 6 additions & 0 deletions empack/micromamba_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ def create_environment(prefix, channels=None, packages=None, platform=None, no_d
extra_kwargs["stdout"] = subprocess.DEVNULL
subprocess.run(micromamba_command, check=True, **extra_kwargs)
except subprocess.CalledProcessError as e:
# run again but without supressing stdout
if supress_stdout:
# add --log-level=debug
micromamba_command += ["--log-level=trace"]
subprocess.run(micromamba_command, check=True)

raise Exception(f"Error: Micromamba command failed with return code {e.returncode}") from e
43 changes: 27 additions & 16 deletions empack/pack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .micromamba_wrapper import create_environment
from .filter_env import filter_pkg, filter_env, iterate_env_pkg_meta
from tempfile import TemporaryDirectory
from pathlib import Path, PosixPath
from pathlib import Path
import tarfile
import os.path
import json
Expand All @@ -18,7 +18,6 @@
PACKED_PACKAGES_CACHE_DIR.mkdir(parents=True, exist_ok=True)
DEFAULT_CONFIG_PATH = Path(sys.prefix) / "share" / "empack" / "empack_config.yaml"


def filename_base_from_meta(pkg_meta):
name = pkg_meta["name"]
version = pkg_meta["version"]
Expand Down Expand Up @@ -206,15 +205,19 @@ def pack_directory(
else:
output_filename = outname

mount_dir = PosixPath(mount_dir)
if not mount_dir.is_absolute() or mount_dir.parts[0] != "/":
mount_dir = str(mount_dir)
if not mount_dir.startswith("/"):
raise RuntimeError(
f'mount_dir must be an absolute path starting with "/" eg "/usr/local" or "/foo/bar" but is: {mount_dir}'
)

# remove first part from mount_dir
mount_dir = PosixPath(*mount_dir.parts[1:])
assert mount_dir.is_absolute() == False
# remove the "/" at the beginning
if mount_dir == "/":
mount_dir = mount_dir[1:]

# remove the "/" at the end
if mount_dir.endswith("/"):
mount_dir = mount_dir[:-1]

# iterate over all files in host_dir and store in list
filenames = []
Expand All @@ -224,10 +227,10 @@ def pack_directory(
abs_path = os.path.join(root, file)
rel_path = os.path.relpath(abs_path, host_dir)
filenames.append(os.path.join(root, file))
if mount_dir == PosixPath("."):
if mount_dir == "":
arcnames.append(rel_path)
else:
arcnames.append(os.path.join(mount_dir, rel_path))
arcnames.append(f"{mount_dir}/{rel_path}")

save_as_tarfile(
output_filename=output_filename,
Expand All @@ -250,8 +253,8 @@ def pack_file(
if not host_file.is_file():
raise RuntimeError(f"File {host_file} is not a file")

mount_dir = PosixPath(mount_dir)
if not mount_dir.is_absolute() or mount_dir.parts[0] != "/":
mount_dir = str(mount_dir)
if not mount_dir.startswith("/"):
raise RuntimeError(
'mount_dir must be an absolute path starting with "/" eg "/usr/local" or "/foo/bar"'
)
Expand All @@ -261,14 +264,22 @@ def pack_file(
else:
output_filename = outname

# remove first part from mount_dir
mount_dir = PosixPath(*mount_dir.parts[1:])
assert mount_dir.is_absolute() == False

# remove the "/" at the beginning
if mount_dir == "/":
mount_dir = mount_dir[1:]

if mount_dir.endswith("/"):
mount_dir = mount_dir[:-1]

if mount_dir == "":
arcname = host_file.name
else:
arcname = f"{mount_dir}/{host_file.name}"
print(f"mount_dir: {mount_dir} arcname: {arcname}")
save_as_tarfile(
output_filename=output_filename,
filenames=[host_file],
arcnames=[mount_dir / host_file.name],
arcnames=[arcname],
compression_format=compression_format,
compresslevel=compresslevel,
)
15 changes: 14 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@

from empack.file_patterns import pkg_file_filter_from_yaml

import platform
IS_WINDOWS = (platform.system() == "Windows")

def to_native_path(posix_path_str):
if IS_WINDOWS:
return posix_path_str.replace("/", "\\")
else:
return posix_path_str


THIS_DIR = os.path.dirname(os.path.realpath(__file__))
CONFIG_PATH = os.path.join(THIS_DIR, "..", "config", "empack_config.yaml")
FILE_FILTERS = pkg_file_filter_from_yaml(CONFIG_PATH)
CHANNELS = ["conda-forge", "https://repo.mamba.pm/emscripten-forge"]


# check if environment variable MAMBA_EXE is set
MAMBA_EXE = os.environ.get("MAMBA_EXE")

def get_free_port():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand All @@ -31,3 +42,5 @@ def tmp_path_module(request, tmpdir_factory):
"""A tmpdir fixture for the module scope. Persists throughout the module."""
return Path(tmpdir_factory.mktemp(request.module.__name__))



Loading