本文整理汇总了Python中pipenv.project.Project方法的典型用法代码示例。如果您正苦于以下问题:Python project.Project方法的具体用法?Python project.Project怎么用?Python project.Project使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pipenv.project
的用法示例。
在下文中一共展示了project.Project方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pipfile_envvar_expansion
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def test_pipfile_envvar_expansion(PipenvInstance):
with PipenvInstance(chdir=True) as p:
with temp_environ():
with open(p.pipfile_path, 'w') as f:
f.write("""
[[source]]
url = 'https://${TEST_HOST}/simple'
verify_ssl = false
name = "pypi"
[packages]
pytz = "*"
""".strip())
os.environ['TEST_HOST'] = 'localhost:5000'
project = Project()
assert project.sources[0]['url'] == 'https://localhost:5000/simple'
assert 'localhost:5000' not in str(pipfile.load(p.pipfile_path))
示例2: test_run_in_virtualenv
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def test_run_in_virtualenv(PipenvInstance):
with PipenvInstance(chdir=True) as p:
c = p.pipenv('run pip freeze')
assert c.return_code == 0
assert 'Creating a virtualenv' in c.err
project = Project()
c = p.pipenv("run pip install click")
assert c.return_code == 0
c = p.pipenv("install six")
assert c.return_code == 0
c = p.pipenv('run python -c "import click;print(click.__file__)"')
assert c.return_code == 0
assert normalize_path(c.out.strip()).startswith(
normalize_path(str(project.virtualenv_location))
)
c = p.pipenv("clean --dry-run")
assert c.return_code == 0
assert "click" in c.out
示例3: update
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def update(cls, content, dependency, version, spec="==", hashes=()):
data = toml.loads(content)
if data:
for package_type in ['packages', 'dev-packages']:
if package_type in data:
if dependency.full_name in data[package_type]:
data[package_type][dependency.full_name] = "{spec}{version}".format(
spec=spec, version=version
)
try:
from pipenv.project import Project
except ImportError:
raise ImportError("Updating a Pipfile requires the pipenv extra to be installed. Install it with "
"pip install dparse[pipenv]")
pipfile = tempfile.NamedTemporaryFile(delete=False)
p = Project(chdir=False)
p.write_toml(data=data, path=pipfile.name)
data = open(pipfile.name).read()
os.remove(pipfile.name)
return data
示例4: get_top_level_dependencies
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def get_top_level_dependencies():
pip_packages = Project().parsed_pipfile.get('packages', {}).items()
packages = [Package(name_, version_) for name_, version_ in pip_packages]
pip_dev_packages = Project().parsed_pipfile.get('dev-packages', {}).items()
dev_packages = [Package(name_, version_) for name_, version_ in pip_dev_packages]
LOGGER.debug(f"Packages in Pipfile: {packages}")
LOGGER.debug(f"Development packages in Pipfile: {dev_packages}")
return packages, dev_packages
示例5: update_pipfile
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def update_pipfile(stdout: bool):
import toml
project = Project()
LOGGER.debug(f"Processing {project.pipfile_location}")
top_level_packages, top_level_dev_packages = get_top_level_dependencies()
all_packages, all_dev_packages = get_all_packages()
pipfile = toml.load(project.pipfile_location)
configuration = [{'section': 'packages',
'top_level': top_level_packages,
'all_packages': all_packages},
{'section': 'dev-packages',
'top_level': top_level_dev_packages,
'all_packages': all_dev_packages}]
for config in configuration:
pipfile[config.get('section')] = {package.name: package.full_version
for package in _get_packages(config.get('top_level'),
config.get('all_packages'))}
if stdout:
LOGGER.debug(f"Outputting Pipfile on stdout")
print(toml.dumps(pipfile))
else:
LOGGER.debug(f"Outputting Pipfile top {project.pipfile_location}")
with open(project.pipfile_location, 'w') as writer:
writer.write(toml.dumps(pipfile))
return True
示例6: test_include_editable_packages
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def test_include_editable_packages(PipenvInstance, testsroot, pathlib_tmpdir):
file_name = "tablib-0.12.1.tar.gz"
package = pathlib_tmpdir.joinpath("tablib-0.12.1")
source_path = os.path.abspath(os.path.join(testsroot, "pypi", "tablib", file_name))
with PipenvInstance(chdir=True) as p:
with tarfile.open(source_path, "r:gz") as tarinfo:
tarinfo.extractall(path=str(pathlib_tmpdir))
c = p.pipenv('install -e {0}'.format(package.as_posix()))
assert c.return_code == 0
project = Project()
assert "tablib" in [
package.project_name
for package in project.environment.get_installed_packages()
]
示例7: test_run_in_virtualenv_with_global_context
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def test_run_in_virtualenv_with_global_context(PipenvInstance, virtualenv):
with PipenvInstance(chdir=True, venv_root=virtualenv.as_posix(), ignore_virtualenvs=False, venv_in_project=False) as p:
c = delegator_run(
"pipenv run pip freeze", cwd=os.path.abspath(p.path),
env=os.environ.copy()
)
assert c.return_code == 0, (c.out, c.err)
assert 'Creating a virtualenv' not in c.err, c.err
project = Project()
assert project.virtualenv_location == virtualenv.as_posix(), (
project.virtualenv_location, virtualenv.as_posix()
)
c = delegator_run(
"pipenv run pip install click", cwd=os.path.abspath(p.path),
env=os.environ.copy()
)
assert c.return_code == 0, (c.out, c.err)
assert "Courtesy Notice" in c.err, (c.out, c.err)
c = delegator_run(
"pipenv install six", cwd=os.path.abspath(p.path), env=os.environ.copy()
)
assert c.return_code == 0, (c.out, c.err)
c = delegator_run(
'pipenv run python -c "import click;print(click.__file__)"',
cwd=os.path.abspath(p.path), env=os.environ.copy()
)
assert c.return_code == 0, (c.out, c.err)
assert is_in_path(c.out.strip(), str(virtualenv)), (c.out.strip(), str(virtualenv))
c = delegator_run(
"pipenv clean --dry-run", cwd=os.path.abspath(p.path),
env=os.environ.copy()
)
assert c.return_code == 0, (c.out, c.err)
assert "click" in c.out, c.out
示例8: test_environment_variable_value_does_not_change_hash
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def test_environment_variable_value_does_not_change_hash(PipenvInstance):
with PipenvInstance(chdir=True) 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'] = 'whatever'
os.environ['PYPI_PASSWORD'] = 'pass'
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'] = 'pass2'
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()
示例9: get_top_level_dependencies
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def get_top_level_dependencies():
pip_packages = Project().parsed_pipfile.get('packages', {}).items()
packages = [Package(name_, version_) if isinstance(version_, str) else Package(name_, **version_)
for name_, version_ in pip_packages]
pip_dev_packages = Project().parsed_pipfile.get('dev-packages', {}).items()
dev_packages =[Package(name_, version_) if isinstance(version_, str) else Package(name_, **version_)
for name_, version_ in pip_dev_packages]
LOGGER.debug(f'Packages in Pipfile: {packages}')
LOGGER.debug(f'Development packages in Pipfile: {dev_packages}')
return packages, dev_packages
示例10: update_pipfile
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def update_pipfile(stdout: bool):
import toml
project = Project()
LOGGER.debug(f"Processing {project.pipfile_location}")
top_level_packages, top_level_dev_packages = get_top_level_dependencies()
all_packages, all_dev_packages = get_all_packages()
pipfile = toml.load(project.pipfile_location)
configuration = [{'section': 'packages',
'top_level': top_level_packages,
'all_packages': all_packages},
{'section': 'dev-packages',
'top_level': top_level_dev_packages,
'all_packages': all_dev_packages}]
for config in configuration:
pipfile[config.get('section')] = {package.name: package.full_version
for package in _get_packages(config.get('top_level'),
config.get('all_packages'))}
if stdout:
LOGGER.debug(f'Outputting Pipfile on stdout')
print(toml.dumps(pipfile))
else:
LOGGER.debug(f'Outputting Pipfile top {project.pipfile_location}')
with open(project.pipfile_location, 'w') as writer:
writer.write(toml.dumps(pipfile))
return True
示例11: get_packages_from_Pipfile
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def get_packages_from_Pipfile():
pipfile = Project(chdir=False).parsed_pipfile
return convert_deps_to_pip(pipfile['packages'], r=False)
示例12: mock_env_home
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def mock_env_home(TempEnviron, mock_projects_dir, venv_fresh):
__cwd = os.getcwd()
with TemporaryDirectory(prefix='pipenv_home_real') as pipenv_home:
project_names = os.listdir(mock_projects_dir)
for project_name in project_names:
project_dir = os.path.join(mock_projects_dir, project_name)
pipfile = os.path.join(project_dir, 'Pipfile')
touch(pipfile)
os.chdir(project_dir)
with TempEnviron(WORKON_HOME=pipenv_home):
project = Project()
envname = project.virtualenv_name
os.chdir(__cwd)
envpath = os.path.join(pipenv_home, envname)
shutil.copytree(venv_fresh, envpath)
# Make Project Links
envs = find_environments(pipenv_home)
for e in envs:
project_dir = os.path.join(mock_projects_dir, e.project_name)
write_project_dir_project_file(
envpath=e.envpath,
project_dir=project_dir
)
with TempEnviron(WORKON_HOME=pipenv_home):
yield pipenv_home, mock_projects_dir
os.chdir(__cwd)
示例13: main
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def main():
args = parse_args()
logger = get_logger(args.quiet)
if args.freeze:
pipfile = Project().lockfile_content
else:
# pylint: disable=protected-access
pipfile = Project()._lockfile
# pylint: enable=protected-access
def_req = parse_pip_file(pipfile, 'default')
dev_req = parse_pip_file(pipfile, "develop")
intro = [
"################################################################################",
"# This requirements file has been automatically generated from `Pipfile` with",
'# `pipenv-to-requirements`', '#', '#',
'# This has been done to maintain backward compatibility with tools and services',
'# that do not support `Pipfile` yet.', '#',
"# Do NOT edit it directly, use `pipenv install [-d]` to modify `Pipfile` and",
"# `Pipfile.lock` and then regenerate `requirements*.txt`.",
"################################################################################", ""
]
if def_req:
if args.output:
requirement_txt = args.output
elif args.dev_output:
# if -d without -o, do not generate packages, for compatibility sake
requirement_txt = None
else:
requirement_txt = "requirements.txt"
if requirement_txt:
with open(requirement_txt, "w") as f:
f.write("\n".join(intro + sorted(def_req)) + "\n")
logger.info("generated: %s", requirement_txt)
if dev_req:
if args.dev_output:
requirement_txt = args.dev_output
elif args.output:
# if -o without -d, do not generate dev packages, for compatibility sake
requirement_txt = None
else:
requirement_txt = "requirements-dev.txt"
if requirement_txt:
with open(requirement_txt, "w") as f:
f.write("\n".join(intro + sorted(dev_req)) + "\n")
logger.info("generated: %s", requirement_txt)
示例14: test_get_source
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
def test_get_source(PipenvInstance, lock_first):
with PipenvInstance(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())
示例15: test_scripts
# 需要导入模块: from pipenv import project [as 别名]
# 或者: from pipenv.project import Project [as 别名]
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\""
""")
if os.name == "nt":
f.write('scriptwithenv = "echo %HELLO%"\n')
else:
f.write('scriptwithenv = "echo $HELLO"\n')
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']
with temp_environ():
os.environ['HELLO'] = 'WORLD'
c = p.pipenv("run scriptwithenv")
assert c.ok
if os.name != "nt": # This doesn't work on CI windows.
assert c.out.strip() == "WORLD"