-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mono/0.6.0.dev1' into pyproject
- Loading branch information
Showing
14 changed files
with
1,828 additions
and
1 deletion.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
pkgs/experimental/swarmauri_experimental/swarmauri_experimental/utils/add_comment_to_file.py
This file contains 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,50 @@ | ||
import os | ||
|
||
# Define a map for comment styles based on file extensions | ||
COMMENT_STYLES = { | ||
'.py': '#', # Python | ||
'.js': '//', # JavaScript | ||
'.java': '//', # Java | ||
'.html': '<!-- -->', # HTML | ||
'.css': '/* */', # CSS | ||
} | ||
|
||
def get_comment_style(file_path): | ||
""" | ||
Determine the comment style based on the file extension. | ||
""" | ||
_, ext = os.path.splitext(file_path) | ||
return COMMENT_STYLES.get(ext, None) | ||
|
||
def add_comment(file_path, comment_text): | ||
""" | ||
Add a comment to the top of a file with the appropriate comment style. | ||
""" | ||
comment_style = get_comment_style(file_path) | ||
if not comment_style: | ||
print(f"Unsupported file type for: {file_path}") | ||
return | ||
|
||
# Read the existing content | ||
with open(file_path, 'r') as file: | ||
content = file.readlines() | ||
|
||
# Prepare the comment based on the style | ||
if comment_style in ['#', '//']: | ||
comment = f"{comment_style} {comment_text}\n" | ||
elif comment_style == '<!-- -->': | ||
comment = f"<!-- {comment_text} -->\n" | ||
elif comment_style == '/* */': | ||
comment = f"/* {comment_text} */\n" | ||
else: | ||
print(f"Unsupported comment style: {comment_style}") | ||
return | ||
|
||
# Write the comment at the top and add the existing content | ||
with open(file_path, 'w') as file: | ||
file.write(comment) | ||
file.writelines(content) | ||
|
||
# Example usage | ||
add_comment('example.py', 'This is a Python file') | ||
add_comment('example.js', 'This is a JavaScript file') |
This file contains 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
Empty file.
This file contains 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,245 @@ | ||
<p align="center"> | ||
<a href="https://github.com/swarmauri/swarmauri-sdk/"><img src="https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png" alt="Swamauri Logo"/></a> | ||
<br /> | ||
<a href="https://hits.sh/github.com/swarmauri/monorepo_manager/"><img src="https://hits.sh/github.com/swarmauri/monorepo_manager.svg" alt="Hits"/></a> | ||
<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="License"/></a> | ||
<a href="https://pypi.org/project/monorepo_manager/"><img src="https://img.shields.io/pypi/v/monorepo_manager?label=monorepo_manager" alt="PyPI - monorepo_manager Version"/></a> | ||
<a href="https://pypi.org/project/monorepo_manager/"><img src="https://img.shields.io/pypi/dm/monorepo_manager?label=monorepo_manager%20Downloads" alt="PyPI - monorepo_manager Downloads"/></a> | ||
<br /> | ||
<img src="https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=python&labelColor=black" alt="Python"/> | ||
</p> | ||
|
||
|
||
# Monorepo Manager | ||
|
||
**Monorepo Manager** is a unified command-line tool for managing a Python monorepo that contains multiple standalone packages—each with its own `pyproject.toml`. It consolidates common tasks such as dependency management, version bumping, remote dependency resolution, test execution and analysis, and project configuration updates into one robust CLI. | ||
|
||
## Features | ||
|
||
- **Dependency Management** | ||
- **Lock:** Generate a `poetry.lock` file. | ||
- **Install:** Install dependencies with options for extras and development dependencies. | ||
- **Show Freeze:** (Available as an internal command) Display installed packages using `pip freeze`. | ||
|
||
- **Build Operations** | ||
- **Build:** Recursively build packages based on local (path) dependencies as specified in your `pyproject.toml` files. | ||
|
||
- **Version Management** | ||
- **Version:** Bump (major, minor, patch, finalize) or explicitly set package versions in `pyproject.toml`. | ||
|
||
- **Remote Operations** | ||
- **Remote Fetch:** Fetch the version from a remote GitHub repository’s `pyproject.toml`. | ||
- **Remote Update:** Update a local `pyproject.toml` file with version information fetched from remote Git dependencies. | ||
|
||
- **Testing and Analysis** | ||
- **Test:** Run your tests using pytest. Optionally, run tests in parallel (supports [pytest‑xdist](https://pypi.org/project/pytest-xdist/)). | ||
- **Analyze:** Analyze test results provided in a JSON file by displaying summary statistics and evaluating threshold conditions for passed/skipped tests. | ||
|
||
- **Pyproject Operations** | ||
- **Pyproject:** Extract both local (path) and Git-based dependencies from a `pyproject.toml` file and, optionally, update dependency versions. | ||
|
||
## Installation | ||
|
||
Install via pip: | ||
|
||
```bash | ||
pip install monorepo-manager | ||
``` | ||
|
||
_This command installs the `monorepo-manager` CLI, which is provided via the entry point `monorepo-manager`, into your system PATH._ | ||
|
||
## Usage | ||
|
||
After installation, run the following command to see a list of available commands: | ||
|
||
```bash | ||
monorepo-manager --help | ||
``` | ||
|
||
### Command Examples | ||
|
||
#### 1. Lock Dependencies | ||
|
||
Generate a `poetry.lock` file by specifying either a directory or a file path containing a `pyproject.toml`: | ||
|
||
```bash | ||
# Lock using a directory: | ||
monorepo-manager lock --directory ./packages/package1 | ||
|
||
# Lock using an explicit pyproject.toml file: | ||
monorepo-manager lock --file ./packages/package1/pyproject.toml | ||
``` | ||
|
||
#### 2. Install Dependencies | ||
|
||
Install dependencies with options for extras and including development dependencies: | ||
|
||
```bash | ||
# Basic installation: | ||
monorepo-manager install --directory ./packages/package1 | ||
|
||
# Using an explicit pyproject.toml file: | ||
monorepo-manager install --file ./packages/package1/pyproject.toml | ||
|
||
# Install including development dependencies: | ||
monorepo-manager install --directory ./packages/package1 --dev | ||
|
||
# Install including extras (e.g., extras named "full"): | ||
monorepo-manager install --directory ./packages/package2 --extras full | ||
|
||
# Install including all extras: | ||
monorepo-manager install --directory ./packages/package2 --all-extras | ||
``` | ||
|
||
#### 3. Build Packages | ||
|
||
Recursively build packages based on their local dependency paths defined in their `pyproject.toml` files: | ||
|
||
```bash | ||
# Build packages using a directory containing a master pyproject.toml: | ||
monorepo-manager build --directory . | ||
|
||
# Build packages using an explicit pyproject.toml file: | ||
monorepo-manager build --file ./packages/package1/pyproject.toml | ||
``` | ||
|
||
#### 4. Version Management | ||
|
||
Bump or explicitly set the version in a package's `pyproject.toml`: | ||
|
||
```bash | ||
# Bump the patch version (e.g., from 1.2.3.dev1 to 1.2.3.dev2): | ||
monorepo-manager version ./packages/package1/pyproject.toml --bump patch | ||
|
||
# Finalize a development version (remove the .dev suffix): | ||
monorepo-manager version ./packages/package1/pyproject.toml --bump finalize | ||
|
||
# Set an explicit version: | ||
monorepo-manager version ./packages/package1/pyproject.toml --set 2.0.0.dev1 | ||
``` | ||
|
||
#### 5. Remote Operations | ||
|
||
Fetch remote version information and update your local dependency configuration: | ||
|
||
```bash | ||
# Fetch the version from a remote GitHub repository's pyproject.toml: | ||
monorepo-manager remote fetch --git-url https://github.com/YourOrg/YourRepo.git --branch main --subdir "src/" | ||
|
||
# Update a local pyproject.toml with remote-resolved versions: | ||
# (If --output is omitted, the input file is overwritten.) | ||
monorepo-manager remote update --input ./packages/package1/pyproject.toml --output ./packages/package1/pyproject.updated.toml | ||
``` | ||
|
||
#### 6. Testing and Analysis | ||
|
||
Run your tests using pytest and analyze test results from a JSON report: | ||
|
||
- **Run Tests:** | ||
Execute tests within a specified directory. Use the `--num-workers` flag for parallel execution (requires pytest‑xdist): | ||
|
||
```bash | ||
# Run tests sequentially: | ||
monorepo-manager test --directory ./tests | ||
|
||
# Run tests in parallel using 4 workers: | ||
monorepo-manager test --directory ./tests --num-workers 4 | ||
``` | ||
|
||
- **Analyze Test Results:** | ||
Analyze a JSON test report and enforce thresholds for passed and skipped tests: | ||
|
||
```bash | ||
# Analyze test results without thresholds: | ||
monorepo-manager analyze test-results.json | ||
|
||
# Analyze test results with thresholds (e.g., passed tests > 75% and skipped tests < 20%): | ||
monorepo-manager analyze test-results.json --required-passed gt:75 --required-skipped lt:20 | ||
``` | ||
|
||
#### 7. Pyproject Operations | ||
|
||
Extract and update dependency information from a `pyproject.toml` file: | ||
|
||
```bash | ||
# Extract local (path) and Git-based dependencies: | ||
monorepo-manager pyproject --pyproject ./packages/package1/pyproject.toml | ||
|
||
# Update local dependency versions to 2.0.0 (updates the parent file and, if possible, each dependency's own pyproject.toml): | ||
monorepo-manager pyproject --pyproject ./packages/package1/pyproject.toml --update-version 2.0.0 | ||
``` | ||
|
||
## Workflow Example in GitHub Actions | ||
|
||
Here's an example GitHub Actions workflow that uses **monorepo_manager** to lock, build, install, test, bump the patch version, and publish: | ||
|
||
```yaml | ||
name: Release Workflow | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.9' | ||
|
||
- name: Install monorepo_manager Tools | ||
run: pip install "monorepo_manager@git+https://github.com/swarmauri/monorepo_manager.git@master" | ||
|
||
- name: Lock Dependencies | ||
run: monorepo-manager lock --directory . | ||
|
||
- name: Build Packages | ||
run: monorepo-manager build --directory . | ||
|
||
- name: Install Dependencies | ||
run: monorepo-manager install --directory . | ||
|
||
- name: Run Tests | ||
run: monorepo-manager test --directory ./tests --num-workers 4 | ||
|
||
- name: Bump Patch Version | ||
run: monorepo-manager version ./packages/package1/pyproject.toml --bump patch | ||
|
||
- name: Publish Packages | ||
env: | ||
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} | ||
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | ||
run: monorepo-manager publish --directory . --username "$PYPI_USERNAME" --password "$PYPI_PASSWORD" | ||
``` | ||
## Development | ||
### Project Structure | ||
``` | ||
monorepo_manager/ | ||
├── __init__.py | ||
├── cli.py # Main CLI entry point | ||
├── poetry_ops.py # Poetry operations (lock, install, build, publish, run tests, etc.) | ||
├── version_ops.py # Version bumping and setting operations | ||
├── remote_ops.py # Remote Git dependency version fetching/updating | ||
├── test_ops.py # Test result analysis operations | ||
└── pyproject_ops.py # pyproject.toml dependency extraction and updates | ||
pyproject.toml # Package configuration file containing metadata | ||
README.md # This file | ||
``` | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! Please open issues or submit pull requests for improvements or bug fixes. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
14 changes: 14 additions & 0 deletions
14
pkgs/tooling/monorepo_manager/monorepo_manager/__init__.py
This file contains 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,14 @@ | ||
# monorepo_manager/__init__.py | ||
|
||
try: | ||
# For Python 3.8 and newer | ||
from importlib.metadata import version, PackageNotFoundError | ||
except ImportError: | ||
# For older Python versions, use the backport | ||
from importlib_metadata import version, PackageNotFoundError | ||
|
||
try: | ||
__version__ = version("monorepo-manager") | ||
except PackageNotFoundError: | ||
# If the package is not installed (for example, during development) | ||
__version__ = "0.0.0" |
Oops, something went wrong.