-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcfb764
commit bc6abbd
Showing
11 changed files
with
166 additions
and
16 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -3,4 +3,6 @@ __pycache__/ | |
.idea | ||
uploads/ | ||
app.log | ||
.DS_Store | ||
.DS_Store | ||
rosemary.egg-info/ | ||
build/ |
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
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
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,19 @@ | ||
# rosemary/cli.py | ||
|
||
import click | ||
from rosemary.commands.update import update | ||
from rosemary.commands.info import info | ||
from rosemary.commands.env import env | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
pass | ||
|
||
|
||
cli.add_command(update) | ||
cli.add_command(info) | ||
cli.add_command(env) | ||
|
||
if __name__ == '__main__': | ||
cli() |
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,15 @@ | ||
# rosemary/commands/env.py | ||
|
||
import click | ||
from dotenv import dotenv_values | ||
|
||
|
||
@click.command() | ||
def env(): | ||
"""Displays the current .env file values.""" | ||
# Load the .env file | ||
env_values = dotenv_values(".env") | ||
|
||
# Display keys and values | ||
for key, value in env_values.items(): | ||
click.echo(f"{key}={value}") |
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,31 @@ | ||
import click | ||
import pkg_resources | ||
|
||
|
||
def get_metadata_value(metadata_lines, key): | ||
default_value = f"{key}: Unknown" | ||
line = next((line for line in metadata_lines if line.startswith(key)), default_value) | ||
return line.split(':', 1)[1].strip() if line != default_value else default_value.split(':', 1)[1].strip() | ||
|
||
|
||
@click.command() | ||
def info(): | ||
"""Displays information about the Rosemary CLI.""" | ||
distribution = pkg_resources.get_distribution("rosemary") | ||
|
||
try: | ||
metadata = distribution.get_metadata_lines('METADATA') | ||
author = get_metadata_value(metadata, 'Author') | ||
author_email = get_metadata_value(metadata, 'Author-email') | ||
description = get_metadata_value(metadata, 'Summary') | ||
except FileNotFoundError: | ||
author, author_email, description = "Unknown", "Unknown", "Not available" | ||
|
||
name = distribution.project_name | ||
version = distribution.version | ||
|
||
click.echo(f"Name: {name}") | ||
click.echo(f"Version: {version}") | ||
click.echo(f"Author: {author}") | ||
click.echo(f"Author-email: {author_email}") | ||
click.echo(f"Description: {description}") |
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,29 @@ | ||
# rosemary/commands/update.py | ||
|
||
import click | ||
import subprocess | ||
import os | ||
|
||
|
||
@click.command() | ||
def update(): | ||
"""This command updates pip, all packages, and updates requirements.txt.""" | ||
try: | ||
# Update pip | ||
subprocess.check_call(['pip', 'install', '--upgrade', 'pip']) | ||
|
||
# Get the list of installed packages and update them | ||
packages = subprocess.check_output(['pip', 'freeze']).decode('utf-8').split('\n') | ||
for package in packages: | ||
package_name = package.split('==')[0] | ||
if package_name: # Check if the package name is not empty | ||
subprocess.check_call(['pip', 'install', '--upgrade', package_name]) | ||
|
||
# Update requirements.txt | ||
requirements_path = os.path.join(os.getcwd(), 'requirements.txt') | ||
with open(requirements_path, 'w') as f: | ||
subprocess.check_call(['pip', 'freeze'], stdout=f) | ||
|
||
click.echo('Update completed!') | ||
except subprocess.CalledProcessError as e: | ||
click.echo(f'Error during the update: {e}') |
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,21 @@ | ||
# setup.py | ||
|
||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='rosemary', | ||
version='0.1.0', | ||
packages=find_packages(), | ||
include_package_data=True, | ||
install_requires=[ | ||
'click', | ||
'python-dotenv', | ||
], | ||
author='David Romero', | ||
author_email='[email protected]', | ||
description="Rosemary is a CLI to be able to work on UVLHub development more easily.", | ||
entry_points=''' | ||
[console_scripts] | ||
rosemary=rosemary.cli:cli | ||
''', | ||
) |