Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
后端镜像
Pdm
提交
d2cc5343
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,发现更多精彩内容 >>
未验证
提交
d2cc5343
编写于
11月 24, 2020
作者:
F
Frost Ming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Supporting running scripts directly
上级
f73c6432
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
58 addition
and
25 deletion
+58
-25
news/176.feature
news/176.feature
+1
-0
pdm/cli/commands/run.py
pdm/cli/commands/run.py
+34
-24
pyproject.toml
pyproject.toml
+1
-0
tests/cli/test_cli.py
tests/cli/test_cli.py
+2
-0
tests/cli/test_run.py
tests/cli/test_run.py
+20
-1
未找到文件。
news/176.feature
0 → 100644
浏览文件 @
d2cc5343
Supporting
running
scripts
with
the
nearest
`__pypackages__`
loaded.
pdm/cli/commands/run.py
浏览文件 @
d2cc5343
...
...
@@ -11,6 +11,7 @@ from pdm.cli.commands.base import BaseCommand
from
pdm.exceptions
import
PdmUsageError
from
pdm.iostream
import
stream
from
pdm.project
import
Project
from
pdm.utils
import
find_project_root
class
Command
(
BaseCommand
):
...
...
@@ -40,27 +41,30 @@ class Command(BaseCommand):
shell
=
False
,
env
=
None
,
)
->
None
:
if
env
:
os
.
environ
.
update
(
env
)
if
shell
:
sys
.
exit
(
subprocess
.
call
(
os
.
path
.
expandvars
(
args
),
shell
=
True
))
with
project
.
environment
.
activate
():
if
env
:
os
.
environ
.
update
(
env
)
if
shell
:
sys
.
exit
(
subprocess
.
call
(
os
.
path
.
expandvars
(
args
),
shell
=
True
))
command
,
*
args
=
args
expanded_command
=
project
.
environment
.
which
(
command
)
if
not
expanded_command
:
raise
PdmUsageError
(
"Command {} is not found on your PATH."
.
format
(
stream
.
green
(
f
"'
{
command
}
'"
)
command
,
*
args
=
args
expanded_command
=
project
.
environment
.
which
(
command
)
if
not
expanded_command
:
raise
PdmUsageError
(
"Command {} is not found on your PATH."
.
format
(
stream
.
green
(
f
"'
{
command
}
'"
)
)
)
)
expanded_command
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
expanded_command
))
expanded_args
=
[
os
.
path
.
expandvars
(
arg
)
for
arg
in
[
expanded_command
]
+
args
]
if
os
.
name
==
"nt"
or
"CI"
in
os
.
environ
:
# In order to make sure pytest is playing well,
# don't hand over the process under a testing environment.
sys
.
exit
(
subprocess
.
call
(
expanded_args
))
else
:
os
.
execv
(
expanded_command
,
expanded_args
)
expanded_command
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
expanded_command
))
expanded_args
=
[
os
.
path
.
expandvars
(
arg
)
for
arg
in
[
expanded_command
]
+
args
]
if
os
.
name
==
"nt"
or
"CI"
in
os
.
environ
:
# In order to make sure pytest is playing well,
# don't hand over the process under a testing environment.
sys
.
exit
(
subprocess
.
call
(
expanded_args
))
else
:
os
.
execv
(
expanded_command
,
expanded_args
)
def
_normalize_script
(
self
,
script
):
if
not
getattr
(
script
,
"items"
,
None
):
...
...
@@ -125,8 +129,14 @@ class Command(BaseCommand):
def
handle
(
self
,
project
:
Project
,
options
:
argparse
.
Namespace
)
->
None
:
if
options
.
list
:
return
self
.
_show_list
(
project
)
with
project
.
environment
.
activate
():
if
project
.
scripts
and
options
.
command
in
project
.
scripts
:
self
.
_run_script
(
project
,
options
.
command
,
options
.
args
)
else
:
self
.
_run_command
(
project
,
[
options
.
command
]
+
options
.
args
)
if
project
.
scripts
and
options
.
command
in
project
.
scripts
:
self
.
_run_script
(
project
,
options
.
command
,
options
.
args
)
elif
os
.
path
.
isfile
(
options
.
command
)
and
options
.
command
.
endswith
(
".py"
):
# Allow executing py scripts like `pdm run my_script.py`.
# In this case, the nearest `__pypackages__` will be loaded as
# the library source.
new_root
=
find_project_root
(
os
.
path
.
abspath
(
options
.
command
))
project
=
Project
(
new_root
)
if
new_root
else
project
self
.
_run_command
(
project
,
[
"python"
,
options
.
command
]
+
options
.
args
)
else
:
self
.
_run_command
(
project
,
[
options
.
command
]
+
options
.
args
)
pyproject.toml
浏览文件 @
d2cc5343
...
...
@@ -169,3 +169,4 @@ colorama = []
filterwarnings
=
[
"ignore::DeprecationWarning"
]
markers
=
[
"pypi: Tests that connect to the real PyPI"
]
tests/cli/test_cli.py
浏览文件 @
d2cc5343
...
...
@@ -239,12 +239,14 @@ def test_import_other_format_file(project, invoke, filename):
assert
result
.
exit_code
==
0
@
pytest
.
mark
.
pypi
def
test_search_package
(
project
,
invoke
):
result
=
invoke
([
"search"
,
"requests"
],
obj
=
project
)
assert
result
.
exit_code
==
0
assert
len
(
result
.
output
.
splitlines
())
>
0
@
pytest
.
mark
.
pypi
def
test_show_package_on_pypi
(
invoke
):
result
=
invoke
([
"show"
,
"ipython"
])
assert
result
.
exit_code
==
0
...
...
tests/cli/test_run.py
浏览文件 @
d2cc5343
...
...
@@ -2,6 +2,8 @@ import json
import
os
import
textwrap
import
pytest
from
pdm.utils
import
cd
,
temp_environ
...
...
@@ -134,7 +136,6 @@ def test_run_show_list_of_scripts(project, invoke):
}
project
.
write_pyproject
()
result
=
invoke
([
"run"
,
"--list"
],
obj
=
project
)
print
(
result
.
output
,
result
.
stderr
)
result_lines
=
result
.
output
.
splitlines
()[
2
:]
assert
result_lines
[
0
].
strip
()
==
"test_cmd cmd flask db upgrade"
assert
(
...
...
@@ -142,3 +143,21 @@ def test_run_show_list_of_scripts(project, invoke):
==
"test_script call test_script:main call a python function"
)
assert
result_lines
[
2
].
strip
()
==
"test_shell shell echo $FOO shell command"
@
pytest
.
mark
.
pypi
def
test_run_script_with_pep582
(
project
,
invoke
,
capfd
):
project
.
tool_settings
[
"python_requires"
]
=
">=3.7"
project
.
write_pyproject
()
(
project
.
root
/
"test_script.py"
).
write_text
(
"import requests
\n
print(requests.__version__)
\n
"
)
result
=
invoke
([
"add"
,
"requests==2.24.0"
],
obj
=
project
)
assert
result
.
exit_code
==
0
capfd
.
readouterr
()
with
cd
(
os
.
path
.
expanduser
(
"~"
)):
result
=
invoke
([
"run"
,
str
(
project
.
root
/
"test_script.py"
)],
obj
=
project
)
assert
result
.
exit_code
==
0
out
,
_
=
capfd
.
readouterr
()
assert
out
.
strip
()
==
"2.24.0"
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录