Skip to content

Commit

Permalink
Merge pull request #51 from garthk/load-envars-from-dot-ampy-file
Browse files Browse the repository at this point in the history
Load environment variables from .ampy config file
  • Loading branch information
ladyada authored Jul 9, 2018
2 parents 916079d + d04a52f commit cb3db88
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ You should see a list of files on the board's root directory printed to the
terminal. Note that you'll need to change the port parameter to the name or path
to the serial port that the MicroPython board is connected to.

For convenience you can set an AMPY_PORT environment variable which will be used
Other commands are available, run ampy with --help to see more information:

ampy --help

Each subcommand has its own help, for example to see help for the ls command run (note you
unfortunately must have a board connected and serial port specified):

ampy --port /dev/tty.SLAB_USBtoUART ls --help

## Configuration

For convenience you can set an `AMPY_PORT` environment variable which will be used
if the port parameter is not specified. For example on Linux or OSX:

export AMPY_PORT=/dev/tty.SLAB_USBtoUART
Expand All @@ -88,11 +99,19 @@ Or on Windows (untested) try the SET command:
set AMPY_PORT=COM4
ampy ls

Other commands are available, run ampy with --help to see more information:
Similarly, you can set `AMPY_BAUD` and `AMPY_DELAY` to control your baud rate and
the delay before entering RAW MODE.

ampy --help
To set these variables automatically each time you run `ampy`, copy them into a
file named `.ampy`:

Each subcommand has its own help, for example to see help for the ls command run (note you
unfortunately must have a board connected and serial port specified):
```sh
# Example .ampy file
# Please fill in your own port, baud rate, and delay
AMPY_PORT=/dev/cu.wchusbserial1410
AMPY_BAUD=115200
AMPY_DELAY=0.5 # Fix for macOS users' "Could not enter raw repl"
```

ampy --port /dev/tty.SLAB_USBtoUART ls --help
You can put the `.ampy` file in your working directory, one of its parents, or in
your home directory.
7 changes: 7 additions & 0 deletions ampy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
import serial.serialutil

import click
import dotenv

# Load AMPY_PORT et al from .ampy file
# Performed here because we need to beat click's decorators.
config = dotenv.find_dotenv(filename='.ampy', usecwd=True)
if config:
dotenv.load_dotenv(dotenv_path=config)

import ampy.files as files
import ampy.pyboard as pyboard
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
],
keywords='micropython',
packages=find_packages(),
install_requires=['click', 'pyserial'],
install_requires=['click', 'pyserial', 'python-dotenv'],
entry_points={
'console_scripts': [
'ampy=ampy.cli:cli',
Expand Down

0 comments on commit cb3db88

Please sign in to comment.