Skip to content

Commit 69e3bcd

Browse files
Merge pull request #5 from JordanWelsman/command-line
Fixed merge conflict with #7. Added command-line features to setup file. To-do list complete. Merging now.
2 parents d8c08f8 + 65e0d85 commit 69e3bcd

File tree

1 file changed

+70
-20
lines changed

1 file changed

+70
-20
lines changed

setup.py

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,73 @@
1+
# Module imports
2+
import sys
3+
import os
14
from setuptools import setup
25

3-
with open("README.md", "r") as fh:
4-
long_description = fh.read()
6+
# Terminal formatting
7+
class color:
8+
DEFAULT = '\033[39m'
9+
BLACK = '\033[30m'
10+
RED = '\033[31m'
11+
GREEN = '\033[32m'
12+
YELLOW = '\033[33m'
13+
BLUE = '\033[34m'
14+
MAGENTA = '\033[35m'
15+
CYAN = '\033[36m'
16+
LIGHTGRAY = '\033[37m'
17+
DARKGRAY = '\033[90m'
18+
LIGHTRED = '\033[91m'
19+
LIGHTGREEN = '\033[92m'
20+
LIGHTYELLOW = '\033[93m'
21+
LIGHTBLUE = '\033[94m'
22+
LIGHTMAGENTA = '\033[95m'
23+
LIGHTCYAN = '\033[96m'
24+
WHITE = '\033[97m'
525

6-
setup(
7-
name = 'mathplug',
8-
version = '0.0.2',
9-
description = 'A lightweight Python package which supplies simple math functions.',
10-
long_description = long_description,
11-
long_description_content_type = 'text/markdown',
12-
author = 'Jordan Welsman',
13-
author_email = 'jordan.welsman@outlook.com',
14-
url = 'https://github.com/JordanWelsman/mathplug/',
15-
py_modules = ["__init__", "mathplug", "test_mathplug"],
16-
classifiers = ["Development Status :: 2 - Pre-Alpha", "Intended Audience :: Other Audience", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.9", "Topic :: Scientific/Engineering :: Mathematics"],
17-
package_dir = {'': 'mathplug'},
18-
extras_require = {
19-
"dev": [
20-
"pytest >= 7.1",
21-
],
22-
},
23-
)
26+
27+
# Python 3 assertion
28+
assert sys.version_info.major >= 3, f"{color.LIGHTRED}Python version must be 3 or higher."
29+
30+
# Arguments
31+
args = sys.argv
32+
num_args = len(args)
33+
program_name = args[0]
34+
version = "0.0.1"
35+
run_pytest_after_setup = False
36+
37+
def run_program():
38+
if (num_args > 1): # if arguments are passed
39+
arg = args[1]
40+
match arg:
41+
case '-v' | '--version': # display version number
42+
print(f"Running {color.DARKGRAY}mathplug{color.DEFAULT} version {color.GREEN}v{version}{color.DEFAULT}.")
43+
case 'bdist_wheel': # create package files
44+
with open("README.md", "r") as fh:
45+
long_description = fh.read()
46+
47+
setup(
48+
name = 'mathplug',
49+
version = '0.0.2',
50+
description = 'A lightweight Python package which supplies simple math functions.',
51+
long_description = long_description,
52+
long_description_content_type = 'text/markdown',
53+
author = 'Jordan Welsman',
54+
author_email = 'jordan.welsman@outlook.com',
55+
url = 'https://github.com/JordanWelsman/mathplug/',
56+
py_modules = ["__init__", "mathplug", "test_mathplug"],
57+
classifiers = ["Development Status :: 2 - Pre-Alpha", "Intended Audience :: Other Audience", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.9", "Topic :: Scientific/Engineering :: Mathematics"],
58+
package_dir = {'': 'mathplug'},
59+
extras_require = {
60+
"dev": [
61+
"pytest >= 7.1",
62+
],
63+
},
64+
)
65+
if run_pytest_after_setup:
66+
os.system("pytest")
67+
case other: # incorrect
68+
print(f"{color.RED}ERROR: {color.LIGHTRED}argument not recognized:{color.DEFAULT} {other}")
69+
else:
70+
print(f"If no arguments are required, use {color.GREEN}<python | python3> <setup.py> <bdist_wheel> {color.DEFAULT} to run setup.")
71+
72+
# Run the program
73+
run_program()

0 commit comments

Comments
 (0)