コード例 #1
0
    def update_informations(self, create=False, path=None):
        """
        Updates class-attributes with new informations collected from
        meta.yaml, git config and current datetime.

        Parameters
        ----------
        create: bool
            If project isn't created yet the name of the environment can't be
            extracted from the meta.yaml. In this case it has to be combined
            from companyname, namespace and projectname.
        path: pathlib.Path
            The projects-path.

        Note
        ----
        Uses :class:`conda.MetaYaml` to collect the name of environment
        from the current project if **create** is False.
        To collect git-specific informations :class:`git.GitRepo` is used.
        Checks for valid project-definition with :class:`validators.SProject`.
        """
        self.environment = f'{self.company}-{self.namespace}-{self.project}'
        if create:
            if not path:
                path = self.path.parent
            self.git = git.GitRepo(path=self.path)
        else:
            #if not self.environment in str(self.path):
            #    self.path = self.path / self.environment
            if not path:
                path = self.path
            meta_yaml = conda.MetaYaml(path=path / CONFIG['meta_yaml_path'])
            self.environment = meta_yaml.package_name
            self.git = git.GitRepo(path=self.path)
            self.version = self.git.get_tag()
        now = dt.datetime.now()
        self.year = now.strftime('%Y')
        self.today = now.strftime('%Y-%m-%d %H:%M')
        self.username = self.git.get_username()
        self.email = self.git.get_email()
        try:
            validators.SProject(strict=True).load(self.__dict__)
        except ValidationError as err:
            inform.error('Can\'t collect project information.')
            inform.error('Invalid value for following params:')
            for key, value in err.messages.items():
                inform.error(f'{key}: {value}')
            inform.critical()
コード例 #2
0
    def info(self, path=None):
        """
        Collects and prints information about the pproject-configuration and
        the current project.

        Parameters
        ----------
        path: pathlib.Path
            The projects path.

        Note
        ----
        Uses :class:`conda.MetaYaml` to collect the project informations.
        The current version is collected by :func:`get_git_tag`.
        Resulting packagename is collected by
        :func:`conda.build_package`.
        The pproject-settings are collected by the global variables.
        """
        if not path:
            path = self.path
        meta_yaml = conda.MetaYaml()
        dependencies = f'- {meta_yaml.dependencies[0]}'
        for dep in meta_yaml.dependencies[1:]:
            try:
                search = (dep.replace("<", "").replace(">", "").replace(
                    "=", "").replace(" ", "="))
                utils.run_in_bash(
                    f'{Path(CONFIG["conda_folder"]) / "bin/conda"} search '
                    f'{search}')
                dependencies += f'\n{"." * 26} - {dep}'
            except CalledProcessError:
                dependencies += (f'\n{"." * 26} {inform.RED}- {dep} '
                                 f'(not available in channels){inform.NCOLOR}')
        project_infos = [
            '', ' PROJECT INFO'.rjust(80, '='),
            f'{" name".rjust(26, ".")}  {self.environment}',
            f'{" reponame".rjust(26, ".")}  {self.environment}',
            f'{" current version-tag".rjust(26, ".")}  {self.git.get_tag()}',
            f'{" pythonversion".rjust(26, ".")}  {self.pythonversion}',
            f'{" dependencies".rjust(26, ".")} {dependencies}', ''
        ]
        for project_info in project_infos:
            print(f'{inform.BOLD}{project_info}{inform.NCOLOR}')
コード例 #3
0
    def update(self, path=None):
        """
        Updates the project-related conda-environment.
        If it already exists it will be removed and then recreated.
        This ensures to remove dependencies of packages which aren't required
        anymore.
        If the environment doesn't exist yet, the environment will be created.
        Finally stores the md5sum of the based meta.yaml file inside a file
        to enable the pproject-autoenv functionality triggered by changes
        inside the meta.yaml file.

        Parameters
        ----------
        path: str
            Path of the required meta.yaml file. Only required if the meta.yaml
            is outside of the current working directory

        Note
        ----
        The pythonversion and the dependencies are collected with
        :class:`conda.MetaYaml`. Environment creation/removal is done using
        :class:`conda.CondaEnvironment`.
        To calculate the new md5sum of the meta.yaml and store it inside the
        hash.md5-file, :func:`update_md5sum` is used.
        """
        self.update_informations()
        if not path:
            path = self.path
        inform.info(f'Environment: {self.environment}')
        inform.info('Updating env')
        meta_yaml = conda.MetaYaml(path=path / CONFIG['meta_yaml_path'])
        self.pythonversion = meta_yaml.pythonversion
        env = conda.CondaEnvironment(name=self.environment)
        if env.exists():
            inform.info('Removing env')
            env.remove()
        inform.info('Creating env')
        env.create(dependencies=meta_yaml.dependencies)
        self.update_md5sum()
        inform.finished()
コード例 #4
0
 def test_metayaml_get_content_ok(self):
     os.chdir(CURRENT_PATH)
     myaml = conda.MetaYaml(path=Path('conda-build/meta.yaml').absolute())
     myaml_content = myaml.get_content()
     assert myaml_content == correct_myaml_content
コード例 #5
0
 def test_metayaml_update_ok(self):
     os.chdir(CURRENT_PATH)
     myaml = conda.MetaYaml(path=Path('conda-build/meta.yaml').absolute())
     myaml.update()
コード例 #6
0
 def test_metayaml_fail(self):
     os.chdir(CURRENT_PATH)
     with pytest.raises(AttributeError):
         conda.MetaYaml(path=Path('/tmp/conda-build/meta.yaml'))
コード例 #7
0
def run(options, path=Path.cwd()):
    """
    Parameters
    ----------
    options: argparse.Namespace
    path: pathlib.Path
    """
    if options.tool == 'info':
        if options.infotype == 'general':
            general_info()
        elif options.infotype == 'project':
            try:
                meta_yaml = conda.MetaYaml()
                company, namespace, projectname = (
                    meta_yaml.package_name.split('-'))
                pythonversion = meta_yaml.pythonversion
                prj = Project(company=company,
                              namespace=namespace,
                              project=projectname,
                              pythonversion=pythonversion,
                              path=path)
                prj.update_informations(create=True, path=path)
                prj.info()
            except Exception as err:
                print(err)
                inform.error('Not a valid pproject-project!')
                inform.critical()
    else:
        if options.tool not in ('create', ):
            meta_yaml = conda.MetaYaml()
            company, namespace, projectname = meta_yaml.package_name.split('-')
            pythonversion = meta_yaml.pythonversion
        else:
            company, namespace, projectname = [
                CONFIG['company'], options.namespace, options.projectname
            ]
            pythonversion = options.pythonversion
        prj = Project(company=company,
                      namespace=namespace,
                      project=projectname,
                      pythonversion=pythonversion,
                      path=path)
        if options.tool == 'update':
            prj.update_informations()
            prj.update()
        elif options.tool == 'test':
            prj.update_informations()
            prj.test(path=path)
        elif options.tool == 'sphinx':
            prj.update_informations()
            prj.sphinx()
        elif options.tool == 'create':
            prj.create(on_vcs=options.remote, path=path)
        elif options.tool == 'build':
            prj.update_informations()
            prj.build(publish=options.publish)
        elif options.tool == 'version':
            prj.update_informations()
            prj.new_version(vtype=options.versiontype, message=options.message)
        elif options.tool == 'release':
            try:
                envname = options.envname
            except:
                envname = f'{Path.cwd().name}_env'
            prj.update_informations()
            prj.release(dst=options.userathost, envname=envname)