Пример #1
0
 def test_add_docs(self):
     runner = CliRunner()
     with runner.isolated_filesystem():
         shell('touch setup.py')
         cwd = Path.cwd()
         runner.invoke(cli, ['add', 'docs'])
         self.assertTrue(exists(cwd / 'docs' / 'conf.py'))
Пример #2
0
def create_docs(path, name, author):
    """ Create a project documentation.

    Parameters
    ----------
    path: str or Pathlib path
        Path of the project root. Folder 'docs' will be created as subfolder.

    name: str
        Name of the project

    author:
        Author of the project
    """

    os.makedirs(path / 'docs')
    render(path / 'docs' / 'requirements.txt', 'sphinx\nsphinx_rtd_theme\n')

    shell(find_python() + ' -m pip install -r requirements.txt',
          root=str(path / 'docs'))

    cmd = find_python(
    ) + ' -m sphinx.cmd.quickstart -p %s -a "%s" -v 0.0.1 --no-sep -l en -r 0.0.1 docs' % (
        name,
        author,
    )
    shell(cmd, str(path), silent=False)

    replace(path / 'docs' / 'conf.py', {'alabaster': 'sphinx_rtd_theme'})
Пример #3
0
 def test_add_license(self):
     runner = CliRunner()
     with runner.isolated_filesystem():
         shell('touch setup.py')
         cwd = Path.cwd()
         add_license(cwd, 'MIT')
         self.assertTrue(exists(cwd / 'LICENSE'))
Пример #4
0
 def test_add_license_existing(self):
     runner = CliRunner()
     with runner.isolated_filesystem():
         with self.assertRaises(click.BadParameter):
             shell('touch LICENSE')
             add_license('.', 'MIT')
         self.assertTrue(exists(Path.cwd() / 'LICENSE'))
Пример #5
0
def run_docs():
    """Build the documentation and show it in the browser."""

    cwd = Path.cwd()
    if not exists(cwd / 'docs'):
        raise click.BadParameter('Cannot find docs folder.')

    shell('make clean', root=str(cwd / 'docs'), silent=False)
    shell(find_python() + ' -m sphinx.cmd.build -M html . _build', root=str(cwd / 'docs'), silent=False)
    click.launch(str(cwd / 'docs' / '_build' / 'html' / 'index.html'))
Пример #6
0
def run_flake8(dirs):
    """Run flake8 style enforcement in specified directories.

    Parameters
    ----------
    dirs: list of str
        The directories to scan for style violations.
    """

    shell(find_python() + ' -m pip install --upgrade flake8')
    shell(find_python() + ' -m flake8 ' + ' '.join(dirs) + ' --max-line-length=120', silent=False)
Пример #7
0
    def _test_add_setup_py_overwrite(self):
        runner = CliRunner()
        with runner.isolated_filesystem():
            shell('touch setup.py')
            cwd = Path.cwd()
            assert getsize(cwd / 'setup.py') == 0
            runner.invoke(cli, ['add', 'setup.py', '--name', 'test_project'],
                          input='\n\n\n\n\ny\n')

            self.assertTrue(exists(cwd / 'setup.py'))
            assert getsize(cwd / 'setup.py') > 0
Пример #8
0
    def test_add_github_action_no_overwrite(self):
        runner = CliRunner()
        with runner.isolated_filesystem():
            cwd = Path.cwd()
            os.mkdir(cwd / '.github')
            os.mkdir(cwd / '.github' / 'workflows')
            target = cwd / '.github' / 'workflows' / 'check.yml'
            shell('touch ' + str(target))

            assert exists(target)
            runner.invoke(cli, ['add', 'github-action'], input='abc\nghi\nn\n')

            assert exists(target)
            check_yml = file_content(target)
            assert 'abc' not in check_yml
Пример #9
0
    def test_deploy(self):
        runner = CliRunner()
        with unittest.mock.patch('manati.deploy.do_twine') as mock:
            instance = mock.return_value
            instance.method.return_value = 'OK'

            with runner.isolated_filesystem():
                create_project_structure('test_project',
                                         pathlib.Path('test_project'), {
                                             'PROJECT_NAME': 'test_project',
                                             'MODULE_NAME': 'test_project'
                                         })

                os.chdir(pathlib.Path.cwd() / 'test_project')
                shell('mkdir build dist')
                result = runner.invoke(cli, ['deploy', 'pypi'], input='y\n')
                assert result.exit_code == 0
Пример #10
0
    def test_run_tests(self):
        runner = CliRunner()
        with runner.isolated_filesystem() as fs:
            create_project_structure('test_project', Path('test_project'), {
                'PROJECT_NAME': 'test_project',
                'MODULE_NAME': 'test_project'
            })

            os.chdir(Path.cwd() / 'test_project')
            shell(find_python() + ' -m pip install -e .')
            result = runner.invoke(
                cli, ['run', 'tests', '-r', 'unittest', '-t', 'tests'])
            assert result.exit_code == 0

            result = runner.invoke(
                cli, ['run', 'tests', '-r', 'pytest', '-t', 'tests'])
            assert result.exit_code == 0
Пример #11
0
def run_coverage(source, test_dir, runner):

    if not exists(test_dir):
        raise click.BadParameter('No such folder or file: %s' % test_dir)

    if not exists(source):
        raise click.BadParameter('No such folder %s' % source)

    if runner == 'unittest':
        shell(find_python() + ' -m pip install --upgrade coverage')
        shell(find_python() + ' -m coverage run --source=%s -m unittest discover %s' %
              (source, test_dir), silent=False)
    elif runner == 'pytest':
        shell(find_python() + ' -m pip install --upgrade coverage pytest')
        shell(find_python() + ' -m coverage run --source=%s -m pytest %s' %
              (source, test_dir), silent=False)
    else:
        raise click.BadParameter('No such test runner: %s' % runner)

    shell(find_python() + ' -m coverage report -m', silent=False)
Пример #12
0
def deploy_pypi():
    """Deploy project in current directory to PyPi."""

    cwd = Path.cwd()

    if not exists(cwd / 'setup.py'):
        raise click.UsageError(
            'No setup.py found. Is this really a project root?')

    if exists(cwd / 'build') or exists(cwd / 'dist'):
        if click.confirm(
                'build and/or dist folder found which will be deleted. Continue?'
        ):
            shutil.rmtree(cwd / 'build')
            shutil.rmtree(cwd / 'dist')
        else:
            click.Abort()
            return

    shell(find_python() + ' -m pip install --upgrade wheel twine',
          silent=False)
    shell(find_python() + ' setup.py sdist bdist_wheel', silent=False)

    do_twine()
Пример #13
0
def run_tests(test_folder, runner):

    if not exists(test_folder):
        raise click.BadParameter('No such folder %s' % test_folder)

    if runner == 'unittest':
        shell(find_python() +' -m unittest discover ' + str(test_folder), silent=False)
    elif runner == 'pytest':
        shell(find_python() + ' -m pip install --upgrade pytest')
        shell(find_python() + ' -m pytest ' + str(test_folder), silent=False)
    else:
        raise click.BadParameter('No such test runner: %s' % runner)
Пример #14
0
def do_twine():
    """Login and upload to PyPi."""
    click.echo('Log in to PyPi...')
    shell(find_python() + ' -m twine upload *', 'dist', silent=False)
Пример #15
0
def deploy_github(url, main):
    shell('git remote add origin ' + url, silent=False)
    shell('git branch -M ' + main, silent=False)
    shell('git push -u origin ' + main, silent=False)
Пример #16
0
def create_git_repo(name):
    shell('git init', root=name)
Пример #17
0
def pip_install_project(name):
    shell(find_python() + ' -m pip install -e .', root=name)
Пример #18
0
def build_documentation(name):
    shell(find_python() + ' -m sphinx.cmd.build -M html . _build',
          root=str(Path.cwd() / name / 'docs'))
Пример #19
0
 def test_add_license_with_string(self):
     runner = CliRunner()
     with runner.isolated_filesystem():
         shell('touch setup.py')
         add_license('.', 'MIT')
         self.assertTrue(exists(Path.cwd() / 'LICENSE'))