Skip to content

Commit dbb6e92

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 3a1cdad commit dbb6e92

File tree

5 files changed

+92
-56
lines changed

5 files changed

+92
-56
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

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

46-
47-
4846
## GUI version
4947

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

5250
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.
5351

52+
## Installation using Python Pip (Linux)
53+
54+
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`.
55+
56+
The package can then be installed for the current user using: `$ pip install .`, or for the all system users using `$ sudo pip install .`.
57+
58+
You can now run the package with `$ pico_project` plus any arguments detailed below, e.g. `$ pico_project --gui`.
59+
60+
5461
Console Options | Description
5562
----------------|-----------
5663
Console over UART | Enable a serial console over the UART. This is the default.
@@ -76,11 +83,3 @@ IDE Options | Description
7683
Create VSCode Project | As well as the CMake files, also create the appropriate Visual Studio Code project files.
7784
Debugger | Use the specified debugger in the IDE
7885

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

pico_project.py renamed to pico_project/pico_project.py

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,9 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger):
11011101

11021102

11031103
def LoadConfigurations():
1104+
# open the pico_configs.tsv from the executable's directory
1105+
this_module_location = os.path.dirname(os.path.realpath(__file__))
1106+
tsv_file = os.path.join(this_module_location, "pico_configs.tsv")
11041107
try:
11051108
with open(args.tsv) as tsvfile:
11061109
reader = csv.DictReader(tsvfile, dialect='excel-tab')
@@ -1201,70 +1204,74 @@ def DoEverything(parent, params):
12011204

12021205
###################################################################################
12031206
# main execution starteth here
1207+
def main():
1208+
args = ParseCommandLine()
12041209

1205-
args = ParseCommandLine()
1206-
1207-
if args.nouart:
1208-
args.uart = False
1210+
if args.nouart:
1211+
args.uart = False
12091212

12101213
# TODO this could be better, need some constants etc
1211-
if args.debugger > 1:
1212-
args.debugger = 0
1214+
if args.debugger > 1:
1215+
args.debugger = 0
12131216

12141217
# Check we have everything we need to compile etc
1215-
c = CheckPrerequisites()
1218+
c = CheckPrerequisites()
12161219

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

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

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

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

12341237
# load/parse any configuration dictionary we may have
1235-
LoadConfigurations()
1238+
LoadConfigurations()
12361239

1237-
p = CheckSDKPath(args.gui)
1240+
p = CheckSDKPath(args.gui)
12381241

1239-
if p == None:
1240-
sys.exit(-1)
1242+
if p == None:
1243+
sys.exit(-1)
12411244

1242-
sdkPath = Path(p)
1245+
sdkPath = Path(p)
12431246

1244-
if args.gui:
1245-
RunGUI(sdkPath, args) # does not return, only exits
1247+
if args.gui:
1248+
RunGUI(sdkPath, args) # does not return, only exits
12461249

1247-
projectRoot = Path(os.getcwd())
1250+
projectRoot = Path(os.getcwd())
12481251

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

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

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

1269-
DoEverything(None, p)
1275+
if __name__ == "__main__":
1276+
main()
12701277

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)