Skip to content

Commit 4bdedef

Browse files
committed
got most of base work done
1 parent 54cbdff commit 4bdedef

16 files changed

Lines changed: 233 additions & 159 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
cpy/**
2-
!cpy/.gitkeep
2+
!cpy/.gitkeep
3+
post_build.sh

Dockerfile

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
FROM ubuntu:20.04
2-
3-
USER root
4-
WORKDIR /cpy
5-
COPY ./cpy/circuitpython .
6-
COPY ./dockerbuildcmd.sh .
7-
# COPY ./dockerfinishcmd.sh .
8-
9-
ARG DEBIAN_FRONTEND=noninteractive
10-
RUN apt-get update && \
11-
apt-get upgrade -y && \
12-
apt-get install -y \
13-
# Development files
14-
build-essential \
15-
git \
16-
bzip2 \
17-
gcc-aarch64-linux-gnu\
18-
python3.8\
19-
python3-pip\
20-
gettext\
21-
wget && \
22-
apt-get clean
23-
RUN wget -qO- https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 | tar -xj
24-
25-
ENV PATH "/cpy/gcc-arm-none-eabi-9-2019-q4-major/bin:$PATH"
26-
27-
# RUN apt-get update && apt-get install -y gettext librsvg2-bin git mingw-w64 latexmk texlive-fonts-recommended texlive-latex-recommended texlive-latex-extra gcc-aarch64-linux-gnu wget python3.8 python3-pip && apt-get clean
28-
RUN make fetch-submodules
29-
RUN pip3 install -r requirements-dev.txt
30-
RUN pip3 install --upgrade click==7.1.2
31-
RUN make -C mpy-cross
32-
# CMD ["bash","dockerbuildcmd.sh"]
33-
34-
CMD ["sleep","3600"]
1+
FROM ubuntu:20.04
2+
3+
USER root
4+
WORKDIR /cpy
5+
# COPY ./cpy/circuitpython .
6+
COPY ./dockersetupcmd.sh .
7+
# COPY ./dockerfinishcmd.sh .
8+
9+
ARG DEBIAN_FRONTEND=noninteractive
10+
RUN apt-get update && \
11+
apt-get upgrade -y && \
12+
apt-get install -y \
13+
# Development files
14+
build-essential \
15+
git \
16+
bzip2 \
17+
gcc-aarch64-linux-gnu\
18+
python3.8\
19+
python3-pip\
20+
gettext\
21+
wget && \
22+
apt-get clean
23+
RUN wget -qO- https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 | tar -xj
24+
25+
ENV PATH "/cpy/gcc-arm-none-eabi-9-2019-q4-major/bin:$PATH"
26+
27+
# RUN apt-get update && apt-get install -y gettext librsvg2-bin git mingw-w64 latexmk texlive-fonts-recommended texlive-latex-recommended texlive-latex-extra gcc-aarch64-linux-gnu wget python3.8 python3-pip && apt-get clean
28+
# RUN make fetch-submodules
29+
# RUN pip3 install -r requirements-dev.txt
30+
# RUN pip3 install --upgrade click==7.1.2
31+
# RUN make -C mpy-cross
32+
CMD ["bash","dockersetupcmd.sh"]
33+
34+
# CMD ["sleep","3600"]

README.md

Lines changed: 88 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,88 @@
1-
# bs-python
2-
What is this all about? So we we wanted something like kmkPython But after talking with the kmk team and hearing the challanges we thought we would start fresh. So welcome to BS_Python (pun very much intended) our version of KMKPython.
3-
4-
So the main idea here and how we are doing this defferently is we as you can see dont have circuit_python in here. What we do is we script everything. We start by cloning circuit_python > check out the right branch > make all the code changes > build the boards
5-
6-
Let me break down whats going on and how you can use this. I will start by going over the code flow then I will tell you what you need to edit (if you need to edit anything) and how you can help out
7-
8-
## Code flow
9-
* scipts/build.sh <- enetry point
10-
* calls main.py
11-
* main.py <- start of the code
12-
* cpy_git <- handles all things to do with git
13-
* clone the repo
14-
* add submodules
15-
* misc_file_changes <- change cpy code
16-
* board_mapping <- this moves BS_python boards into the right place in cpy
17-
* builds docker container
18-
* that way you only need docker and python you dont need to make sure you can compile cpy
19-
* scripts/start.sh
20-
* starts the newly built docker container and builds all of the BS_python boards
21-
22-
Ok now that you have an idea on how this flows together lets go over some things you might do and how you would go about doing them.
23-
24-
## Freez xyz lib into xyz board and let everyone download that
25-
So you will want to copy that board from the cpy folder (run main.py to get that). Then make your changes to it and place that into the ./bs_python_boards folder. Now Its very important you place it in the correct foleder. When you take it from the cpy repo if it is from ports/nrf it needs to go into the nrf folder. If the folder does not exsist just make it but it NEEDS to be spelled the same.
26-
27-
## Freez a lib that is not in CPY
28-
To freez a another libary you can simply add it to the FROZEN_REPO_LIST in cpy_git.py
29-
30-
## other code changes
31-
Above is all that I have implmented But if you want to make random changes to the CPY code base feel free to do so. A few things I would like to ask of you. Make sure that the entry for your code is in misc_file_changes.py (unless another file is better eg: git changes should be in cpy_git.py). And make sure you add somthing to this file letting other know how to do your cool new change.
32-
33-
## TODO / HELP WANTED / DISCLAMER
34-
35-
* Add some boards
36-
* freez in kmk in some way. But I want it compiled to .mpy
37-
* I am a super python noob I barly know how to setup a python project. This one was setup using pipenv and python 3.9.x we dont have a reqerments.txt I dont know how to make one or if we need one we do have a pipfile tho.
38-
39-
40-
41-
42-
1+
# BS-Python
2+
What is this all about? So we wanted something like kmkPython But after talking with the kmk team and hearing the challenges we thought we would start fresh. So welcome to BS_Python (pun very much intended) our version of KMKPython.
3+
4+
So the main idea here and how we are doing this differently is we as you can see dont have circuit_python in here. What we do is we script everything. We start by cloning circuit_python > check out the right branch > make all the code changes > build the boards
5+
6+
Let me break down what's going on and how you can use this. I will start by going over the code flow then I will tell you what you need to edit (if you need to edit anything) and how you can help out
7+
8+
## Quick links
9+
[current boards](supported_boards.md)
10+
11+
12+
13+
## **important**
14+
All scripts are intended to be run from the root so
15+
16+
**dont** do this
17+
```
18+
cd scripts
19+
bash start.sh
20+
```
21+
**do** do this
22+
```
23+
bash scripts/start.sh
24+
```
25+
26+
27+
28+
## Code flow
29+
* scipts/start.sh <- enetry point
30+
* calls main.py
31+
* main.py <- start of the code
32+
* cpy_git <- handles all things to do with git
33+
* clone the repo
34+
* add submodules
35+
* misc_file_changes <- change cpy code
36+
* board_mapping <- this moves BS_python boards into the right place in cpy
37+
* genarates the build script and post build script
38+
* pulls the docker container or uses the one you build (see below)
39+
* starts the new docker container
40+
* runs the dockersetupcmd.sh
41+
* this sets up the cloned cpy repo for building
42+
* runs the genarated build script that builds all the BS_Python boards
43+
* runs the genarated post build script
44+
* this moves all of the built .u2f files into the ./build_out and renames them
45+
46+
47+
48+
## Misc things you can do
49+
below are the other scripts you can run and what they do
50+
* scripts/build.sh
51+
* builds docker container
52+
* that way you only need docker and python you don't need to make sure you can compile cpy
53+
* tries to push it as well.
54+
* scripts/clean.sh
55+
* removes old cpy clones and builds.
56+
* scripts/bash-container.sh
57+
* this is mostly for debugging the docker container
58+
* it dumps you into bash on the container so you can see what's going on in there
59+
* scripts/kill-all.sh
60+
* kills all docker containers running (look out)
61+
62+
Ok now that you have an idea on how this flows together lets go over some things you might do and how you would go about doing them.
63+
64+
## Freez xyz lib into xyz board and let everyone download that
65+
So you will want to copy that board from the cpy folder (run main.py to get that). Then make your changes to it and place that into the ./bs_python_boards folder. Now Its very important you place it in the correct folder. When you take it from the cpy repo if it is from ports/nrf it needs to go into the nrf folder. If the folder does not exist just make it but it NEEDS to be spelled the same.
66+
67+
## Freez a lib that is not in CPY
68+
To freez another library you can simply add it to the FROZEN_REPO_LIST in cpy_git.py
69+
70+
## other code changes
71+
Above is all that I have implemented But if you want to make random changes to the CPY code base feel free to do so. A few things I would like to ask of you. Make sure that the entry for your code is in misc_file_changes.py (unless another file is better eg: git changes should be in cpy_git.py). And make sure you add something to this file letting others know how to do your cool new change.
72+
73+
## TODO / HELP WANTED / DISCLAMER
74+
* typo / spelling
75+
* let me know if I need to make any more changes to stay legal
76+
* Add some boards
77+
* turn all my sick bash scripts into a make file LOL
78+
* freez in kmk in some way. But I want it compiled to .mpy
79+
* I am a super python noob I barely know how to setup a python project. This one was setup using pipenv and python 3.9.x we dont have a reqerments.txt I dont know how to make one or if we need one we do have a pipfile tho.
80+
* github action to add all the .uf2s from ./build_out to git hub releases
81+
* add colors to the logs (just the python parts)
82+
83+
84+
85+
86+
87+
88+

board_mapping.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1-
import os
2-
import shutil
3-
4-
board_dir="./bs_python_boards"
5-
cpy_dir = "./cpy/circuitpython/ports"
6-
def move_boards():
7-
for subdir in os.listdir(board_dir):
8-
board_type = f'{board_dir}/{subdir}'
9-
for board in os.listdir(board_dir+"/"+subdir):
10-
board_dest =f'{cpy_dir}/{subdir}/boards/{board}'
11-
board_src= f'{board_dir}/{subdir}/{board}'
12-
shutil.copytree(board_src, board_dest)
13-
print(f'moving {board} from {board_src} to {board_dest}')
14-
15-
def generate_build_script():
16-
print("pass")
1+
import os
2+
import shutil
3+
4+
board_dir="./bs_python_boards"
5+
cpy_dir = "./cpy/circuitpython"
6+
build_script= "#!/bin/bash\n"
7+
post_build_script= "#!/bin/bash\n"
8+
def generate_build_script():
9+
build_script_path= f'{cpy_dir}/dockerbuildcmd.sh'
10+
with open(build_script_path, 'w') as file:
11+
file.write(build_script)
12+
with open("./post_build.sh", 'w') as file:
13+
file.write(post_build_script)
14+
print(f'making build script in "{build_script_path}"')
15+
16+
def add_board_to_build_script_board(board,board_dir):
17+
global build_script
18+
global post_build_script
19+
build_script+=f'cd ports/{board_dir}\n'
20+
build_script+=f'make BOARD={board}\n'
21+
build_script+=f'sleep 100\n'
22+
build_script+=f'cd ../..\n'
23+
post_build_script+=f'cp ./cpy/circuitpython/ports/{board_dir}/build-{board}/firmware.uf2 ./build_out/{board}.uf2\n'
24+
25+
def move_boards():
26+
for subdir in os.listdir(board_dir):
27+
board_type = f'{board_dir}/{subdir}'
28+
for board in os.listdir(board_dir+"/"+subdir):
29+
board_dest =f'{cpy_dir}/ports/{subdir}/boards/{board}'
30+
board_src= f'{board_dir}/{subdir}/{board}'
31+
shutil.copytree(board_src, board_dest)
32+
print(f'moving {board} from {board_src} to {board_dest}')
33+
add_board_to_build_script_board(board,subdir)
34+
generate_build_script()

bs_python_boards/nrf/nice_nano_bs/mpconfigboard.mk

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ MCU_CHIP = nrf52840
88
INTERNAL_FLASH_FILESYSTEM = 1
99

1010
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BLE
11-
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
12-
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SSD1306
13-
# you need to fix the 1306 lib and you need to add framebuf
11+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel

build_out/boardsource_blok.uf2

0 Bytes
Binary file not shown.

build_out/nice_nano_bs.uf2

1.01 MB
Binary file not shown.

cpy_git.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import git
2-
import subprocess
3-
import shutil
4-
PATH = "./cpy/circuitpython"
5-
REPO_URL = "https://github.com/adafruit/circuitpython.git"
6-
BRANCH = "7.2.x"
7-
FROZEN_REPO_LIST = ["https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306.git","https://github.com/adafruit/Adafruit_CircuitPython_SSD1306.git"]
8-
9-
def clean_dir():
10-
try:
11-
shutil.rmtree(PATH)
12-
except OSError as e:
13-
print("Error: %s : %s" % (PATH, e.strerror))
14-
def add_frozen_lib(repo):
15-
submodule_path= f'{PATH}/frozen'
16-
for lib_url in FROZEN_REPO_LIST:
17-
print(f'adding frozen lib from this url: {lib_url}')
18-
process = subprocess.Popen(["git", "submodule", "add",lib_url],cwd=submodule_path)
19-
process.wait()
20-
21-
# repo.git.submodule.add(submodule_path,lib_url)
22-
23-
def git_checkout():
24-
clean_dir()
25-
repo = git.Repo.clone_from(REPO_URL, PATH)
26-
repo.git.checkout(BRANCH)
1+
import git
2+
import subprocess
3+
import shutil
4+
PATH = "./cpy/circuitpython"
5+
REPO_URL = "https://github.com/adafruit/circuitpython.git"
6+
BRANCH = "7.2.x"
7+
FROZEN_REPO_LIST = ["https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306.git","https://github.com/adafruit/Adafruit_CircuitPython_SSD1306.git"]
8+
9+
def clean_dir():
10+
try:
11+
shutil.rmtree(PATH)
12+
except OSError as e:
13+
print("Error: %s : %s" % (PATH, e.strerror))
14+
def add_frozen_lib(repo):
15+
submodule_path= f'{PATH}/frozen'
16+
for lib_url in FROZEN_REPO_LIST:
17+
print(f'adding frozen lib from this url: {lib_url}')
18+
process = subprocess.Popen(["git", "submodule", "add",lib_url],cwd=submodule_path)
19+
process.wait()
20+
21+
# repo.git.submodule.add(submodule_path,lib_url)
22+
23+
def git_checkout():
24+
clean_dir()
25+
repo = git.Repo.clone_from(REPO_URL, PATH)
26+
repo.git.checkout(BRANCH)
2727
add_frozen_lib(repo)

dockerbuildcmd.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

dockersetupcmd.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cd circuitpython&&make fetch-submodules&&pip3 install -r requirements-dev.txt&&pip3 install --upgrade click==7.1.2&&make -C mpy-cross && bash dockerbuildcmd.sh

0 commit comments

Comments
 (0)