diff --git a/README.md b/README.md index 6638fe2..f1302ab 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pico-project-generator -This is a command line or GUI tool, written in Python, to automatically generate a Pico C SDK Project. +This is a command line or GUI tool, written in Python, to automatically generate a Raspberry Pi Pico C/C++ SDK Project. The tool will generate all required CMake files, program files and VSCode IDE files for the set of features requested. @@ -43,8 +43,6 @@ optional arguments: You can list the features supported by the tools by using `./pico_project --list`. These features can be added to the project using the `--feature` options, this can be used multiple times. - - ## GUI version The GUI version of the tool, run by adding `--gui` to the command line, uses `tkinter` to provide a platform agnostic script that will run on Linux, Mac and Windows. All the options from the command line tool are also supported in the GUI. @@ -77,10 +75,15 @@ Create VSCode Project | As well as the CMake files, also create the appropriate Debugger | Use the specified debugger in the IDE +## Optional: Installation using Python Pip (Linux) +This application can **optionally** be installed to your system using standard Python installation tools. If you would like to do so, follow the instructions below. If you do not wish to install the application, you can run it from the the pico_project directory. +Clone the repository with: `$ git clone https://github.com/raspberrypi/pico-project-generator`. Change to the repository's directory with: `$ cd pico-project-generator`. +The package can then be installed for the current user using: `$ pip install .`, or for all users using `$ sudo pip install .`. +You can now run the application from any directory with `$ pico_project` plus any arguments detailed in this README, e.g. `$ pico_project --gui`. - +The package can be uninstalled with `$ pip uninstall pico-project-generator`. diff --git a/logo_alpha.gif b/pico_project/logo_alpha.gif similarity index 100% rename from logo_alpha.gif rename to pico_project/logo_alpha.gif diff --git a/pico_configs.tsv b/pico_project/pico_configs.tsv similarity index 100% rename from pico_configs.tsv rename to pico_project/pico_configs.tsv diff --git a/pico_project.py b/pico_project/pico_project.py similarity index 95% rename from pico_project.py rename to pico_project/pico_project.py index 3ace1b6..145ee99 100755 --- a/pico_project.py +++ b/pico_project/pico_project.py @@ -797,9 +797,13 @@ def CheckSDKPath(gui): def ParseCommandLine(): + # default tsv file location is in this python module's directory + this_module_location = os.path.dirname(os.path.realpath(__file__)) + default_tsv_file = os.path.join(this_module_location, "pico_configs.tsv") + parser = argparse.ArgumentParser(description='Pico Project generator') parser.add_argument("name", nargs="?", help="Name of the project") - parser.add_argument("-t", "--tsv", help="Select an alternative pico_configs.tsv file", default="pico_configs.tsv") + parser.add_argument("-t", "--tsv", help="Select an alternative pico_configs.tsv file", default=default_tsv_file) parser.add_argument("-o", "--output", help="Set an alternative CMakeList.txt filename", default="CMakeLists.txt") parser.add_argument("-x", "--examples", action='store_true', help="Add example code for the Pico standard library") parser.add_argument("-l", "--list", action='store_true', help="List available features") @@ -1201,70 +1205,75 @@ def DoEverything(parent, params): ################################################################################### # main execution starteth here +def main(): + global args + args = ParseCommandLine() -args = ParseCommandLine() - -if args.nouart: - args.uart = False + if args.nouart: + args.uart = False # TODO this could be better, need some constants etc -if args.debugger > 1: - args.debugger = 0 + if args.debugger > 1: + args.debugger = 0 # Check we have everything we need to compile etc -c = CheckPrerequisites() + c = CheckPrerequisites() ## TODO Do both warnings in the same error message so user does have to keep coming back to find still more to do -if c == None: - m = 'Unable to find the `' + COMPILER_NAME + '` compiler\n' - m +='You will need to install an appropriate compiler to build a Raspberry Pi Pico project\n' - m += 'See the Raspberry Pi Pico documentation for how to do this on your particular platform\n' + if c == None: + m = 'Unable to find the `' + COMPILER_NAME + '` compiler\n' + m +='You will need to install an appropriate compiler to build a Raspberry Pi Pico project\n' + m += 'See the Raspberry Pi Pico documentation for how to do this on your particular platform\n' - if (args.gui): - RunWarning(m) - else: - print(m) - sys.exit(-1) + if (args.gui): + RunWarning(m) + else: + print(m) + sys.exit(-1) -if args.name == None and not args.gui and not args.list and not args.configs: - print("No project name specfied\n") - sys.exit(-1) + if args.name == None and not args.gui and not args.list and not args.configs: + print("No project name specfied\n") + sys.exit(-1) # load/parse any configuration dictionary we may have -LoadConfigurations() + LoadConfigurations() -p = CheckSDKPath(args.gui) + p = CheckSDKPath(args.gui) -if p == None: - sys.exit(-1) + if p == None: + sys.exit(-1) -sdkPath = Path(p) + sdkPath = Path(p) -if args.gui: - RunGUI(sdkPath, args) # does not return, only exits + if args.gui: + RunGUI(sdkPath, args) # does not return, only exits -projectRoot = Path(os.getcwd()) + projectRoot = Path(os.getcwd()) -if args.list or args.configs: - if args.list: - print("Available project features:\n") - for feat in features_list: - print(feat.ljust(6), '\t', features_list[feat][GUI_TEXT]) - print('\n') + if args.list or args.configs: + if args.list: + print("Available project features:\n") + for feat in features_list: + print(feat.ljust(6), '\t', features_list[feat][GUI_TEXT]) + print('\n') - if args.configs: - print("Available project configuration items:\n") - for conf in configuration_dictionary: - print(conf['name'].ljust(40), '\t', conf['description']) - print('\n') + if args.configs: + print("Available project configuration items:\n") + for conf in configuration_dictionary: + print(conf['name'].ljust(40), '\t', conf['description']) + print('\n') + + sys.exit(0) + else : + p = Parameters(sdkPath=sdkPath, projectRoot=projectRoot, projectName=args.name, + gui=False, overwrite=args.overwrite, build=args.build, features=args.feature, + projects=args.project, configs=(), runFromRAM=args.runFromRAM, + examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp, debugger=args.debugger, exceptions=args.cppexceptions, rtti=args.cpprtti) + + DoEverything(None, p) - sys.exit(0) -else : - p = Parameters(sdkPath=sdkPath, projectRoot=projectRoot, projectName=args.name, - gui=False, overwrite=args.overwrite, build=args.build, features=args.feature, - projects=args.project, configs=(), runFromRAM=args.runFromRAM, - examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp, debugger=args.debugger, exceptions=args.cppexceptions, rtti=args.cpprtti) - DoEverything(None, p) +if __name__ == "__main__": + main() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3a11b31 --- /dev/null +++ b/setup.py @@ -0,0 +1,30 @@ +import setuptools + +with open("README.md", "r", encoding="utf-8") as fh: + long_description = fh.read() + +setuptools.setup ( + name = "pico-project-generator", + version = "0.1", + description = "Console and GUI C project generator for the Raspberry Pi Pico", + long_description = long_description, + long_description_content_type = "text/markdown", + url = "https://github.com/raspberrypi/pico-project-generator", + classifiers=[ + "Programming Language :: Python :: 3", + "Topic :: Software Development", + "Topic :: Software Development :: Code Generators", + "Topic :: Software Development :: Embedded Systems", + ], + python_requires = '>=3.6', + package_data = { + 'pico_project': ['logo_alpha.gif', 'pico_configs.tsv'] + }, + packages = ["pico_project"], + entry_points = { + 'console_scripts': [ + 'pico_project=pico_project.pico_project:main', + ], + } +) +