Skip to content

Commit

Permalink
Merge pull request #6 from ussserrr/dev
Browse files Browse the repository at this point in the history
v0.96
  • Loading branch information
ussserrr committed Dec 17, 2019
2 parents 66f134e + 4452185 commit a86cb82
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 132 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ stm32pio changelog:
- Changed: actualized .ioc file for the latest STM32CubeMX version (5.4.0 at the moment)
- Changed: improved help, docs, comments

ver. 0.95 (12.19):
ver. 0.95 (15.12.19):
- New: re-made patch() method: it can intelligently parses platformio.ini and substitute necessary options. Patch can now be a general .INI-format config
- New: test_get_state()
- New: upload to PyPI
Expand All @@ -143,3 +143,14 @@ stm32pio changelog:
- Changed: check whether there is already a platformio.ini file and warn in this case on PlatformIO init stage
- Changed: sort imports in the alphabetic order
- Changed: use configparser to test project patching

ver. 0.96 (17.12.19):
- Fix: generate_code() doesn't destroy the temp folder after execution
- Fix: improved and actualized docs, comments, annotations
- Changed: print Python interpreter information on testing
- Changed: move some asserts inside subTest context managers
- Changed: rename pio_build() => build()
- Changed: take out to the settings.py the width of field in a log format string
- Changed: use file statistic to check its size instead of reading the whole content
- Changed: more logging output
- Changed: change some methods signatures to return result value
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ Basically, you need to follow such a pattern:
3. Work on the project in your editor, compile/upload/debug etc.
4. Edit the configuration in CubeMX when necessary, then run stm32pio to regenerate the code.

Refer to Example section on more detailed steps.
Refer to Example section on more detailed steps. If you face off with some error try to enable a verbose output to get more information about a problem:
```shell script
$ stm32pio -v [command] [options]
```

Note, that the patch operation (which takes the CubeMX code and PlatformIO project to the compliance) erases all the comments (lines starting with `;`) inside the `platformio.ini` file. They are not required anyway, in general, but if you need them please consider to save the information somewhere else.

Starting from v0.95, the patch can has a general-form .INI content so it is possible to modify several sections and apply composite patches. This works totally fine for almost every cases except some big complex patches involving the parameters interpolation feature. It is turned off for both `platformio.ini` and user's patch parsing by default. If there are some problems you've met due to a such behavior please modify the source code to match the parameters interpolation kind for the configs you need to. Seems like `platformio.ini` uses `ExtendedInterpolation` for its needs, by the way.

On the first run stm32pio will create a config file `stm32pio.ini`, syntax of which is similar to the `platformio.ini`. You can also create this config without any following operations by initializing the project:
```shell script
Expand All @@ -65,7 +72,7 @@ $ python3 app.py --help
```
to see help on available commands.

You can also use stm32pio as a package and embed it in your own application. See [`app.py`](/stm32pio/app.py) to see how to implement this. Basically you need to import `stm32pio.lib` module (where the main `Stm32pio` class resides), set up a logger and you are good to go. If you need higher-level API similar to the CLI version use `main()` function in `app.py` passing the same CLI arguments to it.
You can also use stm32pio as a package and embed it in your own application. See [`app.py`](/stm32pio/app.py) to see how to implement this. Basically you need to import `stm32pio.lib` module (where the main `Stm32pio` class resides), set up a logger and you are good to go. If you need higher-level API similar to the CLI version, use `main()` function in `app.py` passing the same CLI arguments to it (except the actual script name).


## Example
Expand Down Expand Up @@ -123,4 +130,4 @@ CI is hard to implement for all target OSes during the requirement to have all t
```ini
lib_extra_dirs = Middlewares/Third_Party/FreeRTOS
```
You also need to move all `.c`/`.h` files to the `src`/`include` folders respectively. See PlatformIO documentation for more information.
You also need to move all `.c`/`.h` files to the appropriate folders respectively. See PlatformIO documentation for more information.
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@
- [x] Do we really need *sys.exc_info() ?
- [x] See logging.exception and sys_exc argument for logging.debug
- [x] Make `save_config()` a part of the `config` i.e. `project.config.save()` (subclass `ConfigParser`)
- [ ] Store an initial folder content in .ini config and ignore it on clean-up process. Allow the user to modify such list. Ask the confirmation of a user by-defualt and add additional option for quiet performance
- [ ] 'status' CLI subcommand, why not?..
- [ ] exclude tests from the bundle (see `setup.py` options)
36 changes: 21 additions & 15 deletions stm32pio/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__version__ = '0.95'
__version__ = '0.96'

import argparse
import logging
Expand All @@ -15,16 +15,16 @@ def parse_args(args: list) -> Optional[argparse.Namespace]:
Dedicated function to parse the arguments given via the CLI
Args:
args: list of strings
args: list of strings CLI arguments
Returns:
argparse.Namespace or None if no arguments were given
"""

parser = argparse.ArgumentParser(description="Automation of creating and updating STM32CubeMX-PlatformIO projects. "
"Requirements: Python 3.6+, STM32CubeMX, Java, PlatformIO CLI. Run "
"'init' command to create settings file and set the path to "
"STM32CubeMX and other tools (if defaults doesn't work)")
"'init' command to create config file and set the path to STM32CubeMX "
"and other tools (if defaults doesn't work for you)")
# Global arguments (there is also an automatically added '-h, --help' option)
parser.add_argument('--version', action='version', version=f"stm32pio v{__version__}")
parser.add_argument('-v', '--verbose', help="enable verbose output (default: INFO)", action='count', required=False)
Expand All @@ -35,7 +35,7 @@ def parse_args(args: list) -> Optional[argparse.Namespace]:
parser_init = subparsers.add_parser('init', help="create config .ini file so you can tweak parameters before "
"proceeding")
parser_new = subparsers.add_parser('new', help="generate CubeMX code, create PlatformIO project")
parser_generate = subparsers.add_parser('generate', help="generate CubeMX code")
parser_generate = subparsers.add_parser('generate', help="generate CubeMX code only")
parser_clean = subparsers.add_parser('clean', help="clean-up the project (WARNING: it deletes ALL content of "
"'path' except the .ioc file)")

Expand All @@ -60,28 +60,34 @@ def parse_args(args: list) -> Optional[argparse.Namespace]:

def main(sys_argv=None) -> int:
"""
Can be used as high-level wrapper to do complete tasks
Can be used as a high-level wrapper to do complete tasks
Example:
ret_code = stm32pio.app.main(sys_argv=['new', '-d', '~/path/to/project', '-b', 'nucleo_f031k6', '--with-build'])
Args:
sys_argv: list of strings
sys_argv: list of strings CLI arguments
Returns:
0 on success, -1 otherwise
"""

if sys_argv is None:
sys_argv = sys.argv[1:]

import stm32pio.settings

args = parse_args(sys_argv)

# Logger instance goes through the whole program.
# Currently only 2 levels of verbosity through the '-v' option are counted (INFO (default) and DEBUG (-v))
logger = logging.getLogger('stm32pio')
logger = logging.getLogger('stm32pio') # the root (relatively to the possible outer scope) logger instance
handler = logging.StreamHandler()
logger.addHandler(handler)
# Currently only 2 levels of verbosity through the '-v' option are counted (INFO (default) and DEBUG (-v))
if args is not None and args.subcommand is not None and args.verbose:
logger.setLevel(logging.DEBUG)
handler.setFormatter(logging.Formatter("%(levelname)-8s %(funcName)-26s %(message)s"))
handler.setFormatter(logging.Formatter("%(levelname)-8s "
f"%(funcName)-{stm32pio.settings.log_function_fieldwidth}s "
"%(message)s"))
logger.debug("debug logging enabled")
elif args is not None and args.subcommand is not None:
logger.setLevel(logging.INFO)
Expand All @@ -92,9 +98,9 @@ def main(sys_argv=None) -> int:
logger.info("\nNo arguments were given, exiting...")
return 0

# Main routine
import stm32pio.lib # import the module after sys.path modification
import stm32pio.lib # import the module after sys.path modification and logger configuration

# Main routine
try:
if args.subcommand == 'init':
project = stm32pio.lib.Stm32pio(args.project_path, parameters={'board': args.board})
Expand All @@ -113,15 +119,15 @@ def main(sys_argv=None) -> int:
project.pio_init()
project.patch()
if args.with_build:
project.pio_build()
project.build()
if args.editor:
project.start_editor(args.editor)

elif args.subcommand == 'generate':
project = stm32pio.lib.Stm32pio(args.project_path, save_on_destruction=False)
project.generate_code()
if args.with_build:
project.pio_build()
project.build()
if args.editor:
project.start_editor(args.editor)

Expand Down
Loading

0 comments on commit a86cb82

Please sign in to comment.