Skip to content

Merge Dev #320

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 8 commits into from
Mar 25, 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
5 changes: 1 addition & 4 deletions .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Build wheel and release into PYPI

on:
release:
types: [published]

on:
push:
branches:
- dev_off
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/build_wheels_on_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build wheel and release into PYPI

on:
release:
types: [published]
workflow_dispatch: {}

jobs:

build_wheels:
if: github.repository_owner == 'mlcommons'
name: Build wheel
runs-on: ubuntu-latest
environment: release

permissions:
id-token: write
contents: write

strategy:
fail-fast: false
steps:
# Step : Checkout the code
- uses: actions/checkout@v4
with:
fetch-depth: 2
ssh-key: ${{ secrets.DEPLOY_KEY }}
ref: ${{ github.ref_name }}

# Step : Set up Python
- uses: actions/setup-python@v3

# Step : Install required dependencies
- name: Install requirements
run: python3 -m pip install setuptools wheel build

# Step : Build the Python wheel
- name: Build wheels
working-directory: ./
run: python3 -m build && rm dist/*.whl

# Step : Publish to PyPI
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verify-metadata: true
skip-existing: true
packages-dir: dist
repository-url: https://upload.pypi.org/legacy/
verbose: true
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1
8 changes: 8 additions & 0 deletions script/get-generic-sys-util/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,14 @@ variations:
brew: pkg-config
dnf: pkg-config
yum: pkg-config
postfix:
env:
MLC_SYS_UTIL_NAME: postfix
new_env_keys:
- MLC_POSTFIX_VERSION
state:
postfix:
apt: postfix
psmisc:
env:
MLC_SYS_UTIL_NAME: psmisc
Expand Down
47 changes: 47 additions & 0 deletions script/send-mail/customize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from mlc import utils
import os
import subprocess


def preprocess(i):

env = i['env']
state = i['state']

os_info = i['os_info']

# Start constructing the argument string
args = f"--subject '{env.get('MLC_EMAIL_SUBJECT', '')}' "

# Process other arguments
args += f"--to_addresses '{env.get('MLC_EMAIL_TO_ADDRESSES', '')}' "
args += f"--cc_addresses '{env.get('MLC_EMAIL_CC_ADDRESSES', '')}' "
args += f"--bcc_addresses '{env.get('MLC_EMAIL_BCC_ADDRESSES', '')}' "
args += f"--content_file '{env.get('MLC_EMAIL_CONTENT_FILE', '')}' "

# Process attachments
args += f"--attachments '{env.get('MLC_EMAIL_ATTACHMENTS', '')}'"

# Add flags for SMTP server, email and password if needed
if env.get('MLC_EMAIL_USE_SMTP_SERVER'):
args += "--use_smtp_server "
args += f"--email '{env.get('MLC_EMAIL_SMPT_EMAIL', '')}' "
args += f"--password '{env.get('MLC_EMAIL_SMTP_PASSWORD', '')}' "
args += f"--smtp_server '{env.get('MLC_EMAIL_SMTP_SERVER', '')}' "

subject = env.get('MLC_EMAIL_SUBJECT', '')
to_address = ",".join(env.get('MLC_EMAIL_TO_ADDRESS', []))

env['MLC_RUN_CMD'] = f"""{env['MLC_PYTHON_BIN_WITH_PATH']} {os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'], 'send-email.py')} {args}"""

return {'return': 0}


def postprocess(i):

env = i['env']
state = i['state']

os_info = i['os_info']

return {'return': 0}
30 changes: 30 additions & 0 deletions script/send-mail/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
alias: send-mail
automation_alias: script
automation_uid: 5b4e0237da074764
category: Utils
deps:
- tags: detect,os
- tags: get,python
names:
- python
- python3
- tags: get,generic-sys-util,_postfix
enable_if_env:
MLC_HOST_OS_FLAVOR:
- ubuntu
new_env_keys: []
new_state_keys: []
post_deps: []
posthook_deps: []
prehook_deps: []
input_mapping:
subject: MLC_EMAIL_SUBJECT
to_addresses: MLC_EMAIL_TO_ADDRESSES
to_address: MLC_EMAIL_TO_ADDRESSES
attachments: MLC_EMAIL_ATTACHMENTS
attachment: MLC_EMAIL_ATTACHMENTS
tags:
- send
- mail
- email
uid: 5f9b9654ecbe4662
23 changes: 23 additions & 0 deletions script/send-mail/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@echo off
setlocal enabledelayedexpansion

:: Function to exit if the last command failed
:exit_if_error
if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL%
exit /b 0

:: Function to run a command
:run
echo Running:
echo %1
echo.

if /I "%MLC_FAKE_RUN%" NEQ "yes" (
call %1
call :exit_if_error
)
exit /b 0

:: Add your run commands here...
:: call :run "%MLC_RUN_CMD%"

18 changes: 18 additions & 0 deletions script/send-mail/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
function exit_if_error() {
test $? -eq 0 || exit $?
}

function run() {
echo "Running: "
echo "$1"
echo ""
if [[ ${MLC_FAKE_RUN} != 'yes' ]]; then
eval "$1"
exit_if_error
fi
}

#Add your run commands here...

run "$MLC_RUN_CMD"
131 changes: 131 additions & 0 deletions script/send-mail/send-email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import smtplib
import sys
import argparse
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.utils import COMMASPACE
from email import encoders


def send_email(subject, to_addresses, cc_addresses, bcc_addresses, content_file,
attachments, use_smtp_server=False, smtp_server=None, email=None, password=None):

to_list = to_addresses.split(',')
cc_list = cc_addresses.split(',')
bcc_list = bcc_addresses.split(',')
attachment_list = attachments.split(',')

if content_file and os.path.exists(content_file):
with open(content_file, 'r') as file:
email_content = file.read()
else:
email_content = ''

msg = MIMEMultipart()
msg['From'] = email if use_smtp_server else 'localhost'
msg['To'] = COMMASPACE.join(to_list)
msg['Cc'] = COMMASPACE.join(cc_list)
msg['Subject'] = subject

msg.attach(MIMEText(email_content, 'plain'))

for attachment in attachment_list:
if attachment.strip() == '':
continue

with open(attachment, 'rb') as file:
part = MIMEBase('application', 'octet-stream')
part.set_payload(file.read())
encoders.encode_base64(part)
part.add_header(
'Content-Disposition',
f'attachment; filename={attachment}')
msg.attach(part)

recipients = to_list + cc_list + bcc_list

if use_smtp_server:
with smtplib.SMTP_SSL(smtp_server) as server:
server.login(email, password)
server.sendmail(email, recipients, msg.as_string())
print("Email sent successfully using SMTP server!")
else:
with smtplib.SMTP('localhost') as server:
server.sendmail(
'localhost@example.com',
recipients,
msg.as_string())
print("Email sent successfully using localhost!")


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Send an email with specified attachments')
parser.add_argument('--subject', type=str, help='Email subject')
parser.add_argument(
'--to_addresses',
type=str,
help='To addresses, comma-separated')
parser.add_argument(
'--cc_addresses',
type=str,
nargs='?',
default='',
help='CC addresses, comma-separated')
parser.add_argument(
'--bcc_addresses',
type=str,
nargs='?',
default='',
help='BCC addresses, comma-separated')
parser.add_argument(
'--content_file',
type=str,
nargs='?',
default='',
help='File containing email content')
parser.add_argument(
'--attachments',
type=str,
nargs='?',
default='',

help='Attachments, comma-separated file paths')

parser.add_argument(
'--use_smtp_server',
action='store_true',
help='Use an SMTP server instead of localhost')
parser.add_argument(
'--email',
type=str,
default='',
nargs='?',
help='Email address for SMTP server')
parser.add_argument(
'--password',
type=str,
default='',
nargs='?',
help='Password for SMTP server')
parser.add_argument('--smtp_server', type=str, help='SMTP server address')

args = parser.parse_args()

if args.use_smtp_server and not all(
[args.email, args.password, args.smtp_server]):
parser.error(
'--email, --password, and --smtp_server are required when --use_smtp_server is set')

send_email(
args.subject,
args.to_addresses,
args.cc_addresses,
args.bcc_addresses,
args.content_file,
args.attachments,
args.use_smtp_server,
args.smtp_server,
args.email,
args.password)
Loading