Skip to content

Commit 8a82140

Browse files
authored
Merge pull request #39 from RobertMcReed/feat/bash
feat/bash: Bash scripts for automating Anaconda / Docker installation and management
2 parents 27f491b + 46a63d4 commit 8a82140

File tree

4 files changed

+792
-10
lines changed

4 files changed

+792
-10
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
debug_*
1515
*/__pycache__/*
1616
*~$*
17+
things/
18+
.DS_Store
1719
things/*.scad
1820
things/*.step
19-
things/*.stl
21+
things/*.stl

README.md

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,27 @@ As part of the effort to create a new engine I converted the code to cadquery/Op
1515

1616
### Docker Autobuild
1717
![Docker Support!](./resources/docker_containers.png)
18+
1819
At the excellent suggestion of [martint17r](https://github.com/joshreve/dactyl-keyboard/issues?q=is%3Apr+author%3Amartint17r)
19-
I have added docker configurations with an Windows batch file to assist with getting setup.
20-
If there is sufficient interest I can add a .sh file as well. If you have
20+
I have added docker configurations with a Windows batch file to assist with getting setup.
21+
If you have
2122
[docker desktop](https://www.docker.com/products/docker-desktop) installed, the batch file will create the
22-
dactyl-keyboard image and 3 containers: DM-run: runs the dactyl_manuform.py, DM-config: runs generate_configuration.py,
23-
and DM-shell: just starts an interactive session to manually run from shell (tip: run bash after entering to get the better
24-
shell environment). All apps bindmount the src and things directory to allow editing in the host and running in the
25-
container. While not exactly hard drive space efficient, this hopefully this helps those having issue getting
23+
dactyl-keyboard image and 4 containers:
24+
25+
- DM-run: runs `dactyl_manuform.py`,
26+
- DM-config: runs `generate_configuration.py`
27+
- DM-shell: starts an interactive session to manually run from shell
28+
- tip: run bash after entering to get a better shell environment
29+
- DM-release-build: runs `model_builder.py` to generate a number of keyboard variants
30+
31+
All apps bindmount the `src` and `things` directory to allow editing in the host and running in the
32+
container. While not exactly hard drive space efficient, this hopefully helps those having issues getting
2633
cadquery running and prevents local Python conflicts. It works well on my computer, but I don't use
2734
docker often, so please let me know if you find any issues with the approach.
2835

2936
### Refactored
3037

31-
Your settings are now created by `generate_configuration.py` or by direct modification fo the `run_config.json` file.
38+
Your settings are now created by `generate_configuration.py` or by direct modification of the `run_config.json` file.
3239
This allows you to save `run_config.json` to share your configuration.
3340

3441
Additionally, the OpenSCAD/solid python and OpenCASCADE/cadquery versions are merged with separate helper functions
@@ -104,13 +111,61 @@ You can now have slightly better control of screw mounts. Set to `'screws_offse
104111
## Status / Future
105112
This is now a bit of a monster of many minds and yet continues to bear fruit. I plan to continue to use this code to try new geometries and features to share. I am still working on a new generator, but feel this one can continue to evolve and inform the other effort.
106113

107-
## Generating a Design
114+
## Installation
115+
116+
There are three different environments in which you can run this application. Depending on which you choose, the installation process will vary.
117+
118+
- [Docker Environment](#docker-environment-installation)
119+
- [Conda Environment](#conda-environment-installation)
120+
- [Python Environment](#python-environment-installation)
121+
122+
### Docker Environment Installation
123+
124+
Running the application with Docker is the most convenient way to do so. In addition to a straightforward installation, this also allows you to generate models in the background without having to keep a shell open.
125+
126+
*Note:* If you are using Windows, see [Docker Autobuild](#docker-autobuild).
127+
128+
Before you proceed, ensure you have installed [Docker](https://www.docker.com/) and the `docker` command is available from your terminal.
129+
130+
There are two tools you can use to help manage the Docker containers associated with this project.
131+
132+
#### Make
133+
134+
If you prefer, you can use `make` to manage the containers. Type `make help` to see the available commands.
135+
136+
#### Bash Script
137+
138+
The `dactyl.sh` bash script provides a CLI to manage the containers. Type `./dactyl.sh --help` to see all CLI options.
139+
140+
In addition to the CLI you can run `./dactyl.sh` without any arguments to use an interactive menu.
141+
142+
Upon running the script, you will be prompted to build the dactyl-keyboard Docker image.
143+
144+
Once the image is built, you can choose which containers to run on an as-needed basis. In general, you can start, stop, rebuild, inspect, and remove the containers via the CLI/Menu.
145+
146+
You can also remove all of the Docker artifacts by running the included uninstaller.
147+
148+
*Tip:* Run `./dactyl.sh shell --session` to jump into a bash session inside of the shell container.
149+
150+
### Conda Environment Installation
151+
152+
After the Docker installation, Anaconda is the next best option. Before you begin, ensure you have installed [Anaconda](https://docs.anaconda.com/anaconda/install/index.html) and the `conda` command is available from your terminal.
153+
154+
You can install all of the dependencies by hand, but you can automate the install by running the bash script `./conda.sh`. This will create a python 3.7 environment named `dactyl-keyboard` and install all of the required dependencies.
155+
156+
If you would like to install into a conda environment manually, check the bash script to see all of the required commands.
157+
158+
If you would like to remove the conda artifacts, run `./conda.sh --uninstall`.
159+
160+
### Python Environment Installation
161+
162+
You can install the application in a regular python environment, but it is not recommended. You will not be able to take advantage of the updated geometry generated by the CadQuery engine, as this is only available via the Docker/Anaconda installation.
108163

109164
**Setting up the Python environment - NEW**
110165
* [Install Python 3.X](https://www.python.org/downloads/release/python-385/) or use your [favorite distro / platform (Anaconda)](https://www.anaconda.com/products/individual)
111166
* It is advisable, but not necessary, to setup a virtual environment to prevent package/library incompatibility
112167
* [Install Numpy](https://pypi.org/project/numpy/), easiest method is `pip install numpy` or `pip3 install numpy` on linux.
113-
* [Install dataclasses_json](https://pypi.org/project/dataclasses_json/), easiest method is `pip install numpy` or `pip3 install numpy` on linux.
168+
* [Install dataclasses_json](https://pypi.org/project/dataclasses_json/), easiest method is `pip install dataclasses-json` or `pip3 install dataclasses-json` on linux.
114169

115170
**cadquery install**
116171
* [Install scipy](https://pypi.org/project/scipy/), easiest method is `pip install scipy` or `pip3 install scipy` on linux.
@@ -120,6 +175,8 @@ This is now a bit of a monster of many minds and yet continues to bear fruit. I
120175
* [Install SolidPython](https://pypi.org/project/solidpython/), easiest method is `pip install solidpython` or `pip3 install solidpython` on linux.
121176
* [Install OpenSCAD](http://www.openscad.org/)
122177

178+
## Generating the design
179+
123180
**Generating the design - UPDATED**
124181
* ~~Run `python dactyl_manuform_cadquery.py` or `python3 dactyl_manuform_cadquery.py`~~
125182
* ~~Run `python dactyl_manuform.py` or `python3 dactyl_manuform.py`~~

conda.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
# exit on any errors
4+
set -e
5+
6+
function inform() { echo -e "\n[INFO] $@\n"; }
7+
function warn() { echo -e "\n[WARN] $@\n"; }
8+
function error() { echo -e "\n[ERROR] $@\n"; }
9+
10+
# exit unless user responds with yes
11+
function confirmContinue() {
12+
while true; do
13+
read -p "$@ [y/n]" yn
14+
case $yn in
15+
[Yy]* ) break;;
16+
[Nn]* ) exit 0;;
17+
* ) error "Please answer yes or no.";;
18+
esac
19+
done
20+
}
21+
22+
if ! which conda &> /dev/null; then
23+
error "Conda not found.\n\nVisit https://docs.anaconda.com/anaconda/install/index.html for more info."
24+
exit 1
25+
fi
26+
27+
# Enable "conda activate" and "conda deactivate"
28+
eval "$(conda shell.bash hook)"
29+
30+
envName=dactyl-keyboard
31+
32+
if [ "$1" = "--uninstall" ]; then
33+
confirmContinue "Would you like to remove the conda environment $envName?"
34+
conda deactivate
35+
conda env remove -n $envName
36+
inform "Conda environment removed!\n\n\tRun \"conda deactivate\" to ensure the environment has been properly deactivated."
37+
38+
exit
39+
fi
40+
41+
if conda info --envs | grep $envName &> /dev/null; then
42+
warn "Conda env \"$envName\" already exists."
43+
confirmContinue "Do you want to overwrite it?"
44+
fi
45+
46+
inform "Creating conda environment: $envName..."
47+
48+
conda create --name=$envName python=3.7 -y
49+
50+
conda activate $envName
51+
52+
inform "Installing CadQuery..."
53+
54+
conda install -c conda-forge -c cadquery cadquery=2 -y
55+
56+
inform "Installing dataclasses-json..."
57+
58+
pip install dataclasses-json
59+
60+
inform "Installing numpy..."
61+
62+
pip install numpy
63+
64+
inform "Installing scipy..."
65+
66+
pip install scipy
67+
68+
inform "Installing solidpython..."
69+
70+
pip install solidpython
71+
72+
inform "Updating conda dependencies..."
73+
74+
conda update --all -y
75+
76+
inform "Success!\n\n\tRun \"conda activate $envName\" to activate the environment."

0 commit comments

Comments
 (0)