Skip to content

Commit

Permalink
Move robotpy launcher to this repository
Browse files Browse the repository at this point in the history
- Added some incremental improvements over old launcher
- Still works with previously defined subcommand entry points
- Fixes robotpy/mostrobotpy#51
  • Loading branch information
virtuald committed Jan 3, 2024
1 parent 3aa950e commit 377ede7
Show file tree
Hide file tree
Showing 5 changed files with 418 additions and 38 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,21 @@ On Linux/OSX:
```
pip3 install -U robotpy[all]
```

Run your robot.py
-----------------

Use these commands to discover subcommands that you can use to manage and execute
your robot project:

On Windows:

```
py -3 -m robotpy
```

On Linux/macOS:

```
python -m robotpy
```
39 changes: 1 addition & 38 deletions robotpy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
def main():
robotpy_logo = r"""
/PPPPPPPPPPYYYYYYYYYY\
/PPPPPPPPPPPYYYYYYYYYYY\
/PPPPPPPPPPPPYYYYYYYYYYYY\
RRRRRR OOOOOO BBBBBB OOOOOO TTTTTTTT /PPP PPPY YYYYYY YY\
RR RR OO OO BB BB OO OO TT /PPPP PPPP PY YYYYYY YYY\
RR RR OO OO BB BB OO OO TT /PPPPP PPPPP PYY YYYY YYYYY\
RR RR OO OO BB BB OO OO TT /PPPPPP PPPPP PYY YYYY YYYYYY\
RR R OO OO BB B OO OO TT /PPPPPPP PPPP PYYY YY YYYYYYYY\
RRRRRR OO OO BBBBBB OO OO TT \PPPPPPP PPPYYYY YYYYYYYYY/
RR RR OO OO BB BB OO OO TT \PPPPPP PPPPPPPPYYYYY YYYYYYYYY/
RR RR OO OO BB BB OO OO TT \PPPPP PPPPPPPPYYYYY YYYYYYYY/
RR RR OO OO BB BB OO OO TT \PPPP PPPPPPPPYYYYY YYYYYYY/
RR RR OOOOOO BBBBBB OOOOOO TT \PPP PPPPPPPPYYYYY YYYYYY/
\PPPPPPPPPPPPYYYYYYYYYYYY/
\PPPPPPPPPPPYYYYYYYYYYY/
\PPPPPPPPPPYYYYYYYYYY/
"""

try:
from colorama import init, Back, Style

init()
robotpy_logo = (
robotpy_logo.replace("R", Back.BLUE + "R" + Style.RESET_ALL)
.replace("O", Back.BLUE + "O" + Style.RESET_ALL)
.replace("B", Back.BLUE + "B" + Style.RESET_ALL)
.replace("T", Back.BLUE + "T" + Style.RESET_ALL)
.replace("P", Back.BLUE + "P" + Style.RESET_ALL)
.replace("Y", Back.BLUE + "Y" + Style.RESET_ALL)
+ Style.RESET_ALL
)
except:
pass

print(robotpy_logo)

from .main import main

if __name__ == "__main__":
main()
65 changes: 65 additions & 0 deletions robotpy/logconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# novalidate

import logging
import pprint

# TODO: Make these configurable
log_datefmt = "%H:%M:%S"
log_format = "%(asctime)s:%(msecs)03d %(levelname)-8s: %(name)-20s: %(message)s"


def configure_logging(verbose):
formatter = VerboseExceptionFormatter(fmt=log_format, datefmt=log_datefmt)

# console logging
handler = logging.StreamHandler()
handler.setFormatter(formatter)

logging.root.addHandler(handler)
logging.root.setLevel(logging.DEBUG if verbose else logging.INFO)


MAX_VARS_LINES = 30
MAX_LINE_LENGTH = 100


class VerboseExceptionFormatter(logging.Formatter):
"""
Taken from http://word.bitly.com/post/69080588278/logging-locals
"""

def __init__(self, log_locals_on_exception=True, *args, **kwargs):
self._log_locals = log_locals_on_exception
super(VerboseExceptionFormatter, self).__init__(*args, **kwargs)

def formatException(self, exc_info):
# First get the original formatted exception.
exc_text = super(VerboseExceptionFormatter, self).formatException(exc_info)
if not self._log_locals:
return exc_text
# Now we're going to format and add the locals information.
output_lines = [exc_text, "\n"]

# Retrieve locals from the innermost exception
exc = exc_info[1]
while exc.__cause__:
exc = exc.__cause__

tb = exc.__traceback__ # This is the outermost frame of the traceback.
if tb: # this should always be true, but sometimes someone messes up
while tb.tb_next:
tb = tb.tb_next # Zoom to the innermost frame.
output_lines.append("Locals at innermost frame:\n")
locals_text = pprint.pformat(tb.tb_frame.f_locals, indent=2)
locals_lines = locals_text.split("\n")
if len(locals_lines) > MAX_VARS_LINES:
locals_lines = locals_lines[:MAX_VARS_LINES]
locals_lines[-1] = "..."
output_lines.extend(
line[: MAX_LINE_LENGTH - 3] + "..."
if len(line) > MAX_LINE_LENGTH
else line
for line in locals_lines
)
output_lines.append("\n")
return "\n".join(output_lines)
Loading

0 comments on commit 377ede7

Please sign in to comment.