Skip to content

Add tests for mlc-scripts installation #323

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

Merged
merged 5 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/test-mlc-script-pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Test pip installation for mlc-script

on:
pull_request:
branches: [ "main", "dev" ]
paths:
- '.github/workflows/test-mlc-script-pip.yml'
- '**'
- '!**.md'

jobs:
test_mlc_script_install_pypi:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.8"]
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
exclude:
- os: windows-latest
- os: macos-latest

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: install mlc-scripts
run: |
pip install mlc-scripts
- name: run detect-os script
run: |
mlcr detect-os -j

test_mlc_script_install_pull_request_source:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.8"]
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
exclude:
- os: windows-latest
- os: macos-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: install mlc-scripts from source repo
run: |
pip install .
- name: run detect-os script
run: |
mlcr detect-os -j
20 changes: 12 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,28 @@ def get_project_meta(file_path="pyproject.toml"):
dict: Dictionary containing the project metadata.
"""
try:
with open(file_path, "rb") as f:
with open(file_path, "r") as f:
content_tmp = f.read()
if 'tomllib' in globals():
project_data = tomllib.load(f) # Use tomllib for Python 3.11+
# Use tomllib for Python 3.11+
project_data = tomllib.loads(content_tmp)
else:
project_data = toml.load(f) # Use toml for older versions
# Use toml for older versions
project_data = toml.loads(content_tmp)

# Extract metadata under [project]
project_meta = project_data.get("project", {})
return project_meta

except FileNotFoundError:
print(f"Error: {file_path} not found.")
raise FileNotFoundError(f"Error: {file_path} not found.")
except Exception as e:
print(f"Error reading {file_path}: {e}")
raise RuntimeError(f"Error reading {file_path}: {e}")
return {}


def check_prerequisites():
"""Check if Git and python-venv are installed on the system."""
"""Check if Git and python-venv are installed on the system. """
try:
# Check for Git
subprocess.run(["git", "--version"], check=True,
Expand Down Expand Up @@ -77,9 +80,10 @@ def run(self):
'branch': branch,
# 'checkout': commit_hash
})
print(res)

if res['return'] > 0:
return res['return']
raise Exception(
f"Return code:{res['return']} with error:{res.get('error')}")

# subprocess.run(["echo", "Custom command executed!"], check=True)
except Exception as e:
Expand Down
Loading