Skip to content

Commit 6b9bbf0

Browse files
committed
Added setup.py to enable installation to user or system directory using setuptools
Re-structured directory tree to permit setuptools installation Added "main" function definition in pico_project.py to permit executable installation using setuptools Updated pico_configs.tsv configuration file read function to read from python script installation directory
1 parent 034dc41 commit 6b9bbf0

File tree

5 files changed

+93
-57
lines changed

5 files changed

+93
-57
lines changed

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pico-project-generator
22

3-
This is a command line or GUI tool, written in Python, to automatically generate a Pico C SDK Project.
3+
This is a command line or GUI tool, written in Python, to automatically generate a Raspberry Pi Pico C SDK Project.
44

55
The tool will generate all required CMake files, program files and VSCode IDE files for the set of features requested.
66

@@ -42,14 +42,21 @@ optional arguments:
4242
You can list the features supported by the tools by using `./pico_project --list`. These features can
4343
be added to the project using the `--feature` options, this can be used multiple times.
4444

45-
46-
4745
## GUI version
4846

4947
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.
5048

5149
You can add specific features to your project by selecting them from the check boxes on the GUI. This will ensure the build system adds the appropriate code to the build, and also adds simple example code to the project showing how to use the feature. There are a number of options available, which provide the following functionality.
5250

51+
## Installation using Python Pip (Linux)
52+
53+
Clone the repository with: `$ git clone https://github.com/raspberrypi/pico-project-generator` (assuming you are using HTTP to clone repositories). Change to the repository's directory with: `$ cd pico-project-generator`.
54+
55+
The package can then be installed for the current user using: `$ pip install .`, or for the all system users using `$ sudo pip install .`.
56+
57+
You can now run the package with `$ pico_project` plus any arguments detailed below, e.g. `$ pico_project --gui`.
58+
59+
5360
Console Options | Description
5461
----------------|-----------
5562
Console over UART | Enable a serial console over the UART. This is the default.
@@ -75,11 +82,3 @@ IDE Options | Description
7582
Create VSCode Project | As well as the CMake files, also create the appropriate Visual Studio Code project files.
7683
Debugger | Use the specified debugger in the IDE
7784

78-
79-
80-
81-
82-
83-
84-
85-
File renamed without changes.
File renamed without changes.

pico_project.py renamed to pico_project/pico_project.py

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,11 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger):
11001100

11011101

11021102
def LoadConfigurations():
1103+
# open the pico_configs.tsv from the executable's directory
1104+
this_module_location = os.path.dirname(os.path.realpath(__file__))
1105+
tsv_file = os.path.join(this_module_location, "pico_configs.tsv")
11031106
try:
1104-
with open("pico_configs.tsv") as tsvfile:
1107+
with open(tsv_file) as tsvfile:
11051108
reader = csv.DictReader(tsvfile, dialect='excel-tab')
11061109
for row in reader:
11071110
configuration_dictionary.append(row)
@@ -1200,70 +1203,74 @@ def DoEverything(parent, params):
12001203

12011204
###################################################################################
12021205
# main execution starteth here
1206+
def main():
1207+
args = ParseCommandLine()
12031208

1204-
args = ParseCommandLine()
1205-
1206-
if args.nouart:
1207-
args.uart = False
1209+
if args.nouart:
1210+
args.uart = False
12081211

12091212
# TODO this could be better, need some constants etc
1210-
if args.debugger > 1:
1211-
args.debugger = 0
1213+
if args.debugger > 1:
1214+
args.debugger = 0
12121215

12131216
# Check we have everything we need to compile etc
1214-
c = CheckPrerequisites()
1217+
c = CheckPrerequisites()
12151218

12161219
## TODO Do both warnings in the same error message so user does have to keep coming back to find still more to do
12171220

1218-
if c == None:
1219-
m = 'Unable to find the `' + COMPILER_NAME + '` compiler\n'
1220-
m +='You will need to install an appropriate compiler to build a Raspberry Pi Pico project\n'
1221-
m += 'See the Raspberry Pi Pico documentation for how to do this on your particular platform\n'
1221+
if c == None:
1222+
m = 'Unable to find the `' + COMPILER_NAME + '` compiler\n'
1223+
m +='You will need to install an appropriate compiler to build a Raspberry Pi Pico project\n'
1224+
m += 'See the Raspberry Pi Pico documentation for how to do this on your particular platform\n'
12221225

1223-
if (args.gui):
1224-
RunWarning(m)
1225-
else:
1226-
print(m)
1227-
sys.exit(-1)
1226+
if (args.gui):
1227+
RunWarning(m)
1228+
else:
1229+
print(m)
1230+
sys.exit(-1)
12281231

1229-
if args.name == None and not args.gui and not args.list and not args.configs:
1230-
print("No project name specfied\n")
1231-
sys.exit(-1)
1232+
if args.name == None and not args.gui and not args.list and not args.configs:
1233+
print("No project name specfied\n")
1234+
sys.exit(-1)
12321235

12331236
# load/parse any configuration dictionary we may have
1234-
LoadConfigurations()
1237+
LoadConfigurations()
12351238

1236-
p = CheckSDKPath(args.gui)
1239+
p = CheckSDKPath(args.gui)
12371240

1238-
if p == None:
1239-
sys.exit(-1)
1241+
if p == None:
1242+
sys.exit(-1)
12401243

1241-
sdkPath = Path(p)
1244+
sdkPath = Path(p)
12421245

1243-
if args.gui:
1244-
RunGUI(sdkPath, args) # does not return, only exits
1246+
if args.gui:
1247+
RunGUI(sdkPath, args) # does not return, only exits
12451248

1246-
projectRoot = Path(os.getcwd())
1249+
projectRoot = Path(os.getcwd())
12471250

1248-
if args.list or args.configs:
1249-
if args.list:
1250-
print("Available project features:\n")
1251-
for feat in features_list:
1252-
print(feat.ljust(6), '\t', features_list[feat][GUI_TEXT])
1253-
print('\n')
1251+
if args.list or args.configs:
1252+
if args.list:
1253+
print("Available project features:\n")
1254+
for feat in features_list:
1255+
print(feat.ljust(6), '\t', features_list[feat][GUI_TEXT])
1256+
print('\n')
12541257

1255-
if args.configs:
1256-
print("Available project configuration items:\n")
1257-
for conf in configuration_dictionary:
1258-
print(conf['name'].ljust(40), '\t', conf['description'])
1259-
print('\n')
1258+
if args.configs:
1259+
print("Available project configuration items:\n")
1260+
for conf in configuration_dictionary:
1261+
print(conf['name'].ljust(40), '\t', conf['description'])
1262+
print('\n')
1263+
1264+
sys.exit(0)
1265+
else :
1266+
p = Parameters(sdkPath=sdkPath, projectRoot=projectRoot, projectName=args.name,
1267+
gui=False, overwrite=args.overwrite, build=args.build, features=args.feature,
1268+
projects=args.project, configs=(), runFromRAM=args.runFromRAM,
1269+
examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp, debugger=args.debugger, exceptions=args.cppexceptions, rtti=args.cpprtti)
1270+
1271+
DoEverything(None, p)
12601272

1261-
sys.exit(0)
1262-
else :
1263-
p = Parameters(sdkPath=sdkPath, projectRoot=projectRoot, projectName=args.name,
1264-
gui=False, overwrite=args.overwrite, build=args.build, features=args.feature,
1265-
projects=args.project, configs=(), runFromRAM=args.runFromRAM,
1266-
examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp, debugger=args.debugger, exceptions=args.cppexceptions, rtti=args.cpprtti)
12671273

1268-
DoEverything(None, p)
1274+
if __name__ == "__main__":
1275+
main()
12691276

setup.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import setuptools
2+
3+
with open("README.md", "r", encoding="utf-8") as fh:
4+
long_description = fh.read()
5+
6+
setuptools.setup (
7+
name = "pico-project-generator",
8+
version = "0.1",
9+
description = "Console and GUI C project generator for the Raspberry Pi Pico",
10+
long_description = long_description,
11+
long_description_content_type = "text/markdown",
12+
url = "https://github.com/raspberrypi/pico-project-generator",
13+
classifiers=[
14+
"Programming Language :: Python :: 3",
15+
"Topic :: Software Development",
16+
"Topic :: Software Development :: Code Generators",
17+
"Topic :: Software Development :: Embedded Systems",
18+
],
19+
python_requires = '>=3.6',
20+
package_data = {
21+
'pico_project': ['logo_alpha.gif', 'pico_configs.tsv']
22+
},
23+
packages = ["pico_project"],
24+
entry_points = {
25+
'console_scripts': [
26+
'pico_project=pico_project.pico_project:main',
27+
],
28+
}
29+
)
30+

0 commit comments

Comments
 (0)