Пример #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)
Пример #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()}")
Пример #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)
Пример #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)
Пример #5
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()
Пример #6
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()
Пример #7
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)
Пример #8
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)
Пример #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)
Пример #10
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)
Пример #11
0
 def __init__(self, package: Package):
     self.is_local = False
     self._package = package
     self.log: ServiceLog = Log.add_logger(repr(self))
Пример #12
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))
Пример #13
0
 def __init__(self, initial_config: dict = {}):
     self._config: dict = initial_config
     self.log: ServiceLog = Log.add_logger(__name__)
Пример #14
0
 def __init__(self, location, log=None):
     self.location = location
     _name = self.__class__.__name__
     self.log = log or Log.add_logger(_name)