Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
后端镜像
Pdm
提交
ea55cddf
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
ea55cddf
编写于
12月 21, 2020
作者:
F
Frost Ming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix regression tests
上级
df44ce87
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
57 addition
and
23 deletion
+57
-23
pdm/cli/actions.py
pdm/cli/actions.py
+5
-7
pdm/formats/flit.py
pdm/formats/flit.py
+8
-2
pdm/formats/legacy.py
pdm/formats/legacy.py
+5
-1
pdm/formats/poetry.py
pdm/formats/poetry.py
+3
-1
pdm/pep582/sitecustomize.py
pdm/pep582/sitecustomize.py
+2
-1
pdm/project/config.py
pdm/project/config.py
+3
-1
pdm/project/core.py
pdm/project/core.py
+18
-6
pdm/utils.py
pdm/utils.py
+8
-1
tests/cli/test_build.py
tests/cli/test_build.py
+3
-3
tests/cli/test_cli.py
tests/cli/test_cli.py
+1
-0
tests/conftest.py
tests/conftest.py
+1
-0
未找到文件。
pdm/cli/actions.py
浏览文件 @
ea55cddf
...
...
@@ -27,7 +27,7 @@ from pdm.models.requirements import Requirement, parse_requirement, strip_extras
from
pdm.models.specifiers
import
get_specifier
from
pdm.project
import
Project
from
pdm.resolver
import
resolve
from
pdm.utils
import
get_python_version
from
pdm.utils
import
get_python_version
,
setdefault
PEP582_PATH
=
os
.
path
.
join
(
os
.
path
.
dirname
(
sys
.
modules
[
__name__
.
split
(
"."
)[
0
]].
__file__
),
"pep582"
...
...
@@ -274,7 +274,7 @@ def do_remove(
(
i
for
i
,
r
in
enumerate
(
deps
)
if
req
.
matches
(
r
)),
None
,
)
if
not
matched_index
:
if
matched_index
is
None
:
raise
ProjectError
(
"{} does not exist in {} dependencies."
.
format
(
stream
.
green
(
name
,
bold
=
True
),
section
...
...
@@ -498,14 +498,12 @@ def do_import(project: Project, filename: str, format: Optional[str] = None) ->
tomlkit
.
comment
(
"See https://www.python.org/dev/peps/pep-0621/"
)
)
for
key
,
value
in
project_data
.
items
():
pyproject
[
"project"
].
add
(
key
,
value
)
pyproject
[
"project"
].
update
(
project_data
)
if
"tool"
not
in
pyproject
or
"pdm"
not
in
pyproject
[
"tool"
]:
pyproject
.
setdefault
(
"tool"
,
{})[
"pdm"
]
=
tomlkit
.
table
()
setdefault
(
pyproject
,
"tool"
,
{})[
"pdm"
]
=
tomlkit
.
table
()
for
key
,
value
in
settings
.
items
():
pyproject
[
"tool"
][
"pdm"
][
key
]
=
value
pyproject
[
"tool"
][
"pdm"
].
update
(
settings
)
pyproject
[
"build-system"
]
=
{
"requires"
:
[
"pdm-pep517"
],
...
...
pdm/formats/flit.py
浏览文件 @
ea55cddf
...
...
@@ -4,7 +4,13 @@ from pathlib import Path
import
tomlkit
import
tomlkit.exceptions
from
pdm.formats.base
import
MetaConverter
,
convert_from
,
make_array
,
make_inline_table
from
pdm.formats.base
import
(
MetaConverter
,
array_of_inline_tables
,
convert_from
,
make_array
,
make_inline_table
,
)
def
check_fingerprint
(
project
,
filename
):
...
...
@@ -20,7 +26,7 @@ def check_fingerprint(project, filename):
def
_get_author
(
metadata
,
type_
=
"author"
):
name
=
metadata
.
pop
(
type_
)
email
=
metadata
.
pop
(
f
"
{
type_
}
-email"
,
None
)
return
[{
"name"
:
name
,
"email"
:
email
}]
return
array_of_inline_tables
([{
"name"
:
name
,
"email"
:
email
}])
class
FlitMetaConverter
(
MetaConverter
):
...
...
pdm/formats/legacy.py
浏览文件 @
ea55cddf
...
...
@@ -21,7 +21,11 @@ def check_fingerprint(project, filename):
except
tomlkit
.
exceptions
.
TOMLKitError
:
return
False
return
"tool"
in
data
and
"pdm"
in
data
[
"tool"
]
and
"name"
in
data
[
"tool"
][
"pdm"
]
return
(
"tool"
in
data
and
"pdm"
in
data
[
"tool"
]
and
"dependencies"
in
data
[
"tool"
][
"pdm"
]
)
class
LegacyMetaConverter
(
MetaConverter
):
...
...
pdm/formats/poetry.py
浏览文件 @
ea55cddf
import
functools
import
operator
import
os
import
re
import
tomlkit
...
...
@@ -16,6 +17,7 @@ from pdm.formats.base import (
from
pdm.models.markers
import
Marker
from
pdm.models.requirements
import
Requirement
from
pdm.models.specifiers
import
PySpecSet
from
pdm.utils
import
cd
def
check_fingerprint
(
project
,
filename
):
...
...
@@ -164,7 +166,7 @@ class PoetryMetaConverter(MetaConverter):
def
convert
(
project
,
filename
):
with
open
(
filename
,
encoding
=
"utf-8"
)
as
fp
:
with
open
(
filename
,
encoding
=
"utf-8"
)
as
fp
,
cd
(
os
.
path
.
dirname
(
filename
))
:
converter
=
PoetryMetaConverter
(
tomlkit
.
parse
(
fp
.
read
())[
"tool"
][
"poetry"
])
return
dict
(
converter
),
converter
.
settings
...
...
pdm/pep582/sitecustomize.py
浏览文件 @
ea55cddf
...
...
@@ -57,6 +57,7 @@ def main():
libpath
=
get_pypackages_path
()
if
not
libpath
:
return
pypackages
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
libpath
))
# First, drop site related paths.
original_sys_path
=
sys
.
path
[:]
paths_to_remove
=
set
()
...
...
@@ -66,7 +67,7 @@ def main():
with_site_packages
or
needs_site_packages
or
script_path
and
not
script_path
.
startswith
(
os
.
path
.
normcase
(
os
.
path
.
dirname
(
libpath
)))
and
not
script_path
.
startswith
(
os
.
path
.
normcase
(
os
.
path
.
dirname
(
pypackages
)))
):
site
.
addsitepackages
(
paths_to_remove
)
paths_to_remove
=
set
(
os
.
path
.
normcase
(
path
)
for
path
in
paths_to_remove
)
...
...
pdm/project/config.py
浏览文件 @
ea55cddf
...
...
@@ -134,7 +134,9 @@ class Config(MutableMapping):
*
parts
,
last
=
key
.
split
(
"."
)
temp
=
toml_data
for
part
in
parts
:
temp
=
temp
.
setdefault
(
part
,
{})
if
part
not
in
temp
:
temp
[
part
]
=
{}
temp
=
temp
[
part
]
temp
[
last
]
=
value
with
self
.
_config_file
.
open
(
"w"
,
encoding
=
"utf-8"
)
as
fp
:
...
...
pdm/project/core.py
浏览文件 @
ea55cddf
...
...
@@ -7,6 +7,7 @@ from pathlib import Path
from
typing
import
TYPE_CHECKING
,
Any
,
Dict
,
Iterable
,
List
,
Optional
,
Type
,
Union
import
tomlkit
from
tomlkit.items
import
Comment
,
Whitespace
from
pdm._types
import
Source
from
pdm.exceptions
import
ProjectError
...
...
@@ -26,6 +27,7 @@ from pdm.utils import (
find_project_root
,
get_python_version
,
get_venv_python
,
setdefault
,
)
if
TYPE_CHECKING
:
...
...
@@ -97,7 +99,7 @@ class Project:
data
=
self
.
pyproject
if
not
data
:
return
{}
return
data
.
setdefault
(
"tool"
,
{}).
setdefault
(
"pdm"
,
{})
return
setdefault
(
setdefault
(
data
,
"tool"
,
{}),
"pdm"
,
{})
@
property
def
lockfile
(
self
):
...
...
@@ -347,12 +349,12 @@ class Project:
def
get_pyproject_dependencies
(
self
,
section
:
str
)
->
List
[
str
]:
"""Get the dependencies array in the pyproject.toml"""
if
section
==
"default"
:
return
se
lf
.
meta
.
setdefault
(
"dependencies"
,
[])
return
se
tdefault
(
self
.
meta
,
"dependencies"
,
[])
elif
section
==
"dev"
:
return
se
lf
.
meta
.
setdefault
(
"dev-dependencies"
,
[])
return
se
tdefault
(
self
.
meta
,
"dev-dependencies"
,
[])
else
:
return
se
lf
.
meta
.
setdefault
(
"optional-dependencies"
,
{}).
se
tdefault
(
section
,
[]
return
setdefault
(
se
tdefault
(
self
.
meta
,
"optional-dependencies"
,
{}),
se
ction
,
[]
)
def
add_dependencies
(
...
...
@@ -366,7 +368,17 @@ class Project:
if
matched_index
is
None
:
deps
.
append
(
dep
.
as_line
())
else
:
deps
[
matched_index
]
=
dep
.
as_line
()
req
=
dep
.
as_line
()
deps
[
matched_index
]
=
req
# XXX: This dirty part is for tomlkit.Array.__setitem__()
j
=
0
for
i
in
range
(
len
(
deps
.
_value
)):
if
isinstance
(
deps
.
_value
[
i
],
(
Comment
,
Whitespace
)):
continue
if
j
==
matched_index
:
deps
.
_value
[
i
]
=
tomlkit
.
item
(
req
)
break
j
+=
1
self
.
write_pyproject
(
show_message
)
def
write_pyproject
(
self
,
show_message
:
bool
=
True
)
->
None
:
...
...
pdm/utils.py
浏览文件 @
ea55cddf
...
...
@@ -243,7 +243,7 @@ def convert_hashes(hashes: Dict[str, str]) -> Dict[str, List[str]]:
name
,
hash_value
=
hash_value
.
split
(
":"
)
except
ValueError
:
name
=
"sha256"
result
.
setdefault
(
name
,
[]).
append
(
hash_value
)
setdefault
(
result
,
name
,
[]).
append
(
hash_value
)
return
result
...
...
@@ -384,3 +384,10 @@ def populate_link(
return
link
=
getattr
(
link
,
"link"
,
link
)
ireq
.
link
=
link
def
setdefault
(
document
,
key
,
value
):
"""A compatiable dict.setdefault() for tomlkit data structures."""
if
key
not
in
document
:
document
[
key
]
=
value
return
document
[
key
]
tests/cli/test_build.py
浏览文件 @
ea55cddf
...
...
@@ -47,7 +47,7 @@ def test_build_single_module(fixture_project):
def
test_build_single_module_with_readme
(
fixture_project
):
project
=
fixture_project
(
"demo-module"
)
project
.
tool_settings
[
"readme"
]
=
"README.md"
project
.
meta
[
"readme"
]
=
"README.md"
project
.
write_pyproject
()
actions
.
do_build
(
project
)
assert
"demo-module-0.1.0/README.md"
in
get_tarball_names
(
...
...
@@ -91,12 +91,12 @@ def test_build_src_package(fixture_project):
def
test_build_package_include
(
fixture_project
):
project
=
fixture_project
(
"demo-package"
)
project
.
tool_settings
[
"includes"
]
=
[
project
.
meta
[
"includes"
]
=
[
"my_package/"
,
"single_module.py"
,
"data_out.json"
,
]
project
.
tool_settings
[
"excludes"
]
=
[
"my_package/*.json"
]
project
.
meta
[
"excludes"
]
=
[
"my_package/*.json"
]
project
.
write_pyproject
()
actions
.
do_build
(
project
)
...
...
tests/cli/test_cli.py
浏览文件 @
ea55cddf
...
...
@@ -236,6 +236,7 @@ def test_cache_clear_command(project, invoke, mocker):
def
test_import_other_format_file
(
project
,
invoke
,
filename
):
requirements_file
=
FIXTURES
/
filename
result
=
invoke
([
"import"
,
str
(
requirements_file
)],
obj
=
project
)
print
(
result
.
stderr
)
assert
result
.
exit_code
==
0
...
...
tests/conftest.py
浏览文件 @
ea55cddf
...
...
@@ -253,6 +253,7 @@ def fixture_project(project_no_init):
def
func
(
project_name
):
source
=
FIXTURES
/
"projects"
/
project_name
copy_tree
(
source
.
as_posix
(),
project_no_init
.
root
.
as_posix
())
project_no_init
.
_pyproject
=
None
return
project_no_init
return
func
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录