Skip to main content

A Python utility to update Node.js project dependencies safely with interactive mode and version management.

Project description

Python Package - packUpdate

Overview

updatepkgs is a comprehensive Python utility that automates the process of updating Node.js project dependencies with intelligent dependency resolution, breaking change detection, and comprehensive safety mechanisms.

Available Commands:

  • updatepkgs - Main command (consistent across Node.js and Python)
  • packUpdate - Alternative command name

Features

🚀 Core Update Features

  • Smart Update Algorithm: Latest → Wanted → Revert strategy with automatic rollback
  • Safe Mode: Test builds and tests after each update
  • Dependency Resolution: Updates packages in correct dependency order
  • Multiple Passes: Configurable number of update attempts

🎯 Interactive Mode

  • Selective Package Updates: Choose specific packages from an interactive checkbox list
  • Version Control: Select between minor or major updates for each package individually
  • Batch Operations: Update multiple packages with different version strategies at once
  • Update Preview: See exactly what will be updated before confirming changes
  • Skip Options: Easily skip packages you don't want to update
  • Safe Integration: Works with safe mode for tested interactive updates

🔧 Version Management

  • Automatic Version Updates: Update project version after successful package updates
  • Flexible Version Types: Support for major, minor, patch, or specific version numbers
  • Dual File Updates: Updates both package.json and package-lock.json automatically
  • Success-Based Updates: Only updates version if package updates were successful
  • Semver Compliance: Maintains proper semantic versioning format

🤖 Git Automation

  • Complete Workflow Automation: Clone → Update → Commit → PR
  • Multi-Platform Support: Bitbucket Server, GitHub, GitLab
  • Smart Branch Management: Auto-detects develop/master branches
  • Pull Request Generation: Detailed PRs with update logs and security reports
  • Ticket Integration: Jira/ticket linking in commits and PRs
  • SSH Authentication: Secure git operations with SSH keys

📝 Advanced Logging

  • Comprehensive Logging: Creates unique timestamped log files for every run
  • Quiet Mode: Runs in background with minimal console output while maintaining full logging
  • Error Tracking: All errors are captured with detailed information
  • Success Tracking: Successful updates are logged with version details

SSH Key Setup for Automation

The automation features require SSH keys for git operations. Follow these steps to set up SSH authentication:

1. Generate SSH Key

# Generate a new SSH key (if you don't have one)
ssh-keygen -t rsa -b 4096 -C "your.email@company.com"

# Save to default location (~/.ssh/id_rsa) when prompted
# Set a passphrase for security (recommended)

2. Add to SSH Agent

# Start SSH agent
eval "$(ssh-agent -s)"

# Add your SSH key
ssh-add ~/.ssh/id_rsa

# For macOS, add to keychain
ssh-add --apple-use-keychain ~/.ssh/id_rsa

3. Add Public Key to Git Servers

Copy your public key:

cat ~/.ssh/id_rsa.pub

Bitbucket Server:

  • Personal Settings → SSH keys → Add key
  • Paste public key content

GitHub:

  • Settings → SSH and GPG keys → New SSH key
  • Paste public key content

GitLab:

  • User Settings → SSH Keys → Add key
  • Paste public key content

4. Test SSH Connection

# Test your connections
ssh -T git@your-bitbucket-server.com
ssh -T git@github.com
ssh -T git@gitlab.com

5. Configure Custom SSH Ports (if needed)

Edit ~/.ssh/config:

Host your-bitbucket-server.com
    HostName your-bitbucket-server.com
    Port 7999
    User git
    IdentityFile ~/.ssh/id_rsa

For detailed SSH setup instructions, see the Automation Documentation.

Automation Examples

# Basic Bitbucket Server automation (safe mode automatic)
updatepkgs --automate \
  --platform bitbucket-server \
  --endpoint https://your-bitbucket-server.com \
  --token your-access-token \
  --repository WORKSPACE/repository \
  --ticket-no JIRA-456

# GitHub automation with minor-only updates (safe mode automatic)
updatepkgs --automate \
  --platform github \
  --repository myorg/myapp \
  --minor-only

# Combined with existing features (safe mode automatic)
updatepkgs --automate \
  --platform bitbucket-server \
  --repository WORKSPACE/webapp \
  --pass=3 \
  --remove-unused \
  --reviewers john.doe,jane.smith

Environment Variables

# Set defaults to avoid repeating parameters
export PACKUPDATE_BITBUCKET_TOKEN="your-token"
export PACKUPDATE_BITBUCKET_ENDPOINT="https://your-bitbucket-server.com"
export PACKUPDATE_REVIEWERS="john.doe,jane.smith"

# Then use simplified commands
updatepkgs --automate --platform bitbucket-server --repository WORKSPACE/repo

Prerequisites

  • Python (v3.8 or higher)
  • Node.js (v14 or higher)
  • npm (v6 or higher)

Installation

Install the library using pip:

pip install packupdate

Usage

Basic Commands

# Update packages in current directory
updatepkgs

# Update specific project
updatepkgs /path/to/project

# Safe mode with testing
updatepkgs --safe

# Interactive mode for selective updates
updatepkgs --interactive

# Quiet mode for automation
updatepkgs --quiet

Interactive Mode

# Interactive package selection
updatepkgs --interactive

# Interactive with safe mode
updatepkgs --interactive --safe

Interactive Features:

  • Package Selection: Choose specific packages to update from a list
  • Version Choice: Select between minor or major version updates for each package
  • Batch Operations: Update multiple packages with different version strategies
  • Update Preview: See exactly what will be updated before confirming
  • Selective Control: Skip packages you don't want to update

Version Management

# Update packages and bump project version
updatepkgs --update-version=minor
updatepkgs --update-version=major

# Set specific project version after updates
updatepkgs --update-version=1.2.3
updatepkgs --update-version=2.0.0

# Combined with other options
updatepkgs --safe --update-version=patch
updatepkgs --interactive --update-version=minor

Version Update Types:

  • major - Increment major version (1.0.0 → 2.0.0)
  • minor - Increment minor version (1.0.0 → 1.1.0)
  • patch - Increment patch version (1.0.0 → 1.0.1)
  • x.y.z - Set specific version (e.g., 1.2.3)

Version-Specific Updates

# Update only minor versions (safer)
updatepkgs --minor-only

# Multiple update passes
updatepkgs --pass=3

# Combined safe minor updates
updatepkgs --safe --minor-only

Analysis & Reporting

# Generate comprehensive report (no updates)
updatepkgs --generate-report

# Report with specific project
updatepkgs /path/to/project --generate-report

# Quiet report generation
updatepkgs --generate-report --quiet

Cleanup Operations

# Remove unused dependencies
updatepkgs --remove-unused

# Deduplicate packages
updatepkgs --dedupe-packages

# Combined cleanup
updatepkgs --remove-unused --dedupe-packages

Command Line Options

Core Options

  • --safe - Enable safe mode (test updates before applying)
  • --quiet - Enable quiet mode (minimal console output)
  • --interactive - Interactive mode for selective package updates
  • --pass=<number> - Number of update passes (default: 1)

Update Control

  • --minor-only - Update only minor versions (1.2.x → 1.3.x, skip major updates)

Analysis & Reporting

  • --generate-report - Generate comprehensive security & dependency report (no updates)

Cleanup & Maintenance

  • --remove-unused - Clean up unused dependencies
  • --dedupe-packages - Remove duplicate dependencies

Version Management

  • --update-version=<type> - Update project version after successful updates (major|minor|patch|x.y.z)

Information

  • --version - Show package version
  • --type - Show package type (python)
  • --help - Show help message
updatenpmpackages <project_path> [--safe] [--quiet] [--pass=N]

Parameters

  • <project_path>: The path to the Node.js project directory containing package.json.
  • --safe: Enables safe mode with comprehensive testing and fallback.
  • --quiet: Runs in quiet mode, suppressing detailed console output while maintaining full logging.
  • --pass=N: Specifies the number of update passes to perform. Default is 1.

Examples

  • Basic Update:

    updatenpmpackages /path/to/project
    
  • Safe Mode:

    updatenpmpackages /path/to/project --safe
    
  • Quiet Mode:

    updatenpmpackages /path/to/project --quiet
    
  • Multiple Passes:

    updatenpmpackages /path/to/project --pass=3
    
  • Combined Parameters:

    updatenpmpackages /path/to/project --safe --quiet --pass=2
    

Run using code

Clone the repository to your local machine:

git clone <repository-url>
cd PackUpdate/python

Install the required Python dependencies:

pip install -r requirements.txt

Usage

1. Run the Update Process

To update the packages in your Node.js project, use the following command:

python updatePackages.py <project_path> [--safe] [--quiet] [--pass=N]

2. Available Commands and Options

  • <project_path>: (Optional) The path to the Node.js project directory containing package.json and package-lock.json. If not provided, uses the current directory.

  • --safe: (Optional) Enables safe mode. In this mode:

    • The script first attempts to update packages to their latest versions.
    • If tests fail, it reverts to the "wanted" version.
    • If tests fail again, it reverts to the current version.
  • --quiet: (Optional) Enables quiet mode:

    • Suppresses detailed console output and test logs.
    • Runs npm operations in background.
    • Only shows critical errors and final log file location.
    • Full detailed logs are still written to the log file.
  • --version: (Optional) Shows the current version of the package.

  • --type: (Optional) Shows the package type (python).

  • --help: (Optional) Shows help message with all available parameters.

  • --pass=N: (Optional) Specifies the number of passes to attempt updating packages. Default is 1.

Note: Parameters can be specified in any order. If no project path is provided, the current directory is used.

3. Examples

Example 1: Basic Update

Run the script to update packages in a project located at /path/to/project:

python updatePackages.py /path/to/project

Example 2: Safe Mode

Run the script in safe mode to ensure updates are validated with tests:

python updatePackages.py /path/to/project --safe

Example 3: Quiet Mode

Run the script in quiet mode for background execution:

python updatePackages.py /path/to/project --quiet

Example 4: Multiple Passes

Run the script with 3 passes to attempt updates multiple times:

python updatePackages.py /path/to/project --pass=3

Example 5: Combined Options

Combine safe mode, quiet mode, and multiple passes:

python updatePackages.py /path/to/project --safe --quiet --pass=3

Example 6: Check Version

Check the current version:

python updatePackages.py --version

Example 7: Check Package Type

Check the package type:

python updatePackages.py --type

Example 8: Show Help

Show all available options:

python updatePackages.py --help

4. Logging

  • Automatic Logging: Every run creates a unique timestamped log file (e.g., packupdate-2025-10-08T11-35-03-140.log)
  • Error Tracking: All errors are logged with detailed information
  • Success Tracking: Successful package updates are recorded with version details
  • Failed Updates: Packages that fail to update are tracked and logged
  • Review: Log files can be reviewed later for troubleshooting or analysis

5. How It Works

  1. Dependency Update:

    • The script identifies outdated packages using npm outdated.
    • It attempts to update each package to the latest version or the "wanted" version based on the mode.
  2. Audit Fix:

    • After updating dependencies, the script runs npm audit fix to resolve any security vulnerabilities.
  3. Validation:

    • The script runs your project's test suite (npm test) to ensure that the updates do not break functionality.
  4. Build:

    • After updates, the script runs npm run build to ensure the project builds successfully.
  5. Logging:

    • All operations are logged to a timestamped file for later review.

6. Logs and Output

  • The script provides detailed logs during the update process, indicating:
    • Which packages were updated successfully.
    • Which packages were reverted to the "wanted" or current version due to issues.
    • Audit issues that were resolved.
  • In quiet mode, detailed output is suppressed but full logs are maintained in the log file.

7. Rollback

If you encounter issues after running the script, you can manually revert to a previous state using your version control system (e.g., Git).

Example Workflow

  1. Ensure your project has a valid package.json and package-lock.json.
  2. Run the script:
    python updatePackages.py /path/to/project --safe --quiet --pass=2
    
  3. Review the generated log file to confirm updates and audit fixes.
  4. Run your application to verify everything works as expected.

Local Development

For testing local changes without publishing:

cd PackUpdate/python
pip install -e .
updatenpmpackages --version  # Test your changes

For detailed local development instructions, see Local Development Guide.

Publishing to PyPI

To publish the PackUpdate package to PyPI, follow these steps:

  1. Install Required Tools: Ensure you have setuptools, wheel, and twine installed:

    pip install setuptools wheel twine
    
  2. Build the Package: Run the following command to create the distribution files:

    python setup.py sdist bdist_wheel
    

    This will generate the dist/ directory containing the .tar.gz and .whl files.

  3. Upload to PyPI: Use twine to upload the package to PyPI:

    twine upload dist/*
    
  4. Authenticate: Enter your PyPI username and password when prompted.

  5. Verify the Upload: Visit https://pypi.org/project/PackUpdate/ to confirm the package is live.

Notes:

  • Ensure your setup.py file is correctly configured with metadata like name, version, author, etc.
  • If you are testing the upload, use the Test PyPI repository:
    twine upload --repository-url https://test.pypi.org/legacy/ dist/*
    

This comprehensive Python package provides enterprise-grade dependency management with safety, intelligence, and automation capabilities.

📚 Documentation

Full documentation is available at: PackUpdate Docs

Or serve locally:

git clone https://github.com/sthpratik/PackUpdate.git
cd PackUpdate/docs
python -m http.server 3000

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

🐛 Issues & Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

packupdate-1.1.4.tar.gz (38.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

packupdate-1.1.4-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

File details

Details for the file packupdate-1.1.4.tar.gz.

File metadata

  • Download URL: packupdate-1.1.4.tar.gz
  • Upload date:
  • Size: 38.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for packupdate-1.1.4.tar.gz
Algorithm Hash digest
SHA256 49765806c2029803b65df422251ba85110d371efca4027d5b55580e888950f29
MD5 b11eb8a7f934661ff247d4e041e88ee9
BLAKE2b-256 ce0b31ff898b852cc10a63a06dc52278592f74ca8b2ff59192ab94e4f042dc23

See more details on using hashes here.

File details

Details for the file packupdate-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: packupdate-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 40.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for packupdate-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 33a9becc72d70227a6f87373055bb71f02ad3632a50ecd2c9757788545679535
MD5 dbc3fcd16059f67674bcd8f9035cea8f
BLAKE2b-256 5613a3e69099a1b7d0780fb33cdb0e3792eb533252d67b6760b2aa775a8b7e9a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page