Example #1
0
    def __init__(self, path, name=None, templates=[], stubs=None,
                 stub_manager=None):
        self._loaded = False
        self.path = Path(path).absolute()
        self.data = self.path / '.micropy'
        self.cache = self.data / '.cache'
        self.info_path = self.path / 'micropy.json'
        self.stub_manager = stub_manager

        self.name = name or self.path.name
        self.stubs = stubs

        self.requirements = self.path / 'requirements.txt'
        self.dev_requirements = self.path / 'dev-requirements.txt'
        self.packages = {}
        self.dev_packages = {'micropy-cli': '*'}
        self.pkg_data = self.data / self.name

        self.config = {'vscode': False, 'pylint': False}
        self.log = Log.add_logger(self.name, show_title=False)
        template_log = Log.add_logger(
            "Templater", parent=self.log, show_title=False)
        self.provider = None
        if templates:
            for key in self.config:
                if key in templates:
                    self.config[key] = True
            self.provider = TemplateProvider(templates, log=template_log)
Example #2
0
    def __init__(self, templates, log=None, **kwargs):
        """Template Factory.

        Args:
            templates ([str]): List of Templates to use
            log (callable, optional): Log instance to use.
                Defaults to None. If none, creates a new one.
            run_checks (bool, optional): Whether to run template checks.
                Defaults to True.

        """
        self.run_checks = kwargs.get('run_checks', True)
        self.template_names = set(
            chain.from_iterable([self.TEMPLATES.get(t)[0] for t in templates]))
        self.files = {
            k: v
            for k, v in self._template_files.items()
            if k in self.template_names
        }
        self.log = log or Log.add_logger('Templater')
        if self.__class__.ENVIRONMENT is None:
            loader = FileSystemLoader(str(self.TEMPLATE_DIR))
            self.__class__.ENVIRONMENT = Environment(loader=loader)
            self.log.debug("Created Jinja2 Environment")
            self.log.debug(
                f"Detected Templates: {self.ENVIRONMENT.list_templates()}")
Example #3
0
 def __init__(self, name, location, path, **kwargs):
     self.name = name
     self.path = path
     self.log = Log.add_logger(self.name)
     self.location = location
     self.packages = kwargs.get("packages", [])
     self.repos.add(self)
Example #4
0
 def __init__(self, resource=None, repos=None):
     self._loaded = set()
     self._firmware = set()
     self.resource = resource
     self.repos = repos
     self.log = Log.add_logger("Stubs", stdout=False, show_title=False)
     if self.resource:
         self.load_from(resource, strict=False)
Example #5
0
 def __init__(self,
              *args: Any,
              source_format: Type[ConfigSource] = JSONConfigSource,
              default: dict = {},
              should_sync: Optional[Callable[..., bool]] = None):
     self.log: ServiceLog = Log.add_logger(f"{__name__}")
     self.should_sync = should_sync or (lambda *args: True)
     self._config = deepcopy(default)
     self.format = source_format
     self._source: ConfigSource = self.format(*args)
     self.sync()
Example #6
0
 def __init__(self, port, connect=True, verbose=False):
     self.connected = False
     self.port = port
     self.rsh = rsh
     self.rsh.ASCII_XFER = False
     self.rsh.QUIET = not verbose
     self.log = Log.add_logger('Pyboard', 'bright_white')
     self._outline = []
     self.format_output = None
     if connect:
         return self.connect()
Example #7
0
def cli(ctx, mpy, skip_checks=False):
    """CLI Application for creating/managing Micropython Projects."""
    if ctx.invoked_subcommand is None:
        if not mpy.project.exists:
            return click.echo(ctx.get_help())
    latest = utils.is_update_available()
    if latest:
        log = Log.get_logger('MicroPy')
        log.title("Update Available!")
        log.info(f"Version $B[v{latest}] is now available")
        log.info("You can update via: $[pip install --upgrade micropy-cli]\n")
    mpy.RUN_CHECKS = not skip_checks
Example #8
0
 def __init__(self,
              *args: Any,
              source_format: Type[ConfigSource] = JSONConfigSource,
              default: dict = {}):
     self.log: ServiceLog = Log.add_logger(f"{__name__}")
     self.format = source_format
     self._source: ConfigSource = self.format(*args)
     self._config = deepcopy(default)
     if self._source.exists:
         with self._source as src:
             self.log.debug("loaded config values")
             dpath.util.merge(self._config, src, flags=dpath.MERGE_REPLACE)
Example #9
0
 def __init__(self, templates=None, run_checks=True, **kwargs):
     self.templates = templates or []
     self.run_checks = run_checks
     self.enabled = {'vscode': False, 'pylint': False}
     self.log = Log.add_logger('Templater', show_title=False)
     if templates:
         for key in self.enabled:
             if key in self.templates:
                 self.enabled[key] = True
     self.provider = TemplateProvider(self.templates,
                                      run_checks=self.run_checks,
                                      log=self.log,
                                      **kwargs)
Example #10
0
def cli(ctx):
    """CLI Application for creating/managing Micropython Projects."""
    if ctx.invoked_subcommand is None:
        proj = Project.resolve('.')
        if not proj:
            return click.echo(ctx.get_help())
    latest = utils.is_update_available()
    if latest:
        log = Log.get_logger('MicroPy')
        log.title("Update Available!")
        log.info(f"Version $B[v{latest}] is now available")
        log.info(
            "You can update via: $[pip install --upgrade micropy-cli]\n")
Example #11
0
    def __init__(self, path: str, name: Optional[str] = None, **kwargs: Any):
        self._children: List[Type[ProjectModule]] = []
        self.path: Path = Path(path).absolute()
        self.data_path: Path = self.path / '.micropy'
        self.info_path: Path = self.path / 'micropy.json'
        self.cache_path: Path = self.data_path / '.cache'
        self._context = Config(source_format=DictConfigSource)

        self.name: str = name or self.path.name
        self._config: Config = Config(self.info_path,
                                      default={'name': self.name},
                                      should_sync=lambda *a: self.exists)
        self.log: ServiceLog = Log.add_logger(self.name, show_title=False)
Example #12
0
 def __init__(self, path: str, name: Optional[str] = None, **kwargs: Any):
     self._children: List[Type[ProjectModule]] = []
     self.path: Path = Path(path).absolute()
     self.data_path: Path = self.path / ".micropy"
     self.info_path: Path = self.path / "micropy.json"
     self.cache_path: Path = self.data_path / ".cache"
     self._cache = Config(self.cache_path)
     self._context = Config(source_format=DictConfigSource, default={"datadir": self.data_path})
     self.name: str = name or self.path.name
     default_config = {
         "name": self.name,
     }
     self._config: Config = Config(self.info_path, default=default_config)
     self.log: ServiceLog = Log.add_logger(self.name, show_title=False)
Example #13
0
# -*- coding: utf-8 -*-

"""Various requirement checks for templates."""

import subprocess as subproc
from functools import partial as _p

from packaging import version

from micropy.logger import Log

VSCODE_MS_PY_MINVER = "2019.9.34474"

log = Log.get_logger('MicroPy')


def iter_vscode_ext(name=None):
    """Iterates over installed VSCode Extensions.

    Args:
        name (str, optional): Name of Extension to Yield

    """
    _cmd = "code --list-extensions --show-versions"
    proc = subproc.run(_cmd, stdout=subproc.PIPE, stderr=subproc.PIPE, shell=True)
    results = [e.strip() for e in proc.stdout.splitlines()]
    for ext in results:
        ename, vers = ext.split('@')
        if not name:
            yield (ename, vers)
        if name and ename == name:
Example #14
0
 def __init__(self):
     self.log = Log.get_logger('MicroPy')
     self.verbose = True
     self.log.debug("MicroPy Loaded")
     if not data.STUB_DIR.exists():
         self.setup()
Example #15
0
 def __init__(self, package: Package):
     self.is_local = False
     self._package = package
     self.log: ServiceLog = Log.add_logger(repr(self))
Example #16
0
 def __init__(self, name: str):
     self.methods: List[ProxyItem[Callable[..., Any]]] = []
     self.instances: List[Type[ProjectModule]] = []
     self._name: str = name
     self.log: ServiceLog = Log.add_logger(str(self))
Example #17
0
 def __init__(self):
     self.log = Log.get_logger('MicroPy')
     self.setup()
Example #18
0
 def __init__(self, initial_config: dict = {}):
     self._config: dict = initial_config
     self.log: ServiceLog = Log.add_logger(__name__)
Example #19
0
 def __init__(self, location, log=None):
     self.location = location
     _name = self.__class__.__name__
     self.log = log or Log.add_logger(_name)
Example #20
0
# -*- coding: utf-8 -*-
"""Various requirement checks for templates."""

import subprocess as subproc
from functools import partial as _p

from micropy.logger import Log
from packaging import version

VSCODE_MS_PY_MINVER = "2019.9.34474"

log = Log.get_logger("MicroPy")


def iter_vscode_ext(name=None):
    """Iterates over installed VSCode Extensions.

    Args:
        name (str, optional): Name of Extension to Yield

    """
    _cmd = "code --list-extensions --show-versions"
    proc = subproc.run(_cmd,
                       stdout=subproc.PIPE,
                       stderr=subproc.PIPE,
                       shell=True)
    results = [e.strip() for e in proc.stdout.splitlines()]
    for ext in results:
        ename, vers = ext.split("@")
        if not name:
            yield (ename, vers)