-
Notifications
You must be signed in to change notification settings - Fork 13
Modernize Python packaging using uv and pyproject.toml #225
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
gdevenyi
wants to merge
7
commits into
master
Choose a base branch
from
modernize-packaging-with-uv
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ed25bd3
Modernize Python packaging using uv and pyproject.toml
gdevenyi 1941ff1
Update repository references to CoBrALab organization
gdevenyi cbb2f27
Update GitHub Actions to use uv for building
gdevenyi ba93932
Remove stale [project.optional-dependencies] testing group
gdevenyi ecd8ed4
update workflow versions
CMonnin 8d654ed
Update README.md
gdevenyi ad92960
Update test/test_qbatch.py
gdevenyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,54 @@ | ||
| # Python | ||
| *.pyc | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
| .Python | ||
|
|
||
| # Virtual environments | ||
| .venv/ | ||
| venv/ | ||
| ENV/ | ||
| env/ | ||
|
|
||
| # Testing | ||
| .pytest_cache/ | ||
| .coverage | ||
| htmlcov/ | ||
| .tox/ | ||
|
|
||
| # Distribution / packaging | ||
| *.egg | ||
| *.egg-info/ | ||
| dist/ | ||
| build/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| share/python-wheels/ | ||
|
|
||
| # Project specific | ||
| .scripts/ | ||
| logs/ | ||
| .qbatch/ | ||
| .eggs/ | ||
| qbatch.egg-info/ | ||
|
|
||
| # uv | ||
| uv.lock | ||
| .python-version | ||
|
|
||
| # IDE | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Overview | ||
|
|
||
| qbatch is a command-line tool and Python library for executing shell commands in parallel on high-performance computing clusters. It abstracts differences between various job schedulers (PBS/Torque, SGE, Slurm) and provides a unified interface for submitting batch jobs. | ||
|
|
||
| ## Common Development Commands | ||
|
|
||
| ### Testing | ||
| ```bash | ||
| # Run all tests | ||
| nosetests test/test_qbatch.py | ||
|
|
||
| # Run a specific test | ||
| nosetests test/test_qbatch.py:test_run_qbatch_local_piped_commands | ||
|
|
||
| # Run with verbose output | ||
| nosetests -v test/test_qbatch.py | ||
| ``` | ||
|
|
||
| ### Building | ||
| ```bash | ||
| # Build source distribution and wheel | ||
| python setup.py sdist bdist_wheel | ||
|
|
||
| # Build for local testing | ||
| pip install -e . | ||
| ``` | ||
|
|
||
| ### Installation | ||
| ```bash | ||
| # Install from source | ||
| pip install . | ||
|
|
||
| # Install with testing dependencies | ||
| pip install -r requirements-testing.txt | ||
| ``` | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Architecture | ||
|
|
||
| ### Core Components | ||
|
|
||
| The codebase is intentionally simple, with all logic contained in a single main file: | ||
|
|
||
| - **qbatch/qbatch.py** (777 lines): Contains all functionality | ||
| - **qbatch/__init__.py**: Package exports | ||
|
|
||
| ### Key Functions | ||
|
|
||
| **`qbatchParser(args=None)`** (line 645-772) | ||
| - Argument parser using argparse | ||
| - Parses command-line options and environment variables | ||
| - Calls `qbatchDriver()` with parsed arguments | ||
|
|
||
| **`qbatchDriver(**kwargs)`** (line 341-642) | ||
| - Main driver function that orchestrates job submission | ||
| - Accepts either a command file or a `task_list` (list of command strings) | ||
| - Generates job scripts based on the selected scheduler system | ||
| - Supports "chunking" commands into groups, each running in parallel via GNU parallel | ||
|
|
||
| **System-specific functions:** | ||
| - `pbs_find_jobs(patterns)` (line 238-285): Finds PBS/Torque jobs using qstat XML output | ||
| - `slurm_find_jobs(patterns)` (line 288-317): Finds Slurm jobs using squeue | ||
| - `compute_threads(ppj, ncores)` (line 228-235): Calculates threads per command | ||
|
|
||
| ### Templates (lines 76-155) | ||
|
|
||
| The system uses template strings for generating job scheduler headers: | ||
| - `PBS_HEADER_TEMPLATE`: PBS/Torque job scripts | ||
| - `SGE_HEADER_TEMPLATE`: Grid Engine job scripts | ||
| - `SLURM_HEADER_TEMPLATE`: Slurm job scripts | ||
| - `LOCAL_TEMPLATE`: Local execution using GNU parallel | ||
| - `CONTAINER_TEMPLATE`: For containerized environments | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| All defaults can be overridden via environment variables (prefix `QBATCH_`): | ||
| - `QBATCH_SYSTEM`: Scheduler type (pbs, sge, slurm, local, container) | ||
| - `QBATCH_PPJ`: Processors per job | ||
| - `QBATCH_CHUNKSIZE`: Commands per job chunk | ||
| - `QBATCH_CORES`: Parallel commands per job | ||
| - `QBATCH_MEM`: Memory request | ||
| - `QBATCH_QUEUE`: Queue name | ||
| - `QBATCH_SCRIPT_FOLDER`: Where to write generated scripts (default: `.qbatch/`) | ||
|
|
||
| ### Key Concepts | ||
|
|
||
| **Chunking**: Commands are divided into chunks (controlled by `-c`). Each chunk becomes one job submission. Within a job, commands run in parallel using GNU parallel (controlled by `-j`). | ||
|
|
||
| **Array vs Individual Jobs**: By default, qbatch creates array jobs when chunks > 1. The `-i` flag submits individual jobs instead. | ||
|
|
||
| **Job Dependencies**: The `--depend` option accepts glob patterns or job IDs to wait for before starting new jobs. | ||
|
|
||
| **Environment Propagation**: Three modes (via `--env`): | ||
| - `copied`: Exports current environment variables into job script | ||
| - `batch`: Uses scheduler's native environment propagation (-V, --export=ALL) | ||
| - `none`: No environment propagation | ||
|
|
||
| ## Testing Notes | ||
|
|
||
| Tests use `nosetests` and rely on: | ||
| - Setting `QBATCH_SCRIPT_FOLDER` to a temp directory | ||
| - Testing dry-run mode (`-n`) to avoid actual job submission | ||
| - Simulating scheduler environment variables (e.g., `SGE_TASK_ID`, `PBS_ARRAYID`) | ||
| - Using Python 2/3 compatibility via `future` library | ||
|
|
||
| Tests are integration-style, generating actual job scripts and verifying they produce expected output when executed. | ||
|
|
||
| ## Python 2/3 Compatibility | ||
|
|
||
| The codebase maintains Python 2.7+ compatibility using: | ||
| - `future` library for standard library aliases | ||
| - Custom `_EnvironDict` class for UTF-8 environment variable handling on Python 2 | ||
| - `io.open()` for UTF-8 file handling | ||
| - Careful string/unicode handling | ||
|
|
||
| ## Version Management | ||
|
|
||
| - Version is defined in `setup.py` (line 14) | ||
| - Uses `importlib.metadata` for version retrieval at runtime (line 9) | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - GitHub Actions workflow publishes releases to PyPI when a release is created | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [project] | ||
| name = "qbatch" | ||
| version = "2.3.1" | ||
| description = "Execute shell command lines in parallel on Slurm, SGE and PBS/Torque clusters" | ||
| readme = "README.md" | ||
| license = { text = "Unlicense" } | ||
| requires-python = ">=3.8" | ||
| authors = [ | ||
| { name = "Jon Pipitone", email = "jon@pipitone.ca" }, | ||
| { name = "Gabriel A. Devenyi", email = "gdevenyi@gmail.com" }, | ||
| ] | ||
| maintainers = [ | ||
| { name = "Jon Pipitone", email = "jon@pipitone.ca" }, | ||
| { name = "Gabriel A. Devenyi", email = "gdevenyi@gmail.com" }, | ||
| ] | ||
| keywords = [ | ||
| "hpc", | ||
| "batch", | ||
| "cluster", | ||
| "slurm", | ||
| "sge", | ||
| "pbs", | ||
| "torque", | ||
| "parallel", | ||
| ] | ||
| classifiers = [ | ||
| "Development Status :: 5 - Production/Stable", | ||
| "Environment :: Console", | ||
| "Intended Audience :: Science/Research", | ||
| "License :: Public Domain", | ||
| "Natural Language :: English", | ||
| "Operating System :: POSIX :: Linux", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.8", | ||
| "Programming Language :: Python :: 3.9", | ||
| "Programming Language :: Python :: 3.10", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
| "Topic :: System :: Clustering", | ||
| "Topic :: System :: Distributed Computing", | ||
| "Topic :: Utilities", | ||
| ] | ||
| dependencies = [] | ||
|
|
||
| [project.optional-dependencies] | ||
| testing = [ | ||
| "nose>=1.0", | ||
| "ushlex", | ||
| ] | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [project.scripts] | ||
| qbatch = "qbatch:qbatchParser" | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/pipitone/qbatch" | ||
| Repository = "https://github.com/pipitone/qbatch" | ||
| Issues = "https://github.com/pipitone/qbatch/issues" | ||
|
|
||
| [dependency-groups] | ||
| dev = [] | ||
| testing = [ | ||
| "pytest>=7.0", | ||
| "pytest-cov>=4.0", | ||
| ] | ||
|
|
||
| [tool.hatch.build.targets.wheel] | ||
| packages = ["qbatch"] | ||
|
|
||
| [tool.hatch.build.targets.sdist] | ||
| include = [ | ||
| "/qbatch", | ||
| "/test", | ||
| "/README.md", | ||
| "/LICENSE", | ||
| "/CLAUDE.md", | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| from __future__ import absolute_import | ||
|
|
||
| from . import qbatch | ||
| from .qbatch import qbatchParser | ||
| from .qbatch import qbatchDriver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.