diff --git a/.github/workflows/test-mlc-script-pip.yml b/.github/workflows/test-mlc-script-pip.yml new file mode 100644 index 000000000..6e93af9c5 --- /dev/null +++ b/.github/workflows/test-mlc-script-pip.yml @@ -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 diff --git a/setup.py b/setup.py index 0ba25f32d..311c51537 100644 --- a/setup.py +++ b/setup.py @@ -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, @@ -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: