Skip to content

Commit 3211724

Browse files
added help docs (#3)
1 parent de80230 commit 3211724

File tree

3 files changed

+268
-168
lines changed

3 files changed

+268
-168
lines changed

setup.py

+9-46
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from setuptools import setup, find_packages
22

3+
from setups.help import usage_instructions
4+
35
VERSION = "0.0.2" # Version of your package
46
DESCRIPTION = 'Setups: Dynamically generate setup.py for Python projects.'
57

@@ -35,7 +37,9 @@
3537
'wheel', # Add wheel to create binary distributions
3638
],
3739
setup_requires=['pytest-runner'], # For running tests during installation
38-
tests_require=['pytest'], # Dependencies for running tests
40+
extras_require={ # Replacing 'tests_require' with 'extras_require'
41+
'tests': ['pytest'], # Optional testing dependencies
42+
},
3943
license='MIT', # License for the project
4044
project_urls={ # Additional URLs related to your project
4145
'Source Code': 'https://github.com/muhammad-fiaz/setups-python',
@@ -50,56 +54,15 @@
5054
)
5155

5256
# Guide for the user after installation
53-
print("""
57+
print(r"""
5458
**************************************************
5559
Installation Complete!
5660
57-
Once you've installed the package, you can now use the 'setup' command to generate setup.py for your Python project.
58-
59-
Usage:
60-
setup <project_name>
61-
62-
This will ask you a series of questions to generate a setup.py file for your project. Once the setup.py is generated:
63-
64-
🎉 Here's what you need to do next to upload your package to PyPI:
65-
66-
Step 1: Create the Distribution
67-
--------------------------------
68-
Run the following commands to build the distribution:
69-
70-
python setup.py sdist bdist_wheel
71-
72-
This creates both source (.tar.gz) and wheel (.whl) distributions in the dist/ folder.
73-
74-
Step 2: Upload to PyPI
75-
-----------------------
76-
Once you've built the distribution, upload it to PyPI with the following:
77-
78-
twine upload dist/*
79-
80-
This will prompt you for your PyPI credentials and upload your package.
81-
82-
You're all set to share your package with the world! 🚀
83-
84-
-------------------
85-
| _______________ |
86-
| |XXXXXXXXXXXXX| |
87-
| |XXXXXXXXXXXXX| |
88-
| |XXXXXXXXXXXXX| |
89-
| |XXXXXXXXXXXXX| |
90-
| |XXXXXXXXXXXXX| |
91-
|_________________|
92-
_[_______]_
93-
___[___________]___
94-
| [_____] []|__
95-
| [_____] []| \__
96-
L___________________J \ \___\/
97-
___________________ /\\
98-
/###################\\ (__)
99-
10061
Thank you for using our tool. For more details on usage, please refer to the documentation:
10162
https://github.com/muhammad-fiaz/setups-python#usage
10263
64+
""")
65+
usage_instructions()
66+
print(r"""
10367
**************************************************
10468
""")
105-

setups/cli.py

+135-122
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,135 @@
1-
import click
2-
3-
# Define a comprehensive list of valid licenses from GitHub
4-
VALID_LICENSES = [
5-
'MIT', 'Apache-2.0', 'GPL-3.0', 'LGPL-3.0', 'BSD-2-Clause', 'BSD-3-Clause',
6-
'CC0-1.0', 'MPL-2.0', 'EPL-2.0', 'AGPL-3.0', 'MIT-0', 'ISC', 'Unlicense'
7-
]
8-
9-
# Define available classifiers for easier reference
10-
DEFAULT_CLASSIFIERS = [
11-
"Development Status :: 5 - Production/Stable",
12-
"Intended Audience :: Developers",
13-
"Programming Language :: Python :: 3",
14-
"License :: OSI Approved :: MIT",
15-
"Operating System :: OS Independent"
16-
]
17-
18-
@click.command()
19-
@click.argument("project_name")
20-
def generate_setup(project_name):
21-
"""
22-
Generate a complete setup.py and README.md file for a new Python project, asking the user for all details dynamically.
23-
"""
24-
click.echo("Generating setup.py and README.md...")
25-
26-
# Asking for required details
27-
version = click.prompt("Version (e.g., 0.1.0)", type=str, default="0.1.0")
28-
description = click.prompt("Short project description (optional)", type=str, default="")
29-
long_description = click.prompt("Long description (optional, use content from your README.md)", type=str, default="")
30-
31-
# Author info now optional
32-
author = click.prompt("Author name (optional)", type=str, default="")
33-
author_email = click.prompt("Author email (optional)", type=str, default="")
34-
35-
# Asking for license selection by index
36-
click.echo("Select a license:")
37-
for idx, license in enumerate(VALID_LICENSES):
38-
click.echo(f"{idx}. {license}")
39-
license_idx = click.prompt("License (Enter the index number)", type=int, default=0)
40-
license_type = VALID_LICENSES[license_idx]
41-
42-
python_version = click.prompt("Minimum Python version required (e.g., 3.8)", type=str, default="3.8")
43-
44-
# Optional fields with defaults if left empty
45-
dependencies = click.prompt("Comma-separated list of dependencies (leave empty for none)", default="", type=str)
46-
dependencies = [dep.strip() for dep in dependencies.split(",") if dep.strip()]
47-
48-
test_dependencies = click.prompt("Comma-separated list of test dependencies (leave empty for none)", default="",
49-
type=str)
50-
test_dependencies = [dep.strip() for dep in test_dependencies.split(",") if dep.strip()]
51-
52-
# URLs now optional
53-
project_url = click.prompt("Project URL (optional)", type=str, default="")
54-
bug_tracker_url = click.prompt("Bug tracker URL (optional)", type=str, default="")
55-
documentation_url = click.prompt("Documentation URL (optional)", type=str, default="")
56-
57-
# Ask if the user wants to specify classifiers
58-
click.echo("Would you like to specify 'Development Status', 'Intended Audience', and 'Programming Language'?")
59-
use_classifiers = click.confirm("Specify classifiers?", default=False)
60-
61-
classifiers = DEFAULT_CLASSIFIERS
62-
if use_classifiers:
63-
# Development Status
64-
development_status = click.prompt("Select 'Development Status' (e.g., 1 - Planning, 2 - Pre-Alpha, etc.)", type=str, default="5 - Production/Stable")
65-
classifiers[0] = f"Development Status :: {development_status}"
66-
67-
# Intended Audience
68-
audience = click.prompt("Select 'Intended Audience' (e.g., Developers, Education, etc.)", type=str, default="Developers")
69-
classifiers[1] = f"Intended Audience :: {audience}"
70-
71-
# Programming Language
72-
language = click.prompt("Select 'Programming Language' (e.g., Python :: 3)", type=str, default="Python :: 3")
73-
classifiers[2] = f"Programming Language :: {language}"
74-
75-
# Prepare the content for the README.md file
76-
readme_content = f"# {project_name}\n\n{long_description if long_description else 'Project description'}\n"
77-
78-
# Prepare the content for the setup.py file
79-
setup_content = f"""
80-
from setuptools import setup, find_packages
81-
82-
VERSION = "{version}" # Version of your package
83-
DESCRIPTION = '{description if description else "Project description"}' # Short description
84-
85-
# Long description of the project (can be pulled from README.md)
86-
LONG_DESCRIPTION = '''{long_description if long_description else 'Detailed project description from README.md'}'''
87-
88-
setup(
89-
name="{project_name}", # Name of your package
90-
version=VERSION, # Package version
91-
author="{author if author else ''}", # Author name
92-
author_email="{author_email if author_email else ''}", # Author's email
93-
description=DESCRIPTION, # Short description
94-
long_description=LONG_DESCRIPTION, # Detailed description from README.md
95-
long_description_content_type="text/markdown", # Format of the long description
96-
url="{project_url if project_url else ''}", # URL to the project's GitHub page
97-
packages=find_packages(), # Automatically find all packages in the directory
98-
classifiers={classifiers}, # List of classifiers to categorize your package
99-
python_requires=">={python_version}", # Minimum Python version required
100-
install_requires={dependencies}, # List of dependencies
101-
setup_requires=["pytest-runner"], # For running tests during installation
102-
tests_require={test_dependencies}, # Specify dependencies needed for running tests
103-
license="{license_type}", # License under which the project is released
104-
project_urls={{ # Additional URLs related to your project
105-
"Source Code": "{project_url}" ,
106-
"Bug Tracker": "{bug_tracker_url}",
107-
"Documentation": "{documentation_url}",
108-
}},
109-
)
110-
"""
111-
112-
# Create the README.md and setup.py files in the current directory
113-
with open("README.md", "w") as readme_file:
114-
readme_file.write(readme_content)
115-
116-
with open("setup.py", "w") as setup_file:
117-
setup_file.write(setup_content)
118-
119-
print(f"README.md and setup.py have been successfully generated for project '{project_name}'.")
120-
121-
if __name__ == "__main__":
122-
generate_setup()
1+
import sys
2+
3+
import click
4+
5+
from setups.help import print_help
6+
7+
# Define a comprehensive list of valid licenses from GitHub
8+
VALID_LICENSES = [
9+
'MIT', 'Apache-2.0', 'GPL-3.0', 'LGPL-3.0', 'BSD-2-Clause', 'BSD-3-Clause',
10+
'CC0-1.0', 'MPL-2.0', 'EPL-2.0', 'AGPL-3.0', 'MIT-0', 'ISC', 'Unlicense'
11+
]
12+
13+
# Define available classifiers for easier reference
14+
DEFAULT_CLASSIFIERS = [
15+
"Development Status :: 5 - Production/Stable",
16+
"Intended Audience :: Developers",
17+
"Programming Language :: Python :: 3",
18+
"License :: OSI Approved :: MIT",
19+
"Operating System :: OS Independent"
20+
]
21+
22+
@click.command(help="Generate a complete setup.py and README.md file for a new Python project.")
23+
@click.argument("project_name", required=False)
24+
@click.option('--help', '-h', is_flag=True, help="Show this message and exit.")
25+
def generate_setup(project_name, help):
26+
if help:
27+
print_help()
28+
else:
29+
if not project_name:
30+
click.echo("Error: Missing argument 'PROJECT_NAME'.")
31+
click.echo(generate_setup.get_help(click.Context(generate_setup)))
32+
return
33+
34+
"""
35+
Generate a complete setup.py and README.md file for a new Python project, asking the user for all details dynamically.
36+
"""
37+
click.echo("Generating setup.py and README.md...")
38+
39+
# Asking for required details
40+
version = click.prompt("Version (e.g., 0.1.0)", type=str, default="0.1.0")
41+
description = click.prompt("Short project description (optional)", type=str, default="")
42+
long_description = click.prompt("Long description (optional, use content from your README.md)", type=str, default="")
43+
44+
# Author info now optional
45+
author = click.prompt("Author name (optional)", type=str, default="")
46+
author_email = click.prompt("Author email (optional)", type=str, default="")
47+
48+
# Asking for license selection by index
49+
click.echo("Select a license:")
50+
for idx, license in enumerate(VALID_LICENSES):
51+
click.echo(f"{idx}. {license}")
52+
license_idx = click.prompt("License (Enter the index number)", type=int, default=0)
53+
license_type = VALID_LICENSES[license_idx]
54+
55+
python_version = click.prompt("Minimum Python version required (e.g., 3.8)", type=str, default="3.8")
56+
57+
# Optional fields with defaults if left empty
58+
dependencies = click.prompt("Comma-separated list of dependencies (leave empty for none)", default="", type=str)
59+
dependencies = [dep.strip() for dep in dependencies.split(",") if dep.strip()]
60+
61+
test_dependencies = click.prompt("Comma-separated list of test dependencies (leave empty for none)", default="",
62+
type=str)
63+
test_dependencies = [dep.strip() for dep in test_dependencies.split(",") if dep.strip()]
64+
65+
# URLs now optional
66+
project_url = click.prompt("Project URL (optional)", type=str, default="")
67+
bug_tracker_url = click.prompt("Bug tracker URL (optional)", type=str, default="")
68+
documentation_url = click.prompt("Documentation URL (optional)", type=str, default="")
69+
70+
# Ask if the user wants to specify classifiers
71+
click.echo("Would you like to specify 'Development Status', 'Intended Audience', and 'Programming Language'?")
72+
use_classifiers = click.confirm("Specify classifiers?", default=False)
73+
74+
classifiers = DEFAULT_CLASSIFIERS
75+
if use_classifiers:
76+
# Development Status
77+
development_status = click.prompt("Select 'Development Status' (e.g., 1 - Planning, 2 - Pre-Alpha, etc.)", type=str, default="5 - Production/Stable")
78+
classifiers[0] = f"Development Status :: {development_status}"
79+
80+
# Intended Audience
81+
audience = click.prompt("Select 'Intended Audience' (e.g., Developers, Education, etc.)", type=str, default="Developers")
82+
classifiers[1] = f"Intended Audience :: {audience}"
83+
84+
# Programming Language
85+
language = click.prompt("Select 'Programming Language' (e.g., Python :: 3)", type=str, default="Python :: 3")
86+
classifiers[2] = f"Programming Language :: {language}"
87+
88+
# Prepare the content for the README.md file
89+
readme_content = f"# {project_name}\n\n{long_description if long_description else 'Project description'}\n"
90+
91+
# Prepare the content for the setup.py file
92+
setup_content = f"""
93+
from setuptools import setup, find_packages
94+
95+
VERSION = "{version}" # Version of your package
96+
DESCRIPTION = '{description if description else "Project description"}' # Short description
97+
98+
# Long description of the project (can be pulled from README.md)
99+
LONG_DESCRIPTION = '''{long_description if long_description else 'Detailed project description from README.md'}'''
100+
101+
setup(
102+
name="{project_name}", # Name of your package
103+
version=VERSION, # Package version
104+
author="{author if author else ''}", # Author name
105+
author_email="{author_email if author_email else ''}", # Author's email
106+
description=DESCRIPTION, # Short description
107+
long_description=LONG_DESCRIPTION, # Detailed description from README.md
108+
long_description_content_type="text/markdown", # Format of the long description
109+
url="{project_url if project_url else ''}", # URL to the project's GitHub page
110+
packages=find_packages(), # Automatically find all packages in the directory
111+
classifiers={classifiers}, # List of classifiers to categorize your package
112+
python_requires=">={python_version}", # Minimum Python version required
113+
install_requires={dependencies}, # List of dependencies
114+
setup_requires=["pytest-runner"], # For running tests during installation
115+
extras_require={{'test': {test_dependencies}}},
116+
license="{license_type}", # License under which the project is released
117+
project_urls={{ # Additional URLs related to your project
118+
"Source Code": "{project_url}"
119+
"Bug Tracker": "{bug_tracker_url}"
120+
"Documentation": "{documentation_url}"
121+
}},
122+
)
123+
"""
124+
125+
# Create the README.md and setup.py files in the current directory
126+
with open("README.md", "w") as readme_file:
127+
readme_file.write(readme_content)
128+
129+
with open("setup.py", "w") as setup_file:
130+
setup_file.write(setup_content)
131+
132+
print(f"README.md and setup.py have been successfully generated for project '{project_name}'.")
133+
134+
if __name__ == "__main__":
135+
generate_setup()

0 commit comments

Comments
 (0)