Skip to content

Commit 41da8a2

Browse files
adding scripts for release automation (Py-Contributors#49)
1 parent 97a1096 commit 41da8a2

File tree

7 files changed

+147
-74
lines changed

7 files changed

+147
-74
lines changed

random_profile/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from pprint import pprint
55

66
sys.path.append('.')
7-
from random_profile.main import RandomProfile, VERSION
7+
from random_profile.main import RandomProfile
8+
from random_profile.main import VERSION
89
from random_profile.api import start_server
910

1011
parser = argparse.ArgumentParser()

random_profile/main.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
from random_profile.utils import generate_random_height_weight
1717
from random_profile.utils import ASSETS_DIR
1818

19-
VERSION = "1.0.1"
20-
21-
fname_txt = os.path.join(ASSETS_DIR, "fnames.txt")
22-
lname_txt = os.path.join(ASSETS_DIR, "lnames.txt")
23-
hair_colors_txt = os.path.join(ASSETS_DIR, "hair_colors.txt")
24-
blood_types_txt = os.path.join(ASSETS_DIR, "blood_types.txt")
25-
street_names_txt = os.path.join(ASSETS_DIR, "street_names.txt")
26-
cities_name_txt = os.path.join(ASSETS_DIR, "cities_name.txt")
27-
states_names_txt = os.path.join(ASSETS_DIR, "states_names.txt")
28-
job_titles_txt = os.path.join(ASSETS_DIR, "job_titles.txt")
29-
states_hash_json = os.path.join(ASSETS_DIR, "states_hash.json")
19+
VERSION = '1.0.1'
20+
21+
fname_txt = os.path.join(ASSETS_DIR, 'fnames.txt')
22+
lname_txt = os.path.join(ASSETS_DIR, 'lnames.txt')
23+
hair_colors_txt = os.path.join(ASSETS_DIR, 'hair_colors.txt')
24+
blood_types_txt = os.path.join(ASSETS_DIR, 'blood_types.txt')
25+
street_names_txt = os.path.join(ASSETS_DIR, 'street_names.txt')
26+
cities_name_txt = os.path.join(ASSETS_DIR, 'cities_name.txt')
27+
states_names_txt = os.path.join(ASSETS_DIR, 'states_names.txt')
28+
job_titles_txt = os.path.join(ASSETS_DIR, 'job_titles.txt')
29+
states_hash_json = os.path.join(ASSETS_DIR, 'states_hash.json')
3030

3131
# loading data from txt files
3232
fname = load_txt_file(fname_txt)
@@ -40,15 +40,15 @@
4040

4141

4242
class RandomProfile(object):
43-
""" Random Profile Generator """
43+
''' Random Profile Generator '''
4444
def __init__(self, num: int = 1):
4545
self.num = num
4646

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

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

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

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

132132
address = {
133-
"street_num": street_num,
134-
"street": street,
135-
"city": city,
136-
"state": state,
137-
"zip_code": zip_code
133+
'street_num': street_num,
134+
'street': street,
135+
'city': city,
136+
'state': state,
137+
'zip_code': zip_code
138138
}
139139
address_list.append(address)
140140

scripts/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Scripts
2+
3+
1. test_changes.sh - Test if the changes are valid and can be released. flake8/pytest are run and the version is checked.
4+
2. test_release.sh - Test the release on test.pypi.org.
5+
3. release.sh - Release the package to PyPI if both tests are successful.
6+
7+
8+
reference links:
9+
10+
- https://packaging.python.org/en/latest/guides/using-testpypi/

scripts/release.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
if ! [ -x "$(command -v flake8)" ]; then
3+
echo 'Error: flake8 is not installed.' >&2
4+
echo 'Installing flake8...'
5+
pip install flake8
6+
fi
7+
8+
if ! [ -x "$(command -v twine)" ]; then
9+
echo 'Error: twine is not installed.' >&2
10+
echo 'Installing twine...'
11+
pip install twine
12+
fi
13+
14+
check_command() {
15+
if [ ! -x "$(command -v $1)" ]; then
16+
echo "$1 is not installed"
17+
pip install $1
18+
exit 1
19+
fi
20+
}
21+
22+
# check if the git is installed
23+
check_command git
24+
check_command flake8
25+
check_command twine
26+
27+
if ! [ -f "setup.py" ]; then
28+
echo 'Error: setup.py is not found.' >&2
29+
exit 1
30+
fi
31+
32+
python3 setup.py sdist bdist_wheel
33+
34+
check_directory() {
35+
if [ ! -d "$1" ]; then
36+
echo "$1 is not found"
37+
exit 1
38+
fi
39+
}
40+
41+
# check if the dist folder is exist
42+
check_directory dist
43+
44+
python3 -m twine upload dist/*
45+
46+
rm -rf dist
47+
rm -rf build
48+
rm -rf *.egg-info
49+
find . -name "*.pyc" -exec rm -rf {}\;

scripts/test_changes.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
# function to check the command exist or not
4+
check_command() {
5+
if [ ! -x "$(command -v $1)" ]; then
6+
echo "$1 is not installed"
7+
pip install $1
8+
exit 1
9+
fi
10+
}
11+
12+
# check if the git is installed
13+
check_command git
14+
check_command pytest
15+
check_command flake8
16+
17+
# run flask8 and pytest
18+
19+
flake8
20+
pytest -e
21+
22+
# check the exit code of the last command
23+
if [ $? -eq 0 ]; then
24+
echo "All tests passed"
25+
else
26+
echo "Some tests failed"
27+
exit 1
28+
fi
29+

scripts/test_release.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
check_command() {
3+
if [ ! -x "$(command -v $1)" ]; then
4+
echo "$1 is not installed"
5+
pip install $1
6+
exit 1
7+
fi
8+
}
9+
10+
# check if the git is installed
11+
check_command git
12+
check_command flake8
13+
check_command twine
14+
15+
if ! [ -f "setup.py" ]; then
16+
echo 'Error: setup.py is not found.' >&2
17+
exit 1
18+
fi
19+
20+
python3 setup.py --repository testpypi dist/*
21+
22+
check_directory() {
23+
if [ ! -d "$1" ]; then
24+
echo "$1 is not found"
25+
exit 1
26+
fi
27+
}
28+
29+
# check if the dist folder is exist
30+
check_directory dist
31+
32+
python3 -m twine upload --repository testpypi dist/*
33+
34+
rm -rf dist
35+
rm -rf build
36+
rm -rf *.egg-info
37+
find . -name "*.pyc" -exec rm -rf {}\;

scripts/update_package.sh

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)