diff --git a/random_profile/cli.py b/random_profile/cli.py index cdb9e32..b9225cb 100644 --- a/random_profile/cli.py +++ b/random_profile/cli.py @@ -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() diff --git a/random_profile/main.py b/random_profile/main.py index 2f21bcc..663d891 100644 --- a/random_profile/main.py +++ b/random_profile/main.py @@ -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) @@ -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) @@ -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]: @@ -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) diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..7228ca3 --- /dev/null +++ b/scripts/README.md @@ -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/ diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100644 index 0000000..d4d7ee1 --- /dev/null +++ b/scripts/release.sh @@ -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 {}\; diff --git a/scripts/test_changes.sh b/scripts/test_changes.sh new file mode 100644 index 0000000..cbd426f --- /dev/null +++ b/scripts/test_changes.sh @@ -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 + diff --git a/scripts/test_release.sh b/scripts/test_release.sh new file mode 100644 index 0000000..9755187 --- /dev/null +++ b/scripts/test_release.sh @@ -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 {}\; diff --git a/scripts/update_package.sh b/scripts/update_package.sh deleted file mode 100644 index 3faa61f..0000000 --- a/scripts/update_package.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -# Update package on pypi server - -# check for flake8 and twine and install if not present -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 for setup.py -if ! [ -f "setup.py" ]; then - echo 'Error: setup.py is not found.' >&2 - exit 1 -fi - - -# run sdists and wheels -python3 setup.py sdist bdist_wheel - -# check for dist folder -if ! [ -d "dist" ]; then - echo 'Error: dist folder is not found.' >&2 - exit 1 -fi - - -read -p "Do you want to upload to pypi? (y/n) " -n 1 -r -echo -if [[ $REPLY =~ ^[Yy]$ ]] -then - python3 -m twine upload dist/* -fi - - -# remove dist folder -rm -rf dist - -# remove build folder -rm -rf build - -# remove .egg-info folder -rm -rf *.egg-info - -# remove .pyc files -find . -name "*.pyc" -exec rm -rf {} \;