Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion random_profile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from pprint import pprint

sys.path.append('.')
from random_profile.main import RandomProfile, VERSION
from random_profile.main import RandomProfile
from random_profile.main import VERSION
from random_profile.api import start_server

parser = argparse.ArgumentParser()
Expand Down
40 changes: 20 additions & 20 deletions random_profile/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
from random_profile.utils import generate_random_height_weight
from random_profile.utils import ASSETS_DIR

VERSION = "1.0.1"

fname_txt = os.path.join(ASSETS_DIR, "fnames.txt")
lname_txt = os.path.join(ASSETS_DIR, "lnames.txt")
hair_colors_txt = os.path.join(ASSETS_DIR, "hair_colors.txt")
blood_types_txt = os.path.join(ASSETS_DIR, "blood_types.txt")
street_names_txt = os.path.join(ASSETS_DIR, "street_names.txt")
cities_name_txt = os.path.join(ASSETS_DIR, "cities_name.txt")
states_names_txt = os.path.join(ASSETS_DIR, "states_names.txt")
job_titles_txt = os.path.join(ASSETS_DIR, "job_titles.txt")
states_hash_json = os.path.join(ASSETS_DIR, "states_hash.json")
VERSION = '1.0.1'

fname_txt = os.path.join(ASSETS_DIR, 'fnames.txt')
lname_txt = os.path.join(ASSETS_DIR, 'lnames.txt')
hair_colors_txt = os.path.join(ASSETS_DIR, 'hair_colors.txt')
blood_types_txt = os.path.join(ASSETS_DIR, 'blood_types.txt')
street_names_txt = os.path.join(ASSETS_DIR, 'street_names.txt')
cities_name_txt = os.path.join(ASSETS_DIR, 'cities_name.txt')
states_names_txt = os.path.join(ASSETS_DIR, 'states_names.txt')
job_titles_txt = os.path.join(ASSETS_DIR, 'job_titles.txt')
states_hash_json = os.path.join(ASSETS_DIR, 'states_hash.json')

# loading data from txt files
fname = load_txt_file(fname_txt)
Expand All @@ -40,15 +40,15 @@


class RandomProfile(object):
""" Random Profile Generator """
''' Random Profile Generator '''
def __init__(self, num: int = 1):
self.num = num

def __str__(self) -> str:
return f"Random Profile Generator version {VERSION}"
return f'Random Profile Generator version {VERSION}'

def __repr__(self) -> str:
return f"RandomProfile(num={self.num})"
return f'RandomProfile(num={self.num})'

def __call__(self, num: int = None) -> List[dict]:
return self.full_profile(num)
Expand Down Expand Up @@ -80,7 +80,7 @@ def last_name(self, num: int = None) -> list:
def full_name(self, num: int = None) -> List[str]:
num = self.num if num is None else num
if num == 1 or num is None:
return f"{random.choice(fname)} {random.choice(lname)}"
return f'{random.choice(fname)} {random.choice(lname)}'
return [random.choice(fname) + ' ' + random.choice(lname) for _ in range(num)]

def ip_address(self, num: int = None) -> List[str]:
Expand Down Expand Up @@ -130,11 +130,11 @@ def generate_address(self, num: int = None) -> List[str]:
zip_code = random.randint(10000, 99999)

address = {
"street_num": street_num,
"street": street,
"city": city,
"state": state,
"zip_code": zip_code
'street_num': street_num,
'street': street,
'city': city,
'state': state,
'zip_code': zip_code
}
address_list.append(address)

Expand Down
10 changes: 10 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Scripts

1. test_changes.sh - Test if the changes are valid and can be released. flake8/pytest are run and the version is checked.
2. test_release.sh - Test the release on test.pypi.org.
3. release.sh - Release the package to PyPI if both tests are successful.


reference links:

- https://packaging.python.org/en/latest/guides/using-testpypi/
49 changes: 49 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
if ! [ -x "$(command -v flake8)" ]; then
echo 'Error: flake8 is not installed.' >&2
echo 'Installing flake8...'
pip install flake8
fi

if ! [ -x "$(command -v twine)" ]; then
echo 'Error: twine is not installed.' >&2
echo 'Installing twine...'
pip install twine
fi

check_command() {
if [ ! -x "$(command -v $1)" ]; then
echo "$1 is not installed"
pip install $1
exit 1
fi
}

# check if the git is installed
check_command git
check_command flake8
check_command twine

if ! [ -f "setup.py" ]; then
echo 'Error: setup.py is not found.' >&2
exit 1
fi

python3 setup.py sdist bdist_wheel

check_directory() {
if [ ! -d "$1" ]; then
echo "$1 is not found"
exit 1
fi
}

# check if the dist folder is exist
check_directory dist

python3 -m twine upload dist/*

rm -rf dist
rm -rf build
rm -rf *.egg-info
find . -name "*.pyc" -exec rm -rf {}\;
29 changes: 29 additions & 0 deletions scripts/test_changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

# function to check the command exist or not
check_command() {
if [ ! -x "$(command -v $1)" ]; then
echo "$1 is not installed"
pip install $1
exit 1
fi
}

# check if the git is installed
check_command git
check_command pytest
check_command flake8

# run flask8 and pytest

flake8
pytest -e

# check the exit code of the last command
if [ $? -eq 0 ]; then
echo "All tests passed"
else
echo "Some tests failed"
exit 1
fi

37 changes: 37 additions & 0 deletions scripts/test_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
check_command() {
if [ ! -x "$(command -v $1)" ]; then
echo "$1 is not installed"
pip install $1
exit 1
fi
}

# check if the git is installed
check_command git
check_command flake8
check_command twine

if ! [ -f "setup.py" ]; then
echo 'Error: setup.py is not found.' >&2
exit 1
fi

python3 setup.py --repository testpypi dist/*

check_directory() {
if [ ! -d "$1" ]; then
echo "$1 is not found"
exit 1
fi
}

# check if the dist folder is exist
check_directory dist

python3 -m twine upload --repository testpypi dist/*

rm -rf dist
rm -rf build
rm -rf *.egg-info
find . -name "*.pyc" -exec rm -rf {}\;
53 changes: 0 additions & 53 deletions scripts/update_package.sh

This file was deleted.