|
1 | | -import click |
2 | | -import os |
3 | | - |
4 | | -# Define a comprehensive list of valid licenses from GitHub |
5 | | -VALID_LICENSES = [ |
6 | | - 'MIT', 'Apache-2.0', 'GPL-3.0', 'LGPL-3.0', 'BSD-2-Clause', 'BSD-3-Clause', |
7 | | - 'CC0-1.0', 'MPL-2.0', 'EPL-2.0', 'AGPL-3.0', 'MIT-0', 'ISC', 'Unlicense' |
8 | | -] |
9 | | - |
10 | | -# Define available classifiers for easier reference |
11 | | -CLASSIFIERS = { |
12 | | - "Development Status": [ |
13 | | - "1 - Planning", "2 - Pre-Alpha", "3 - Alpha", "4 - Beta", "5 - Production/Stable" |
14 | | - ], |
15 | | - "Intended Audience": [ |
16 | | - "Developers", "End Users/Desktop", "Education", "Science/Research", "System Administrators" |
17 | | - ], |
18 | | - "Programming Language": [ |
19 | | - "Python :: 3", "Python :: 3.8", "Python :: 3.9", "Python :: 3.10", "Python :: 3.11" |
20 | | - ], |
21 | | - "License": [ |
22 | | - "OSI Approved :: MIT License", "OSI Approved :: Apache Software License", "OSI Approved :: GPL License" |
23 | | - ], |
24 | | -} |
25 | | - |
26 | | -@click.command() |
27 | | -@click.argument("project_name") |
28 | | -def generate_setup(project_name): |
29 | | - """ |
30 | | - Generate a complete setup.py file for a new Python project, asking the user for all details dynamically. |
31 | | - """ |
32 | | - click.echo("Generating setup.py...") |
33 | | - |
34 | | - # Asking for required details with default values and handling backspace |
35 | | - version = click.prompt("Version (e.g., 0.1.0)", type=str, default="0.1.0") |
36 | | - description = click.prompt("Short project description", type=str) |
37 | | - long_description = click.prompt("Long description (use content from your README.md)", type=str) |
38 | | - author = click.prompt("Author name", type=str) |
39 | | - author_email = click.prompt("Author email", type=str) |
40 | | - |
41 | | - # Handle license validation with retries |
42 | | - while True: |
43 | | - license_type = click.prompt("License type (e.g., MIT, Apache-2.0, GPL-3.0, BSD-3-Clause, etc.)", |
44 | | - type=str, default="MIT") |
45 | | - if license_type in VALID_LICENSES: |
46 | | - break |
47 | | - else: |
48 | | - click.echo( |
49 | | - f"Invalid license type '{license_type}'. Please choose one of the valid licenses: {', '.join(VALID_LICENSES)}") |
50 | | - |
51 | | - python_version = click.prompt("Minimum Python version required (e.g., 3.8)", type=str, default="3.8") |
52 | | - |
53 | | - # Optional fields with defaults if left empty |
54 | | - dependencies = click.prompt("Comma-separated list of dependencies (leave empty for none)", default="", type=str) |
55 | | - dependencies = [dep.strip() for dep in dependencies.split(",") if dep.strip()] |
56 | | - |
57 | | - test_dependencies = click.prompt("Comma-separated list of test dependencies (leave empty for none)", default="", |
58 | | - type=str) |
59 | | - test_dependencies = [dep.strip() for dep in test_dependencies.split(",") if dep.strip()] |
60 | | - |
61 | | - # Asking for URLs |
62 | | - project_url = click.prompt("Project URL (e.g., GitHub URL)", type=str) |
63 | | - bug_tracker_url = click.prompt("Bug tracker URL", type=str) |
64 | | - documentation_url = click.prompt("Documentation URL", type=str) |
65 | | - |
66 | | - # Asking for classifiers (optional but recommended) |
67 | | - click.echo("Select 'Development Status' (e.g., 1 - Planning, 5 - Production/Stable):") |
68 | | - development_status = click.prompt( |
69 | | - "Development Status", type=click.Choice(CLASSIFIERS["Development Status"]), default="1 - Planning" |
70 | | - ) |
71 | | - |
72 | | - click.echo("Select 'Intended Audience' (e.g., Developers, End Users/Desktop):") |
73 | | - audience = click.prompt( |
74 | | - "Intended Audience", type=click.Choice(CLASSIFIERS["Intended Audience"]), default="Developers" |
75 | | - ) |
76 | | - |
77 | | - click.echo("Select 'Programming Language' (e.g., Python 3.8, Python 3.9):") |
78 | | - language = click.prompt( |
79 | | - "Programming Language", type=click.Choice(CLASSIFIERS["Programming Language"]), default="Python :: 3.8" |
80 | | - ) |
81 | | - |
82 | | - # Prepare the content for the setup.py file |
83 | | - setup_content = f""" |
84 | | -from setuptools import setup, find_packages |
85 | | -
|
86 | | -VERSION = "{version}" # Version of your package |
87 | | -DESCRIPTION = '{description}' # Short description |
88 | | -
|
89 | | -# Long description of the project (can be pulled from README.md) |
90 | | -LONG_DESCRIPTION = '''{long_description}''' |
91 | | -
|
92 | | -setup( |
93 | | - name="{project_name}", # Name of your package |
94 | | - version=VERSION, # Package version |
95 | | - author="{author}", # Author name |
96 | | - author_email="{author_email}", # Author's email |
97 | | - description=DESCRIPTION, # Short description |
98 | | - long_description=LONG_DESCRIPTION, # Detailed description from README.md |
99 | | - long_description_content_type="text/markdown", # Format of the long description |
100 | | - url="{project_url}", # URL to the project's GitHub page |
101 | | - packages=find_packages(), # Automatically find all packages in the directory |
102 | | - classifiers=[ # List of classifiers to categorize your package |
103 | | - "Development Status :: {development_status}", |
104 | | - "Intended Audience :: {audience}", |
105 | | - "Programming Language :: {language}", |
106 | | - "License :: OSI Approved :: {license_type}", |
107 | | - "Operating System :: OS Independent", |
108 | | - ], |
109 | | - python_requires=">={python_version}", # Minimum Python version required |
110 | | - install_requires={dependencies}, # List of dependencies |
111 | | - setup_requires=["pytest-runner"], # For running tests during installation |
112 | | - tests_require={test_dependencies}, # Specify dependencies needed for running tests |
113 | | - license="{license_type}", # License under which the project is released |
114 | | - project_urls={{ # Additional URLs related to your project |
115 | | - "Source Code": "{project_url}", |
116 | | - "Bug Tracker": "{bug_tracker_url}", |
117 | | - "Documentation": "{documentation_url}", |
118 | | - }}, |
119 | | -) |
120 | | -
|
121 | | -""" |
122 | | - |
123 | | - # Ensure the project folder exists, and create the setup.py file |
124 | | - if not os.path.exists(project_name): |
125 | | - os.makedirs(project_name) |
126 | | - |
127 | | - with open(f"{project_name}/setup.py", "w") as f: |
128 | | - f.write(setup_content) |
129 | | - |
130 | | - print(f"setup.py has been successfully generated for project '{project_name}'.") |
131 | | - |
132 | | -if __name__ == "__main__": |
133 | | - generate_setup() |
| 1 | +import click |
| 2 | +import os |
| 3 | + |
| 4 | +# Define a comprehensive list of valid licenses from GitHub |
| 5 | +VALID_LICENSES = [ |
| 6 | + 'MIT', 'Apache-2.0', 'GPL-3.0', 'LGPL-3.0', 'BSD-2-Clause', 'BSD-3-Clause', |
| 7 | + 'CC0-1.0', 'MPL-2.0', 'EPL-2.0', 'AGPL-3.0', 'MIT-0', 'ISC', 'Unlicense' |
| 8 | +] |
| 9 | + |
| 10 | +# Define available classifiers for easier reference |
| 11 | +CLASSIFIERS = { |
| 12 | + "Development Status": [ |
| 13 | + "1 - Planning", "2 - Pre-Alpha", "3 - Alpha", "4 - Beta", "5 - Production/Stable" |
| 14 | + ], |
| 15 | + "Intended Audience": [ |
| 16 | + "Developers", "End Users/Desktop", "Education", "Science/Research", "System Administrators" |
| 17 | + ], |
| 18 | + "Programming Language": [ |
| 19 | + "Python :: 3", "Python :: 3.8", "Python :: 3.9", "Python :: 3.10", "Python :: 3.11" |
| 20 | + ], |
| 21 | + "License": [ |
| 22 | + "OSI Approved :: MIT License", "OSI Approved :: Apache Software License", "OSI Approved :: GPL License" |
| 23 | + ], |
| 24 | +} |
| 25 | + |
| 26 | +@click.command() |
| 27 | +@click.argument("project_name") |
| 28 | +def generate_setup(project_name): |
| 29 | + """ |
| 30 | + Generate a complete setup.py file for a new Python project, asking the user for all details dynamically. |
| 31 | + """ |
| 32 | + click.echo("Generating setup.py...") |
| 33 | + |
| 34 | + # Asking for required details with default values and handling backspace |
| 35 | + version = click.prompt("Version (e.g., 0.1.0)", type=str, default="0.1.0") |
| 36 | + description = click.prompt("Short project description", type=str) |
| 37 | + long_description = click.prompt("Long description (use content from your README.md)", type=str) |
| 38 | + author = click.prompt("Author name", type=str) |
| 39 | + author_email = click.prompt("Author email", type=str) |
| 40 | + |
| 41 | + # Handle license validation with retries |
| 42 | + while True: |
| 43 | + license_type = click.prompt("License type (e.g., MIT, Apache-2.0, GPL-3.0, BSD-3-Clause, etc.)", |
| 44 | + type=str, default="MIT") |
| 45 | + if license_type in VALID_LICENSES: |
| 46 | + break |
| 47 | + else: |
| 48 | + click.echo( |
| 49 | + f"Invalid license type '{license_type}'. Please choose one of the valid licenses: {', '.join(VALID_LICENSES)}") |
| 50 | + |
| 51 | + python_version = click.prompt("Minimum Python version required (e.g., 3.8)", type=str, default="3.8") |
| 52 | + |
| 53 | + # Optional fields with defaults if left empty |
| 54 | + dependencies = click.prompt("Comma-separated list of dependencies (leave empty for none)", default="", type=str) |
| 55 | + dependencies = [dep.strip() for dep in dependencies.split(",") if dep.strip()] |
| 56 | + |
| 57 | + test_dependencies = click.prompt("Comma-separated list of test dependencies (leave empty for none)", default="", |
| 58 | + type=str) |
| 59 | + test_dependencies = [dep.strip() for dep in test_dependencies.split(",") if dep.strip()] |
| 60 | + |
| 61 | + # Asking for URLs |
| 62 | + project_url = click.prompt("Project URL (e.g., GitHub URL)", type=str) |
| 63 | + bug_tracker_url = click.prompt("Bug tracker URL", type=str) |
| 64 | + documentation_url = click.prompt("Documentation URL", type=str) |
| 65 | + |
| 66 | + # Asking for classifiers (optional but recommended) |
| 67 | + click.echo("Select 'Development Status' (e.g., 1 - Planning, 5 - Production/Stable):") |
| 68 | + development_status = click.prompt( |
| 69 | + "Development Status", type=click.Choice(CLASSIFIERS["Development Status"]), default="1 - Planning" |
| 70 | + ) |
| 71 | + |
| 72 | + click.echo("Select 'Intended Audience' (e.g., Developers, End Users/Desktop):") |
| 73 | + audience = click.prompt( |
| 74 | + "Intended Audience", type=click.Choice(CLASSIFIERS["Intended Audience"]), default="Developers" |
| 75 | + ) |
| 76 | + |
| 77 | + click.echo("Select 'Programming Language' (e.g., Python 3.8, Python 3.9):") |
| 78 | + language = click.prompt( |
| 79 | + "Programming Language", type=click.Choice(CLASSIFIERS["Programming Language"]), default="Python :: 3.8" |
| 80 | + ) |
| 81 | + |
| 82 | + # Prepare the content for the setup.py file |
| 83 | + setup_content = f""" |
| 84 | +from setuptools import setup, find_packages |
| 85 | +
|
| 86 | +VERSION = "{version}" # Version of your package |
| 87 | +DESCRIPTION = '{description}' # Short description |
| 88 | +
|
| 89 | +# Long description of the project (can be pulled from README.md) |
| 90 | +LONG_DESCRIPTION = '''{long_description}''' |
| 91 | +
|
| 92 | +setup( |
| 93 | + name="{project_name}", # Name of your package |
| 94 | + version=VERSION, # Package version |
| 95 | + author="{author}", # Author name |
| 96 | + author_email="{author_email}", # Author's email |
| 97 | + description=DESCRIPTION, # Short description |
| 98 | + long_description=LONG_DESCRIPTION, # Detailed description from README.md |
| 99 | + long_description_content_type="text/markdown", # Format of the long description |
| 100 | + url="{project_url}", # URL to the project's GitHub page |
| 101 | + packages=find_packages(), # Automatically find all packages in the directory |
| 102 | + classifiers=[ # List of classifiers to categorize your package |
| 103 | + "Development Status :: {development_status}", |
| 104 | + "Intended Audience :: {audience}", |
| 105 | + "Programming Language :: {language}", |
| 106 | + "License :: OSI Approved :: {license_type}", |
| 107 | + "Operating System :: OS Independent", |
| 108 | + ], |
| 109 | + python_requires=">={python_version}", # Minimum Python version required |
| 110 | + install_requires={dependencies}, # List of dependencies |
| 111 | + setup_requires=["pytest-runner"], # For running tests during installation |
| 112 | + tests_require={test_dependencies}, # Specify dependencies needed for running tests |
| 113 | + license="{license_type}", # License under which the project is released |
| 114 | + project_urls={{ # Additional URLs related to your project |
| 115 | + "Source Code": "{project_url}", |
| 116 | + "Bug Tracker": "{bug_tracker_url}", |
| 117 | + "Documentation": "{documentation_url}", |
| 118 | + }}, |
| 119 | +) |
| 120 | +
|
| 121 | +""" |
| 122 | + |
| 123 | + # Ensure the project folder exists, and create the setup.py file |
| 124 | + if not os.path.exists(project_name): |
| 125 | + os.makedirs(project_name) |
| 126 | + |
| 127 | + with open(f"{project_name}/setup.py", "w") as f: |
| 128 | + f.write(setup_content) |
| 129 | + |
| 130 | + print(f"setup.py has been successfully generated for project '{project_name}'.") |
| 131 | + |
| 132 | +if __name__ == "__main__": |
| 133 | + generate_setup() |
0 commit comments