Skip to content

Commit

Permalink
PyPI v0.6.0: Added ability to reinstall all dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
janik6n committed Apr 14, 2019
1 parent 9a5fe5b commit 3afa968
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 3 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.0] - 2019-04-14

### Added

- Added ability to reinstall all dependencies (excluding editable), with `jetzt --reinstall`.

### Changed

### Removed

### Fixed

## [0.5.0] - 2019-04-14

### Added
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ include jetzt/bin/list_outdated_pkgs.sh
include jetzt/bin/update_pypi_pkg.sh
include jetzt/bin/remove_pkg.sh
include jetzt/bin/create_reqs.sh
include jetzt/bin/reinstall_reqs.sh
graft jetzt/seeds
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Things should probably work nicely on other releases of macOS and on various Lin
- [List outdated dependencies](#list-outdated-dependencies)
- [Update outdated dependency](#update-outdated-dependency)
- [Remove installed dependency](#remove-installed-dependency)
- [Reinstall all dependencies](#reinstall-all-dependencies)
- [Create requirements files](#create-requirements-files)

## Create new project
Expand Down Expand Up @@ -126,6 +127,10 @@ To update an outdated dependency, run `jetzt --update`. This will allow you to c

To remove an installed dependency, run `jetzt --remove`. This will list all installed dependencies, and let's you choose which one you want to remove. After the update, the command will update the outdated dependency list automatically.

### Reinstall all dependencies

To reinstall all dependencies (excluding editable), run `jetzt --reinstall`. *Make sure, you are in active virtualenv.*

### Create requirements files

Run `jetzt --create-requirements` to generate standard `requirements.txt` and `requirements-dev.txt` based on `jetzt_metadata.json`.
Expand Down
2 changes: 1 addition & 1 deletion jetzt/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.5.0'
__version__ = '0.6.0'
50 changes: 50 additions & 0 deletions jetzt/bin/reinstall_reqs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/local/bin/zsh

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

echo "Reinstalling all dependencies..."
echo ""
# echo "${GREEN}PROD dependencies > requirements.txt${NC}:"
python "$1/create_reqs.py" dep_type___PROD silent___YES
# echo ""
# echo "${GREEN}DEV dependencies > requirements-dev.txt${NC}:"
python "$1/create_reqs.py" dep_type___DEV silent___YES

# Uninstall all
echo "Removing all installed dependencies (excluding editable)..."
echo ""
pip freeze --exclude-editable | xargs pip uninstall -y

# Reinstall DEVs
echo "Processing DEV dependencies:"
while read in;
do
echo "Processing $in ..."
if pip install -U $in; then
python "$1/update_metadata.py" package___"$in" action___INSTALL package_with_version___"$(pip freeze | grep -iF "$in")" dep_type___"DEV"
echo "${GREEN}Installation of package $in is ready.${NC}"
else
echo "${RED}Installation of package $in failed. See error above.${NC}"
fi;
done < requirements-dev.txt

# Reinstall PRODs
echo "Processing PROD dependencies:"
while read in;
do
echo "Processing $in ..."
if pip install -U $in; then
python "$1/update_metadata.py" package___"$in" action___INSTALL package_with_version___"$(pip freeze | grep -iF "$in")" dep_type___"PROD"
echo "${GREEN}Installation of package $in is ready.${NC}"
else
echo "${RED}Installation of package $in failed. See error above.${NC}"
fi;
done < requirements.txt

rm requirements-dev.txt
rm requirements.txt

echo ""
echo "${GREEN}Successfully reinstalled all dependencies.${NC}"
34 changes: 34 additions & 0 deletions jetzt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,37 @@ def run_remove(app_path=None, jetzt_metadata=None, jetzt_metadata_file='jetzt_me
sys.exit()


def run_reinstall(app_path=None, jetzt_metadata=None, jetzt_metadata_file='jetzt_metadata.json'):
prompt_are_you_sure = 'Are you sure, you want to reinstall all dependencies? Are you sure, you are in an active virtualenv? '

cli = SlidePrompt(
[
Bullet(prompt_are_you_sure,
choices=['No', 'Yes'],
bullet=" >",
margin=2,
bullet_color=colors.bright(colors.foreground["cyan"]),
background_on_switch=colors.background["black"],
word_color=colors.foreground["white"],
word_on_switch=colors.foreground["white"]),
]
)

result = cli.launch()
cli.summarize()

choice = 'No'

for result_item in result:
key, value = result_item
if key == prompt_are_you_sure:
choice = value

if choice == 'Yes':
subprocess.call(f'source {app_path}/bin/reinstall_reqs.sh "{app_path}"', shell=True)
sys.exit()


def run_create_requirements(app_path=None, jetzt_metadata=None, jetzt_metadata_file='jetzt_metadata.json'):
subprocess.call(f'source {app_path}/bin/create_reqs.sh {app_path}', shell=True)
sys.exit()
Expand All @@ -239,6 +270,7 @@ def run_create_requirements(app_path=None, jetzt_metadata=None, jetzt_metadata_f
@click.option('--outdated', 'command', flag_value='outdated', help='List outdated dependencies.')
@click.option('--update', 'command', flag_value='update', help='Update an outdated dependency, based on "jetzt --outdated".')
@click.option('--remove', 'command', flag_value='remove', help='Remove installed dependency.')
@click.option('--reinstall', 'command', flag_value='reinstall', help='Reinstall all installed dependencies (excluding editable).')
@click.option('--create-requirements', 'command', flag_value='create_requirements', help='Create requirements.txt and requirements-dev.txt.')
def app(command):
# Directory, where the command is run.
Expand Down Expand Up @@ -269,6 +301,8 @@ def app(command):
run_update(app_path, jetzt_metadata, jetzt_metadata_file)
elif command == 'remove':
run_remove(app_path, jetzt_metadata, jetzt_metadata_file)
elif command == 'reinstall':
run_reinstall(app_path, jetzt_metadata, jetzt_metadata_file)
elif command == 'create_requirements':
run_create_requirements(app_path, jetzt_metadata, jetzt_metadata_file)
else:
Expand Down
10 changes: 8 additions & 2 deletions jetzt/create_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
metadata = {}

dep_type = ''
silent = False

''' Read existing metadata if available. '''
if os.path.exists(metadata_filename):
Expand All @@ -18,6 +19,9 @@
key, value = arg.split('___')
if key == 'dep_type':
dep_type = value
elif key == 'silent':
if value == 'YES':
silent = True
argv_count += 1

''' List installed packages from metadata. '''
Expand All @@ -27,12 +31,14 @@
if 'dependencies' in metadata:
if isinstance(metadata['dependencies'], dict):
for key, value in metadata['dependencies'].items():
print(f"{key}{value}")
if not silent:
print(f"{key}{value}")
f.write(f"{key}{value}\n")
else:
with open('requirements-dev.txt', 'w') as f:
if 'dev_dependencies' in metadata:
if isinstance(metadata['dev_dependencies'], dict):
for key, value in metadata['dev_dependencies'].items():
print(f"{key}{value}")
if not silent:
print(f"{key}{value}")
f.write(f"{key}{value}\n")

0 comments on commit 3afa968

Please sign in to comment.