Skip to content

Commit 41a3d5f

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 f88cf8d commit 41a3d5f

File tree

4 files changed

+82
-46
lines changed

4 files changed

+82
-46
lines changed
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
@@ -1080,8 +1080,11 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger):
10801080

10811081

10821082
def LoadConfigurations():
1083+
# open the pico_configs.tsv from the executable's directory
1084+
this_module_location = os.path.dirname(os.path.realpath(__file__))
1085+
tsv_file = os.path.join(this_module_location, "pico_configs.tsv")
10831086
try:
1084-
with open("pico_configs.tsv") as tsvfile:
1087+
with open(tsv_file) as tsvfile:
10851088
reader = csv.DictReader(tsvfile, dialect='excel-tab')
10861089
for row in reader:
10871090
configuration_dictionary.append(row)
@@ -1180,70 +1183,74 @@ def DoEverything(parent, params):
11801183

11811184
###################################################################################
11821185
# main execution starteth here
1186+
def main():
1187+
args = ParseCommandLine()
11831188

1184-
args = ParseCommandLine()
1185-
1186-
if args.nouart:
1187-
args.uart = False
1189+
if args.nouart:
1190+
args.uart = False
11881191

11891192
# TODO this could be better, need some constants etc
1190-
if args.debugger > 1:
1191-
args.debugger = 0
1193+
if args.debugger > 1:
1194+
args.debugger = 0
11921195

11931196
# Check we have everything we need to compile etc
1194-
c = CheckPrerequisites()
1197+
c = CheckPrerequisites()
11951198

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

1198-
if c == None:
1199-
m = 'Unable to find the `' + COMPILER_NAME + '` compiler\n'
1200-
m +='You will need to install an appropriate compiler to build a Raspberry Pi Pico project\n'
1201-
m += 'See the Raspberry Pi Pico documentation for how to do this on your particular platform\n'
1201+
if c == None:
1202+
m = 'Unable to find the `' + COMPILER_NAME + '` compiler\n'
1203+
m +='You will need to install an appropriate compiler to build a Raspberry Pi Pico project\n'
1204+
m += 'See the Raspberry Pi Pico documentation for how to do this on your particular platform\n'
12021205

1203-
if (args.gui):
1204-
RunWarning(m)
1205-
else:
1206-
print(m)
1207-
sys.exit(-1)
1206+
if (args.gui):
1207+
RunWarning(m)
1208+
else:
1209+
print(m)
1210+
sys.exit(-1)
12081211

1209-
if args.name == None and not args.gui and not args.list and not args.configs:
1210-
print("No project name specfied\n")
1211-
sys.exit(-1)
1212+
if args.name == None and not args.gui and not args.list and not args.configs:
1213+
print("No project name specfied\n")
1214+
sys.exit(-1)
12121215

12131216
# load/parse any configuration dictionary we may have
1214-
LoadConfigurations()
1217+
LoadConfigurations()
12151218

1216-
p = CheckSDKPath(args.gui)
1219+
p = CheckSDKPath(args.gui)
12171220

1218-
if p == None:
1219-
sys.exit(-1)
1221+
if p == None:
1222+
sys.exit(-1)
12201223

1221-
sdkPath = Path(p)
1224+
sdkPath = Path(p)
12221225

1223-
if args.gui:
1224-
RunGUI(sdkPath, args) # does not return, only exits
1226+
if args.gui:
1227+
RunGUI(sdkPath, args) # does not return, only exits
12251228

1226-
projectRoot = Path(os.getcwd())
1229+
projectRoot = Path(os.getcwd())
12271230

1228-
if args.list or args.configs:
1229-
if args.list:
1230-
print("Available project features:\n")
1231-
for feat in features_list:
1232-
print(feat.ljust(6), '\t', features_list[feat][GUI_TEXT])
1233-
print('\n')
1231+
if args.list or args.configs:
1232+
if args.list:
1233+
print("Available project features:\n")
1234+
for feat in features_list:
1235+
print(feat.ljust(6), '\t', features_list[feat][GUI_TEXT])
1236+
print('\n')
12341237

1235-
if args.configs:
1236-
print("Available project configuration items:\n")
1237-
for conf in configuration_dictionary:
1238-
print(conf['name'].ljust(40), '\t', conf['description'])
1239-
print('\n')
1238+
if args.configs:
1239+
print("Available project configuration items:\n")
1240+
for conf in configuration_dictionary:
1241+
print(conf['name'].ljust(40), '\t', conf['description'])
1242+
print('\n')
1243+
1244+
sys.exit(0)
1245+
else :
1246+
p = Parameters(sdkPath=sdkPath, projectRoot=projectRoot, projectName=args.name,
1247+
gui=False, overwrite=args.overwrite, build=args.build, features=args.feature,
1248+
projects=args.project, configs=(), runFromRAM=args.runFromRAM,
1249+
examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp, debugger=args.debugger, exceptions=args.cppexceptions, rtti=args.cpprtti)
1250+
1251+
DoEverything(None, p)
12401252

1241-
sys.exit(0)
1242-
else :
1243-
p = Parameters(sdkPath=sdkPath, projectRoot=projectRoot, projectName=args.name,
1244-
gui=False, overwrite=args.overwrite, build=args.build, features=args.feature,
1245-
projects=args.project, configs=(), runFromRAM=args.runFromRAM,
1246-
examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp, debugger=args.debugger, exceptions=args.cppexceptions, rtti=args.cpprtti)
12471253

1248-
DoEverything(None, p)
1254+
if __name__ == "__main__":
1255+
main()
12491256

setup.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 CMake 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+
],
16+
python_requires = '>=3.6',
17+
use_scm_version = True,
18+
setup_requires=['setuptools_scm'],
19+
package_data = {
20+
'pico_project': ['logo_alpha.gif', 'pico_configs.tsv']
21+
},
22+
packages = ["pico_project"],
23+
entry_points = {
24+
'console_scripts': [
25+
'pico_project=pico_project.pico_project:main',
26+
],
27+
}
28+
)
29+

0 commit comments

Comments
 (0)