Example #1
0
def test_scripts(PipenvInstance):
    with PipenvInstance(chdir=True) as p:
        with open(p.pipfile_path, 'w') as f:
            f.write(r"""
[scripts]
printfoo = "python -c \"print('foo')\""
notfoundscript = "randomthingtotally"
appendscript = "cmd arg1"
multicommand = "bash -c \"cd docs && make html\""
            """)
        c = p.pipenv('install')
        assert c.return_code == 0

        c = p.pipenv('run printfoo')
        assert c.return_code == 0
        assert c.out == 'foo\n'
        assert c.err == ''

        c = p.pipenv('run notfoundscript')
        assert c.return_code == 1
        assert c.out == ''
        if os.name != 'nt':     # TODO: Implement this message for Windows.
            assert 'Error' in c.err
            assert 'randomthingtotally (from notfoundscript)' in c.err

        project = Project()

        script = project.build_script('multicommand')
        assert script.command == 'bash'
        assert script.args == ['-c', 'cd docs && make html']

        script = project.build_script('appendscript', ['a', 'b'])
        assert script.command == 'cmd'
        assert script.args == ['arg1', 'a', 'b']
Example #2
0
def test_get_source(PipenvInstance, pypi, lock_first):
    with PipenvInstance(pypi=pypi, chdir=True) as p:
        with open(p.pipfile_path, 'w') as f:
            contents = """
[[source]]
url = "{0}"
verify_ssl = false
name = "testindex"

[[source]]
url = "https://pypi.org/simple"
verify_ssl = "true"
name = "pypi"

[packages]
pytz = "*"
six = {{version = "*", index = "pypi"}}

[dev-packages]
            """.format(os.environ['PIPENV_TEST_INDEX']).strip()
            f.write(contents)

        if lock_first:
            # force source to be cached
            c = p.pipenv('lock')
            assert c.return_code == 0
        project = Project()
        sources = [
            ['pypi', 'https://pypi.org/simple'],
            ['testindex', os.environ.get('PIPENV_TEST_INDEX')]
        ]
        for src in sources:
            name, url = src
            source = [s for s in project.pipfile_sources if s.get('name') == name]
            assert source
            source = source[0]
            assert source['name'] == name
            assert source['url'] == url
            assert sorted(source.items()) == sorted(project.get_source(name=name).items())
            assert sorted(source.items()) == sorted(project.get_source(url=url).items())
            assert sorted(source.items()) == sorted(project.find_source(name).items())
            assert sorted(source.items()) == sorted(project.find_source(url).items())
def test_local_extras_install(PipenvInstance, pypi, line, pipfile):
    """Ensure -e .[extras] installs.
    """
    with PipenvInstance(pypi=pypi, chdir=True) as p:
        project = Project()
        setup_py = os.path.join(p.path, "setup.py")
        with open(setup_py, "w") as fh:
            contents = """
from setuptools import setup, find_packages
setup(
name='testpipenv',
version='0.1',
description='Pipenv Test Package',
author='Pipenv Test',
author_email='*****@*****.**',
license='MIT',
packages=find_packages(),
install_requires=[],
extras_require={'dev': ['six']},
zip_safe=False
)
            """.strip()
            fh.write(contents)
        project.write_toml({"packages": pipfile, "dev-packages": {}})
        c = p.pipenv("install")
        assert c.return_code == 0
        assert "testpipenv" in p.lockfile["default"]
        assert p.lockfile["default"]["testpipenv"]["extras"] == ["dev"]
        assert "six" in p.lockfile["default"]
        c = p.pipenv("--rm")
        assert c.return_code == 0
        project.write_toml({"packages": {}, "dev-packages": {}})
        c = p.pipenv("install {0}".format(line))
        assert c.return_code == 0
        assert "testpipenv" in p.pipfile["packages"]
        assert p.pipfile["packages"]["testpipenv"]["path"] == "."
        assert p.pipfile["packages"]["testpipenv"]["extras"] == ["dev"]
        assert "six" in p.lockfile["default"]
def test_environment_variable_value_does_not_change_hash(PipenvInstance, pypi):
    with PipenvInstance(chdir=True, pypi=pypi) as p:
        with temp_environ():
            with open(p.pipfile_path, 'w') as f:
                f.write("""
[[source]]
url = 'https://${PYPI_USERNAME}:${PYPI_PASSWORD}@pypi.org/simple'
verify_ssl = true
name = 'pypi'
[requires]
python_version = '2.7'
[packages]
flask = "==0.12.2"
""")
            project = Project()

            os.environ['PYPI_USERNAME'] = '******'
            os.environ['PYPI_PASSWORD'] = '******'
            assert project.get_lockfile_hash() is None

            c = p.pipenv('install')
            lock_hash = project.get_lockfile_hash()
            assert lock_hash is not None
            assert lock_hash == project.calculate_pipfile_hash()

            # sanity check on pytest
            assert 'PYPI_USERNAME' not in str(pipfile.load(p.pipfile_path))
            assert c.return_code == 0
            assert project.get_lockfile_hash() == project.calculate_pipfile_hash()

            os.environ['PYPI_PASSWORD'] = '******'
            assert project.get_lockfile_hash() == project.calculate_pipfile_hash()

            with open(p.pipfile_path, 'a') as f:
                f.write('requests = "==2.14.0"\n')
            assert project.get_lockfile_hash() != project.calculate_pipfile_hash()
Example #5
0
    def test_activate_virtualenv_no_source(self):
        command = activate_virtualenv(source=False)
        venv = Project().virtualenv_location

        assert command == '{0}/bin/activate'.format(venv)
Example #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages
try:
    from pipenv.project import Project
    from pipenv.utils import convert_deps_to_pip

    pfile = Project().parsed_pipfile
    requirements = convert_deps_to_pip(pfile['packages'], r=False)
    test_requirements = convert_deps_to_pip(pfile['dev-packages'], r=False)
except ImportError:
    # get the requirements from the requirements.txt
    requirements = [line.strip()
                    for line in open('requirements.txt').readlines()
                    if line.strip() and not line.startswith('#')]
    # get the test requirements from the test_requirements.txt
    test_requirements = [line.strip()
                         for line in
                         open('dev-requirements.txt').readlines()
                         if line.strip() and not line.startswith('#')]

readme = open('README.rst').read()
history = open('HISTORY.rst').read().replace('.. :changelog:', '')
version = open('.VERSION').read()


setup(
    name='''locationsharinglib''',
    version=version,
    description='''A library to retrieve coordinates from an google account that has been shared locations of other accounts. ''',
Example #7
0
        if key in os.environ:
            print(f"  - `{key}`: `{os.environ[key]}`")
    print("")
    print("")
    print("---------------------------")
    print("")
    if project.pipfile_exists:
        print_utf(f"Contents of `Pipfile` ({project.pipfile_location!r}):")
        print("")
        print("```toml")
        with open(project.pipfile_location) as f:
            print(f.read())
        print("```")
        print("")
    if project.lockfile_exists:
        print("")
        print_utf(
            f"Contents of `Pipfile.lock` ({project.lockfile_location!r}):")
        print("")
        print("```json")
        with open(project.lockfile_location) as f:
            print(f.read())
        print("```")
    print("</details>")


if __name__ == "__main__":
    from pipenv.project import Project

    get_pipenv_diagnostics(Project())
def test_environment_variable_value_does_not_change_hash(PipenvInstance, pypi):
    with PipenvInstance(chdir=True, pypi=pypi) as p:
        with temp_environ():
            with open(p.pipfile_path, 'w') as f:
                f.write("""
[[source]]
url = 'https://${PYPI_USERNAME}:${PYPI_PASSWORD}@pypi.org/simple'
verify_ssl = true
name = 'pypi'

[packages]
six = "*"
""")
            project = Project()

            os.environ['PYPI_USERNAME'] = '******'
            os.environ['PYPI_PASSWORD'] = '******'
            assert project.get_lockfile_hash() is None

            c = p.pipenv('install')
            assert c.return_code == 0
            lock_hash = project.get_lockfile_hash()
            assert lock_hash is not None
            assert lock_hash == project.calculate_pipfile_hash()

            # sanity check on pytest
            assert 'PYPI_USERNAME' not in str(pipfile.load(p.pipfile_path))
            assert c.return_code == 0
            assert project.get_lockfile_hash(
            ) == project.calculate_pipfile_hash()

            os.environ['PYPI_PASSWORD'] = '******'
            assert project.get_lockfile_hash(
            ) == project.calculate_pipfile_hash()

            with open(p.pipfile_path, 'a') as f:
                f.write('requests = "==2.14.0"\n')
            assert project.get_lockfile_hash(
            ) != project.calculate_pipfile_hash()
from setuptools import setup, find_packages
from pipenv.project import Project
from pipenv.utils import convert_deps_to_pip

pfile = Project(chdir=False).parsed_pipfile
requirements = convert_deps_to_pip(pfile['packages'], r=False)
test_requirements = convert_deps_to_pip(pfile['dev-packages'], r=False)

print(requirements)

setup(
    name="{{cookiecutter.package_name}}",
    version="{{cookiecutter.package_version}}",
    packages=find_packages(exclude=['tests']),
    install_requires=requirements,
    tests_require=test_requirements
)
Example #10
0
def requirements():
    pipfile = Project(chdir=False).parsed_pipfile
    return convert_deps_to_pip(pipfile['packages'], r=False)
def get_top_level_dependencies(package_type):
    validate_package_type(package_type)
    _type = 'packages' if package_type == 'default' else 'dev-packages'
    return Project().parsed_pipfile.get(_type, {}).keys()
Example #12
0
from setuptools import find_packages, setup
from pipenv.project import Project
from pipenv.utils import convert_deps_to_pip

import hutils

with open("README.md", "r", encoding="utf-8") as f:
    description = f.read()

setup(
    name="hutils",
    version=hutils.__version__,
    description="a charming python web util-library",
    long_description=description,
    long_description_content_type="text/markdown",
    author="ZaiHui Dev",
    author_email="*****@*****.**",
    url="https://github.com/zaihui/hutils/",
    license="MIT License",
    install_requires=convert_deps_to_pip(Project(chdir=False).parsed_pipfile["packages"], r=False),
    packages=find_packages(exclude=["tests"]),
    classifiers=[
        "License :: OSI Approved :: MIT License",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.5",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
    ],
)
Example #13
0
def test_proper_names_unamanged_virtualenv(PipenvInstance, pypi):
    with PipenvInstance(chdir=True, pypi=pypi) as p:
        c = delegator.run('python -m virtualenv .venv')
        assert c.return_code == 0
        project = Project()
        assert project.proper_names == []