Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a0a83fc
modularize
A-codinglee Aug 26, 2025
b086eef
add run_machinestate.sh
A-codinglee Sep 9, 2025
af4dc08
Update common.py and run_machinestate.sh
Sep 9, 2025
fdba3dd
add build_single.py and machinestate.py(from build_single.py)
Sep 10, 2025
900a4d3
updated build_single.py and machinestate.py
Sep 10, 2025
06eee1f
updated build_single.py
Sep 10, 2025
5e0c105
build single file machinestate.py on push to modularize
Sep 10, 2025
906364e
Add YAML output option (--yaml) to script.py and update build_single.…
Sep 23, 2025
8023b27
Update build_single.yml
A-codinglee Sep 23, 2025
5a8cb8a
Update build_single.yml
A-codinglee Sep 23, 2025
cc24886
Add YAML output support (--yaml) and unify structured output handling
Sep 26, 2025
c649039
update CLI: add --json output flag, rename compare option to --compare
A-codinglee Sep 30, 2025
60aa91e
Update common.py
TomTheBear Oct 1, 2025
ccae0b6
CI: build machinestate.py before tests
A-codinglee Oct 20, 2025
ddf9a0b
Rename machinestate folder to machinestate_pkg; keep machinestate.py …
A-codinglee Oct 20, 2025
d1ee1c2
Rename machinestate folder to machinestate_pkg; keep machinestate.py …
A-codinglee Oct 20, 2025
b4168f8
Rename machinestate folder to machinestate_pkg; keep machinestate.py …
A-codinglee Oct 20, 2025
231c7b1
change -j into -p
A-codinglee Oct 20, 2025
15e20cb
change -j into -p\
A-codinglee Oct 20, 2025
63a8869
remove --json
A-codinglee Oct 20, 2025
373ef22
-j to -p
A-codinglee Oct 20, 2025
744de6a
Add CgroupV2Info and unified CgroupInfo dispatcher for cgroup V2 support
A-codinglee Oct 30, 2025
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
58 changes: 58 additions & 0 deletions .github/workflows/build_single.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build single-file machinestate.py

on:
push:
branches: [ modularize ]
workflow_dispatch:

concurrency:
group: build-single-${{ github.ref }}
cancel-in-progress: true

jobs:
build-single:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Show Python version
run: python -V

# Install deps if your builder needs any. Otherwise this is harmless.
- name: Install dependencies (optional)
run: |
python -m pip install --upgrade pip
pip install pyyaml
# pip install -r requirements.txt

- name: Build single-file script
run: |
echo "[info] Running build_single.py..."
python build_single.py
echo "[info] Build complete."
test -f machinestate.py && ls -lh machinestate.py

# Optional smoke test; uncomment if 'machinestate.py -h' should work headlessly
# - name: Smoke test
# run: |
# python machinestate.py -h || true

- name: Upload machinestate.py artifact
uses: actions/upload-artifact@v4
with:
name: machinestate-single
path: machinestate.py
if-no-files-found: error
compression-level: 9
retention-days: 14

4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jobs:
python -m pip install build
python -m pip install setuptools
python -m pip install --upgrade pip
- name: Build single-file
run: |
python build_single.py
test -f machinestate.py && echo "machinestate.py generated."
- name: Build package
run: |
python -m build --wheel --sdist
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/test-n-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ jobs:
python -m pip install codecov
python -m pip install requests
python -m pip install --upgrade pip
- name: Build single-file
run: |
python build_single.py
test -f machinestate.py && echo "machinestate.py generated."
- name: Install
run: |
python -m pip install -e .
Expand All @@ -75,9 +79,9 @@ jobs:
coverage run -p `which machinestate` -s -i 4 -o output.json
CC=testcompiler CXX=testccompiler FC=testfortran coverage run -p `which machinestate` -c
coverage run -p `which machinestate` -e -s -a -m hostname
coverage run -p `which machinestate` -j output.json
coverage run -p `which machinestate` -e -j output.json
coverage run -p `which machinestate` -j output-ext.json
coverage run -p `which machinestate` -p output.json
coverage run -p `which machinestate` -e -p output.json
coverage run -p `which machinestate` -p output-ext.json
coverage run -p `which machinestate` --html
coverage run -p `which machinestate` --html -o output.html
- uses: codecov/codecov-action@v4
Expand Down
106 changes: 106 additions & 0 deletions build_single.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re, sys, os, pathlib, time

FILES = [
"machinestate_pkg/common.py",
"machinestate_pkg/BiosInfo.py",
"machinestate_pkg/CacheTopology.py",
"machinestate_pkg/CgroupInfo.py",
"machinestate_pkg/ClocksourceInfo.py",
"machinestate_pkg/CompilerInfo.py",
"machinestate_pkg/CoretempInfo.py",
"machinestate_pkg/CpuAffinity.py",
"machinestate_pkg/CpuFrequency.py",
"machinestate_pkg/CpuInfo.py",
"machinestate_pkg/CpuTopology.py",
"machinestate_pkg/DmiDecodeFile.py",
"machinestate_pkg/ExecutableInfo.py",
"machinestate_pkg/HostInfo.py",
"machinestate_pkg/Hugepages.py",
"machinestate_pkg/InfinibandInfo.py",
"machinestate_pkg/IrqAffinity.py",
"machinestate_pkg/KernelInfo.py",
"machinestate_pkg/LoadAvg.py",
"machinestate_pkg/MemInfo.py",
"machinestate_pkg/ModulesInfo.py",
"machinestate_pkg/MpiInfo.py",
"machinestate_pkg/NecTsubasaInfo.py",
"machinestate_pkg/NumaBalance.py",
"machinestate_pkg/NumaInfo.py",
"machinestate_pkg/NvidiaSmiInfo.py",
"machinestate_pkg/OpenCLInfo.py",
"machinestate_pkg/OperatingSystemInfo.py",
"machinestate_pkg/PowercapInfo.py",
"machinestate_pkg/PrefetcherInfo.py",
"machinestate_pkg/PythonInfo.py",
"machinestate_pkg/ShellEnvironment.py",
"machinestate_pkg/ThermalZoneInfo.py",
"machinestate_pkg/TransparentHugepages.py",
"machinestate_pkg/TurboInfo.py",
"machinestate_pkg/Uptime.py",
"machinestate_pkg/UsersInfo.py",
"machinestate_pkg/VulnerabilitiesInfo.py",
"machinestate_pkg/WritebackInfo.py",
"machinestate_pkg/WritebackWorkqueue.py",
"machinestate_pkg/script.py",
]

OUT = "machinestate.py"

# Regexes to strip package-relative imports and __main__ blocks
REL_IMPORT_RE = re.compile(r'^\s*from\s+\.\w+\s+import\s+.*$', re.M)
PKG_IMPORT_RE = re.compile(r'^\s*from\s+machinestate(?:\.\w+)?\s+import\s+.*$', re.M)

def strip_relative_imports(text: str) -> str:
# Remove "from .X import Y"
text = REL_IMPORT_RE.sub('', text)
# Remove "from machinestate(.X)? import Y"
text = PKG_IMPORT_RE.sub('', text)
# Also remove "import machinestate" (rare)
text = re.sub(r'^\s*import\s+machinestate\s*$', '', text, flags=re.M)
return text

def add_section_banner(path: str) -> str:
filename = os.path.basename(path)
return (
"\n\n" +
"#" * 80 + "\n" +
f"# BEGIN: {filename}\n" +
"#" * 80 + "\n"
)

def main():
root = pathlib.Path(__file__).parent
out_path = root / OUT

header = (
"#!/usr/bin/env python3\n"
f"# Auto-generated single-file MachineState ({time.strftime('%Y-%m-%d %H:%M:%S')})\n"
"# Do not edit manually; edit sources and re-run build_single_py.py\n\n"
)

chunks = [header]

for rel in FILES:
src_path = root / rel
if not src_path.exists():
print(f"[warn] missing file: {rel}", file=sys.stderr)
continue
text = src_path.read_text(encoding='utf-8')

text = strip_relative_imports(text)

chunks.append(add_section_banner(rel))
chunks.append(text.rstrip() + "\n")

# Ensure only ONE top-level runner: rely on script.py:main()
# If script.py doesn't have main(), you can add one here.
result = "".join(chunks)

out_path.write_text(result, encoding='utf-8')
os.chmod(out_path, 0o755)
print(f"[ok] wrote {OUT} ({out_path.stat().st_size} bytes)")

if __name__ == "__main__":
main()
Loading
Loading