Skip to content

Commit

Permalink
Ready this for publication to the Python Package Index
Browse files Browse the repository at this point in the history
- Makes a new console script available: `slim`
- Removes `requirements.txt` and replaces it with `pyproject.toml` which has both the dependencies and the package metadata
- Updates the instructions to demonstration installation from PyPI as well as how to continue local development
- Adds support for `--version` and version tracking
- Adds a `.gitignore`
- Removes potential [Dependency Confusion Vulnerabilities](https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610)
- Comments-out `tabulate` dependency; it doesn't appear to be used
- Removes `argparse` dependency; it's part of the standard library
  • Loading branch information
nutjob4life committed Aug 22, 2024
1 parent 4a314ca commit ff551ec
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 37 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.DS_Store
._*
*.py[co]
.*.cfg
*.egg-info
dist
build
eggs
downloads
*.log
*~
*.sublime-workspace
.venv
venv
__pycache__
64 changes: 48 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,23 @@ This guide provides a quick way to get started with our project. Please see our

### Setup Instructions

1. Clone the repository
```bash
git clone https://github.com/NASA-AMMOS/slim-cli.git
cd slim-cli
```
2. Install dependencies
```bash
pip install -r requirements.txt
```
As the SLIM CLI is written in Python, you'll need Python 3.7 or later. Usually, you'll want to create a virtual environment in order to isolate the dependencies of SLIM from other Python-using applications. Install into that environment using `pip`:

pip install slim-cli

This installs the latest SLIM CLI and its dependencies from the [Python Package Index](https://pypi.org/). The new console script `slim` is now ready for use. Confirm by running either:

slim --version
slim --help

To upgrade:

pip install --upgrade slim-cli

Or select a specific version, such as `X.Y.Z`:

pip install slim-cli==X.Y.Z


### Run Instructions

Expand All @@ -82,7 +90,7 @@ This section provides detailed commands to interact with the SLIM CLI. Each comm
1. **List all available best practices**
- This command lists all best practices fetched from the SLIM registry.
```bash
python slim-cli.py list
slim list
```

2. **Apply best practices to repositories**
Expand All @@ -93,21 +101,21 @@ This section provides detailed commands to interact with the SLIM CLI. Each comm
- `--clone-to-dir`: Path where the repository should be cloned if not present locally. Compatible with `--repo-urls`.
- `--use-ai`: Enables AI features to customize the application of best practices based on the project’s specific needs. Specify the model provider and model name as an argument (e.g., `azure/gpt-4o`).
```bash
python slim-cli.py apply --best-practice-ids SLIM-123 SLIM-456 --repo-urls https://github.com/your-username/your-repo1 https://github.com/your-username/your-repo2
slim apply --best-practice-ids SLIM-123 SLIM-456 --repo-urls https://github.com/your-username/your-repo1 https://github.com/your-username/your-repo2
```
- To apply a best practice using AI customization:
```bash
# Apply a specific best practice using AI customization
python slim-cli.py apply --best-practice-ids SLIM-123 --repo-urls https://github.com/your_org/your_repo.git --use-ai <model provider>/<model name>
slim apply --best-practice-ids SLIM-123 --repo-urls https://github.com/your_org/your_repo.git --use-ai <model provider>/<model name>
```
Example usage:
```bash
# Apply and deploy a best practice using Azure's GPT-4o model
python slim-cli.py apply --best-practice-ids SLIM-3.1 --repo-urls https://github.com/riverma/terraformly/ --use-ai azure/gpt-4o
slim apply --best-practice-ids SLIM-3.1 --repo-urls https://github.com/riverma/terraformly/ --use-ai azure/gpt-4o
```
```bash
# Apply and deploy a best practice using Ollama's LLaMA 3.1 model
python slim-cli.py apply --best-practice-ids SLIM-3.1 --repo-urls https://github.com/riverma/terraformly/ --use-ai ollama/llama3.1:405b
slim apply --best-practice-ids SLIM-3.1 --repo-urls https://github.com/riverma/terraformly/ --use-ai ollama/llama3.1:405b
```

3. **Deploy a best practice**
Expand All @@ -117,7 +125,7 @@ This section provides detailed commands to interact with the SLIM CLI. Each comm
- `--remote-name`: Specifies the remote name in the git configuration to which the changes will be pushed.
- `--commit-message`: A message describing the changes for the commit.
```bash
python slim-cli.py deploy --best-practice-ids SLIM-123 SLIM-456 --repo-dir /path/to/repo --remote-name origin --commit-message "Apply SLIM best practices"
slim deploy --best-practice-ids SLIM-123 SLIM-456 --repo-dir /path/to/repo --remote-name origin --commit-message "Apply SLIM best practices"
```

4. **Apply and deploy a best practice**
Expand All @@ -129,7 +137,7 @@ This section provides detailed commands to interact with the SLIM CLI. Each comm
- `--commit-message`: A message describing the changes for the commit.
- `--use-ai`: If specified, enables AI customization of the best practice before applying. False by default.
```bash
python slim-cli.py apply-deploy --best-practice-ids SLIM-123 --repo-urls https://github.com/your-username/your-repo1 https://github.com/your-username/your-repo2 --remote-name origin --commit-message "Integrated SLIM best practice with AI customization"
slim apply-deploy --best-practice-ids SLIM-123 --repo-urls https://github.com/your-username/your-repo1 https://github.com/your-username/your-repo2 --remote-name origin --commit-message "Integrated SLIM best practice with AI customization"
```
Example output:
```
Expand Down Expand Up @@ -158,6 +166,30 @@ For guidance on how to interact with our team, please see our code of conduct lo

For guidance on our governance approach, including decision-making process and our various roles, please see our governance model at: [GOVERNANCE.md](GOVERNANCE.md)


### Local Development

For local development of SLIM CLI, clone the GitHub repository, create a virtual environment, and then install the package in editable mode into it:
```bash
git clone --quiet https://github.com/NASA-AMMOS/slim-cli.git
cd slim-cli
python3 -m venv .venv
source .venv/bin/activate
pip install --editable .
```

The `slim` console-script is now ready in editable mode; changes you make to the source files under `src` are immediately reflected when run.

To publish a new version of SLIM CLI to the Python Package Index, typically you'll update the `VERSION.txt` file; then do:
```bash
pip install build wheel twine
python3 -m build .
twine upload dist/*
```

(Note: this can and should eventually be automated with GitHub Actions.)


## License

See our: [LICENSE](LICENSE)
Expand Down
64 changes: 64 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[project]
name = 'slim-cli'
dynamic = ['version']
requires-python = '>=3.7'
dependencies = [
# Note: these dependencies were taking from original `requirements.txt`
# file (now retired in favor of this file, `pyproject.toml`). However,
# pessimistic version constraints were added in order to avoid the
# Dependency Confusion Vulnerability.

'azure-identity ~= 1.17.1',
'gitpython ~= 3.1.43',
'ollama ~= 0.3.1',
'openai ~= 1.42.0',
'python-dotenv ~= 1.0.1',
'requests ~= 2.32.3',
'rich ~= 13.7.1',

# Commenting-out tabulate since it's not used in the code currenty:
# 'tabulate ~= 0.9.0',
]
authors = [
{name = 'James Ray', email='[email protected]'},
{name = 'Kyongsik Yun', email='[email protected]'},
{name = 'Rishi Verma', email='[email protected]'},
{name = 'Sean Kelly', email='[email protected]'}
]
description = 'Automation of the application of software lifecycle best practices to your GitHub repositories'
readme = 'README.md'
keywords = ['software', 'development', 'automation', 'practice', 'slim', 'nasa', 'ammos']
classifiers = [
'Development Status :: 2 - Pre-Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
]
license = {file = 'LICENSE'}


[project.urls]
Homepage = 'https://github.com/SLIM/slim-cli'
Issues = 'https://github.com/SLIM/slim-cli/issues'


[project.scripts]
slim = 'jpl.slim.cli:main'


[tool.hatch.version]
path = 'src/jpl/slim/VERSION.txt'
pattern = '(?P<version>.+)'


[tool.hatch.build.targets.wheel]
packages = ['src/jpl']


[build-system]
requires = ['hatchling']
build-backend = 'hatchling.build'
9 changes: 0 additions & 9 deletions requirements.txt

This file was deleted.

1 change: 1 addition & 0 deletions src/jpl/slim/VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.0
9 changes: 9 additions & 0 deletions src/jpl/slim/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# encoding: utf-8

'''🛠️ SLIM command-line tools.'''

import importlib.resources


PACKAGE_NAME = __name__
__version__ = VERSION = importlib.resources.files(__name__).joinpath('VERSION.txt').read_text().strip()
19 changes: 7 additions & 12 deletions slim-cli.py → src/jpl/slim/cli.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import argparse
import logging
import sys
import requests
import re
import git
import json
import logging
import os
import textwrap
import subprocess
from tabulate import tabulate
import requests
import tempfile
import textwrap
import urllib
import uuid
import openai
from dotenv import load_dotenv
from typing import Optional, Dict, Any
from rich.console import Console
from rich.table import Table
import git
import urllib

from . import VERSION


# Constants
Expand Down Expand Up @@ -864,6 +858,7 @@ def apply_and_deploy_best_practice(best_practice_id, use_ai_flag, model, remote_

def create_parser():
parser = argparse.ArgumentParser(description='This tool automates the application of best practices to git repositories.')
parser.add_argument('--version', action='version', version=VERSION)
parser.add_argument('-d', '--dry-run', action='store_true', help='Generate a dry-run plan of activities to be performed')

subparsers = parser.add_subparsers(dest='command', required=True)
Expand Down

0 comments on commit ff551ec

Please sign in to comment.