コード例 #1
0
def package():
    with safe_cd(SRC):
        for folder in ["build", "dist", PROJECT_NAME + ".egg-info"]:
            execute("rm", "-rf", folder)

    with safe_cd(SRC):
        execute(PYTHON, "-m", "build")

    os.system('say "package complete."')
コード例 #2
0
def lint():
    """
    Lint
    """
    with safe_cd(SRC):
        if os.path.isfile("lint.txt"):
            execute("rm", "lint.txt")

    with safe_cd(SRC):
        command = (
            "{0} pylint --rcfile=pylintrc.ini {2}".format(
                PIPENV, PROJECT_NAME
            )
            .strip()
            .replace("  ", " ")
        )
        print(command)
        command = command.split(" ")

        # keep out of src tree, causes extraneous change detections
        lint_output_file_name = "lint.txt"
        with open(lint_output_file_name, "w") as outfile:
            env = config_pythonpath()
            subprocess.call(command, stdout=outfile, env=env)

        fatal_errors = sum(
            1
            for line in open(lint_output_file_name)
            if "no-member" in line
            or "no-name-in-module" in line
            or "import-error" in line
        )

        if fatal_errors > 0:
            for line in open(lint_output_file_name):
                if (
                    "no-member" in line
                    or "no-name-in-module" in line
                    or "import-error" in line
                ):
                    print(line)

            print("Fatal lint errors : {0}".format(fatal_errors))
            exit(-1)

        cutoff = 100
        num_lines = sum(
            1
            for line in open(lint_output_file_name)
            if "*************" not in line
            and "---------------------" not in line
            and "Your code has been rated at" not in line
        )
        if num_lines > cutoff:
            raise TypeError(
                "Too many lines of lint : {0}, max {1}".format(num_lines, cutoff)
            )
コード例 #3
0
def docs():
    """
    Docs
    """
    with safe_cd(SRC):
        with safe_cd("docs"):
            my_env = config_pythonpath()
            command = "{0} make html".format(PIPENV).strip()
            print(command)
            execute_with_environment(command, env=my_env)
コード例 #4
0
def package():
    """
    package, but don't upload
    """
    with safe_cd(SRC):
        for folder in ["build", "dist", PROJECT_NAME + ".egg-info"]:
            execute("rm", "-rf", folder)

    with safe_cd(SRC):
        execute(PYTHON, "setup.py", "sdist", "--formats=gztar,zip")
コード例 #5
0
def check_setup_py():
    with safe_cd(SRC):
        if IS_TRAVIS:
            execute(PYTHON, *("setup.py check -r -s".split(" ")))
        else:
            execute(*("{0} {1} setup.py check -r -s".format(
                PIPENV, PYTHON).strip().split(" ")))
コード例 #6
0
def pytests():
    with safe_cd(SRC):
        my_env = config_pythonpath()
        command = "{0} {1} -m pytest {2}".format(PIPENV, PYTHON,
                                                 "tests").strip()
        print(command)
        execute_with_environment(command, env=my_env)
コード例 #7
0
def dead_code():
    """
    This also finds code you are working on today!
    """
    with safe_cd(SRC):
        exclusions = "--exclude *settings.py,migrations/,*models.py,*_fake.py,*tests.py,*ui/admin.py"
        if IS_GITHUB_CI:
            command = (
                "{0} vulture {1} {2}".format(PYTHON, PROJECT_NAME, exclusions)
                .strip()
                .split()
            )
        else:
            command = (
                "{0} vulture {1} {2}".format(PIPENV, PROJECT_NAME, exclusions)
                .strip()
                .split()
            )

        output_file_name = "dead_code.txt"
        with open(output_file_name, "w") as outfile:
            env = config_pythonpath()
            subprocess.call(command, stdout=outfile, env=env)

        cutoff = 120
        num_lines = sum(1 for line in open(output_file_name) if line)
        if num_lines > cutoff:
            print(
                "Too many lines of dead code : {0}, max {1}".format(num_lines, cutoff)
            )
            exit(-1)
コード例 #8
0
ファイル: test_safecd.py プロジェクト: rags/pynt-contrib
    def test_change_yield_revert(self):
        """Safe cd should change directory, yield and revert back"""
        with safe_cd(self.temp_dir):
            os.path.exists(self.temp_dir)

        self.assertEqual(os.getcwd(), self.cwd,
                         "Working directory was not restored.")
コード例 #9
0
def pin_dependencies():
    """
    Create requirement*.txt
    """
    with safe_cd(SRC):
        execute(
            *("{0} pipenv_to_requirements".format(PIPENV).strip().split(" ")))
コード例 #10
0
    def test_change_error_revert(self):
        """Should restore directory after an exception during yield"""
        try:
            with safe_cd(self.temp_dir):
                raise ValueError
        except ValueError:
            pass

        self.assertEqual(os.getcwd(), self.cwd, "Working directory was not restored.")
コード例 #11
0
    def test_change_error_revert(self):
        """Should restore directory after an exception during yield"""
        try:
            with safe_cd(self.temp_dir):
                raise ValueError
        except ValueError:
            pass

        self.assertEqual(os.getcwd(), self.cwd, "Working directory was not restored.")
コード例 #12
0
def prospector():
    """
    Catch a few things with a non-strict propector run
    """
    with safe_cd(SRC):
        command = "{0} prospector {1} --profile {1}_style --pylint-config-file=pylintrc.ini --profile-path=.prospector".format(
            PIPENV, PROJECT_NAME).strip().replace("  ", " ")
        print(command)
        execute(*(command.split(" ")))
コード例 #13
0
def upload_package():
    """
    Upload
    """
    with safe_cd(SRC):
        if IS_GITHUB_CI:
            pass
        else:
            execute(
                *("{0} twine upload dist/*".format(PIPENV).strip().split(" ")))
コード例 #14
0
def coverage():
    """
    Coverage, which is a bit redundant with nose test
    """
    print("Coverage tests always re-run")
    with safe_cd(SRC):
        my_env = config_pythonpath()
        command = "{0} py.test {1} --cov={2} --cov-report html:coverage --cov-fail-under 40  --verbose".format(
            PIPENV, "test", PROJECT_NAME)
        execute_with_environment(command, my_env)
コード例 #15
0
def coverage():
    """
    Do tests exercise enough code?
    """
    print("Coverage tests always re-run")
    with safe_cd(SRC):
        my_env = config_pythonpath()
        command = "{0} py.test {1} --cov={2} --cov-report html:coverage --cov-fail-under 55  --verbose".format(
            PIPENV, "test", PROJECT_NAME
        )
        execute_with_environment(command, my_env)
コード例 #16
0
def check_setup_py():
    # if
    # ValueError: ZIP does not support timestamps before 1980
    # then run this to ID
    #   find . -mtime +13700 -ls
    with safe_cd(SRC):
        if IS_TRAVIS:
            execute(PYTHON, *("setup.py check -r -s".split(" ")))
        else:
            execute(*("{0} {1} setup.py check -r -s".format(
                PIPENV, PYTHON).strip().split(" ")))
コード例 #17
0
def runserver():
    """Runs the server using gunicorn"""
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "readonly.settings.local")
    with safe_cd(paths.project_paths.manage_root):
        project.venv_execute(
           'gunicorn',
           '--reload',
           '-b', '0.0.0.0:8000',
           '--access-logfile', '-',
           'readonly.wsgi',
       )
コード例 #18
0
def upload_package():
    """
    Upload
    """
    with safe_cd(SRC):
        if IS_GITHUB_CI:
            pass
        else:
            execute(
                *("{0} {1} setup.py upload".format(PIPENV, PYTHON).strip().split(" "))
            )
コード例 #19
0
def compile_mark_down():
    """
    Convert MD to RST
    """
    with safe_cd(SRC):
        if IS_TRAVIS:
            command = "pandoc --from=markdown --to=rst --output=README.rst README.md".strip(
            ).split(" ")
        else:
            command = "{0} pandoc --from=markdown --to=rst --output=README.rst README.md".format(
                PIPENV).strip().split(" ")
        execute(*(command))
コード例 #20
0
def compile_mark_down():
    """
    Convert MD to RST
    """
    # print("Not compiling README.md because moderately complex MD makes pypi rst parser puke.")
    with safe_cd(SRC):
        if IS_TRAVIS:
            command = "pandoc --from=markdown --to=rst --output=README.rst README.md".strip(
            ).split(" ")
        else:
            command = "{0} pandoc --from=markdown --to=rst --output=README.rst README.md".format(
                PIPENV).strip().split(" ")
        execute(*(command))
コード例 #21
0
def check_setup_py():
    """
    Setup.py checks package things including README.rst
    """
    with safe_cd(SRC):
        if IS_GITHUB_CI:
            execute(PYTHON, *("setup.py check -r -s".split(" ")))
        else:
            execute(
                *(
                    "{0} {1} setup.py check -r -s".format(PIPENV, PYTHON)
                    .strip()
                    .split(" ")
                )
            )
コード例 #22
0
def formatting():
    with safe_cd(SRC):
        if sys.version_info < (3, 6):
            print("Black doesn't work on python 2")
            return
        command = "{0} black {1}".format(PIPENV, PROJECT_NAME).strip()
        print(command)
        result = execute_get_text(command)
        assert result
        changed = []
        for line in result.split("\n"):
            if "reformatted " in line:
                file = line[len("reformatted "):].strip()
                changed.append(file)
        for change in changed:
            command = "git add {0}".format(change)
            print(command)
            execute(*(command.split(" ")))
コード例 #23
0
def pin_dependencies():
    """
    Create requirement*.txt
    """
    with safe_cd(SRC):

        def write_reqs(filename: str, command: str):
            result = execute_get_text(command)
            lines = result.split("\n")
            with open(filename, "w") as output_reqs:
                for i, line in enumerate(lines):
                    if "Courtesy Notice:" not in line:
                        output_reqs.writelines(
                            [line + ("\n" if i != len(lines) - 1 else "")])

        write_reqs("requirements.txt",
                   "{0} lock --requirements".format("pipenv"))
        write_reqs("requirements-dev.txt",
                   "{0} lock --requirements --dev".format("pipenv"))
コード例 #24
0
ファイル: build.py プロジェクト: pombredanne/pypi_librarian
def dead_code():
    """
    This also finds code you are working on today!
    """
    with safe_cd(SRC):
        if IS_TRAVIS:
            command = "{0} vulture {1}".format(PYTHON, PROJECT_NAME).strip().split()
        else:
            command = "{0} vulture {1}".format(PIPENV, PROJECT_NAME).strip().split()

        output_file_name = "dead_code.txt"
        with open(output_file_name, "w") as outfile:
            env = config_pythonpath()
            subprocess.call(command, stdout=outfile, env=env)

        cutoff = 1000
        print("High cutt off for dead code because not even out of beta")
        num_lines = sum(1 for line in open(output_file_name) if line)
        if num_lines > cutoff:
            print("Too many lines of dead code : {0}, max {1}".format(num_lines, cutoff))
            exit(-1)
コード例 #25
0
def compile_py():
    """
    Catch on the worst syntax errors
    """
    with safe_cd(SRC):
        execute(PYTHON, "-m", "compileall", PROJECT_NAME)
コード例 #26
0
def jiggle_version():
    with safe_cd(SRC):
        command = "{0} jiggle_version here --module={1}".format(
            PIPENV, PROJECT_NAME).strip()
        execute(*(command.split(" ")))
コード例 #27
0
def compile_py():
    with safe_cd(SRC):
        execute(PYTHON, "-m", "compileall", PROJECT_NAME)
コード例 #28
0
def clean():
    with safe_cd(SRC):
        execute("rm", "-rf", ".mypy_cache", ".build_state", "dist", "build",
                PROJECT_NAME + ".egg-info", "dead_code.txt", "mypy_errors.txt",
                "detect-secrets-results.txt", "lint.txt")
コード例 #29
0
def test_manage(*args, **kwargs):
    """Runs all tests through manage.py w/pynt args/kwargs"""
    with safe_cd(project_paths.manage_root):
        project.execute_manage('test', *args, **kwargs)
コード例 #30
0
def clean_state():
    with safe_cd(".build_state"):
        # wild cards don't expand by default
        for file in os.listdir("."):
            if file.startswith("last") and file.endswith(".txt"):
                execute("rm", "-f", str(file))
コード例 #31
0
ファイル: build.py プロジェクト: Sambit009/django-andablog
def rundocserver():
    """Runs the sphinx-autobuild server"""
    with safe_cd('docs'):
        project.venv_execute('sphinx-autobuild', '.', '_build/html')
コード例 #32
0
def test_venv():
    """Runs all tests on venv"""
    with safe_cd('demo'):
        project.execute_manage('test', 'andablog')
        project.execute_manage('test')
コード例 #33
0
def pwd_ls(dir="/tmp"):
    '''Run "pwd followed by "ls" on a given directory'''
    with safe_cd(dir):
        execute('pwd')
    execute("ls",dir)
コード例 #34
0
def rundocserver():
    """Runs the sphinx-autobuild server"""
    with safe_cd('docs'):
        project.venv_execute('sphinx-autobuild', '.', '_build/html')
コード例 #35
0
def docs(*args, **kwargs):
    """Makes the docs w/pynt args/kwargs"""
    with safe_cd('docs'):
        project.venv_execute('sphinx-build', '-b', 'html', '.', '_build/html', *args, **kwargs)
コード例 #36
0
    def test_change_yield_revert(self):
        """Safe cd should change directory, yield and revert back"""
        with safe_cd(self.temp_dir):
            os.path.exists(self.temp_dir)

        self.assertEqual(os.getcwd(), self.cwd, "Working directory was not restored.")