Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
后端镜像
Pdm
提交
4227f801
P
Pdm
项目概览
后端镜像
/
Pdm
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Pdm
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
4227f801
编写于
4月 02, 2021
作者:
F
Frost Ming
提交者:
GitHub
4月 02, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #371 from pdm-project/bugfix/no-overwrite-import
Don't overwrite existing dependencies
上级
a10f9fe5
9f4d3daf
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
52 addition
and
10 deletion
+52
-10
news/370.bugfix.md
news/370.bugfix.md
+1
-0
pdm/cli/actions.py
pdm/cli/actions.py
+3
-2
pdm/cli/options.py
pdm/cli/options.py
+1
-1
pdm/cli/utils.py
pdm/cli/utils.py
+13
-0
pdm/formats/requirements.py
pdm/formats/requirements.py
+3
-6
tests/cli/test_cli.py
tests/cli/test_cli.py
+11
-0
tests/test_formats.py
tests/test_formats.py
+1
-1
tests/test_utils.py
tests/test_utils.py
+19
-0
未找到文件。
news/370.bugfix.md
0 → 100644
浏览文件 @
4227f801
Don't overwrite existing dependencies when importing from requirements.txt.
pdm/cli/actions.py
浏览文件 @
4227f801
...
...
@@ -17,6 +17,7 @@ from pdm.cli.utils import (
find_importable_files
,
format_lockfile
,
format_resolution_impossible
,
merge_dictionary
,
save_version_specifiers
,
set_env_in_reg
,
translate_sections
,
...
...
@@ -537,8 +538,8 @@ def do_import(
tomlkit
.
comment
(
"See https://www.python.org/dev/peps/pep-0621/"
)
)
pyproject
[
"project"
].
update
(
project_data
)
pyproject
[
"tool"
][
"pdm"
].
update
(
settings
)
merge_dictionary
(
pyproject
[
"project"
],
project_data
)
merge_dictionary
(
pyproject
[
"tool"
][
"pdm"
],
settings
)
pyproject
[
"build-system"
]
=
{
"requires"
:
[
"pdm-pep517"
],
"build-backend"
:
"pdm.pep517.api"
,
...
...
pdm/cli/options.py
浏览文件 @
4227f801
...
...
@@ -102,7 +102,7 @@ sections_group.add_argument(
dest
=
"default"
,
action
=
"store_false"
,
default
=
True
,
help
=
"Don't include dependencies from default sec
it
on"
,
help
=
"Don't include dependencies from default sec
ti
on"
,
)
...
...
pdm/cli/utils.py
浏览文件 @
4227f801
...
...
@@ -462,3 +462,16 @@ def translate_sections(
if
default
:
sections
.
add
(
"default"
)
return
sections
def
merge_dictionary
(
target
:
dict
,
input
:
dict
)
->
None
:
"""Merge the input dict with the target while preserving the existing values
properly. This will update the target dictionary in place.
"""
for
key
,
value
in
input
.
items
():
if
key
not
in
target
:
target
[
key
]
=
value
elif
isinstance
(
value
,
dict
):
target
[
key
].
update
(
value
)
elif
isinstance
(
value
,
list
):
target
[
key
].
extend
(
value
)
pdm/formats/requirements.py
浏览文件 @
4227f801
...
...
@@ -7,7 +7,6 @@ from typing import Any, Dict, List, Optional, Tuple, Union
from
distlib.wheel
import
Wheel
from
pip._vendor.packaging.requirements
import
Requirement
as
PRequirement
from
pdm.exceptions
import
PdmUsageError
from
pdm.formats.base
import
make_array
from
pdm.models.candidates
import
Candidate
from
pdm.models.environment
import
Environment
...
...
@@ -109,12 +108,10 @@ def convert(
reqs
=
[
ireq_as_line
(
ireq
,
project
.
environment
)
for
ireq
in
ireqs
]
deps
=
make_array
(
reqs
,
True
)
data
=
{
"dependencies"
:
[]
}
data
=
{}
settings
=
{}
if
options
.
dev
and
options
.
section
:
raise
PdmUsageError
(
"Can't specify --dev and --section at the same time"
)
elif
options
.
dev
:
settings
[
"dev-dependencies"
]
=
{
"dev"
:
deps
}
if
options
.
dev
:
settings
[
"dev-dependencies"
]
=
{
options
.
section
or
"dev"
:
deps
}
elif
options
.
section
:
data
[
"optional-dependencies"
]
=
{
options
.
section
:
deps
}
else
:
...
...
tests/cli/test_cli.py
浏览文件 @
4227f801
...
...
@@ -291,6 +291,17 @@ def test_import_other_format_file(project, invoke, filename):
assert
result
.
exit_code
==
0
def
test_import_requirement_no_overwrite
(
project
,
invoke
,
tmp_path
):
project
.
add_dependencies
({
"requests"
:
parse_requirement
(
"requests"
)})
tmp_path
.
joinpath
(
"reqs.txt"
).
write_text
(
"flask
\n
flask-login
\n
"
)
result
=
invoke
(
[
"import"
,
"-dsweb"
,
str
(
tmp_path
.
joinpath
(
"reqs.txt"
))],
obj
=
project
)
assert
result
.
exit_code
==
0
,
result
.
stderr
assert
list
(
project
.
get_dependencies
())
==
[
"requests"
]
assert
list
(
project
.
get_dependencies
(
"web"
))
==
[
"flask"
,
"flask-login"
]
@
pytest
.
mark
.
pypi
def
test_search_package
(
project
,
invoke
):
result
=
invoke
([
"search"
,
"requests"
],
obj
=
project
)
...
...
tests/test_formats.py
浏览文件 @
4227f801
...
...
@@ -151,5 +151,5 @@ def test_import_requirements_with_section(project):
assert
"webassets==2.0"
in
section
assert
'whoosh==2.7.4; sys_platform == "win32"'
in
section
assert
"-e git+https://github.com/pypa/pip.git@master#egg=pip"
in
section
assert
not
result
[
"dependencies"
]
assert
not
result
.
get
(
"dependencies"
)
assert
not
result
.
get
(
"dev-dependencies"
,
{}).
get
(
"dev"
)
tests/test_utils.py
浏览文件 @
4227f801
...
...
@@ -5,6 +5,7 @@ import sys
import
pytest
from
pdm
import
utils
from
pdm.cli
import
utils
as
cli_utils
@
pytest
.
mark
.
parametrize
(
...
...
@@ -66,3 +67,21 @@ def test_find_python_in_path(tmp_path):
)
assert
not
utils
.
find_python_in_path
(
tmp_path
)
def
test_merge_dictionary
():
target
=
{
"existing_dict"
:
{
"foo"
:
"bar"
,
"hello"
:
"world"
},
"existing_list"
:
[
"hello"
],
}
input_dict
=
{
"existing_dict"
:
{
"foo"
:
"baz"
},
"existing_list"
:
[
"world"
],
"new_dict"
:
{
"name"
:
"Sam"
},
}
cli_utils
.
merge_dictionary
(
target
,
input_dict
)
assert
target
==
{
"existing_dict"
:
{
"foo"
:
"baz"
,
"hello"
:
"world"
},
"existing_list"
:
[
"hello"
,
"world"
],
"new_dict"
:
{
"name"
:
"Sam"
},
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录