Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
9a283965
Unverified
Commit
9a283965
authored
Apr 22, 2020
by
Oleg Höfling
Committed by
GitHub
Apr 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix regression in stub-only package (PEP-561) support
Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
parent
dbc1e1b9
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
148 additions
and
5 deletions
+148
-5
poetry/masonry/utils/package_include.py
+18
-5
tests/masonry/builders/fixtures/pep_561_stub_only/pkg-stubs/__init__.pyi
+0
-0
tests/masonry/builders/fixtures/pep_561_stub_only/pkg-stubs/module.pyi
+4
-0
tests/masonry/builders/fixtures/pep_561_stub_only/pkg-stubs/subpkg/__init__.pyi
+0
-0
tests/masonry/builders/fixtures/pep_561_stub_only/pyproject.toml
+14
-0
tests/masonry/builders/fixtures/pep_561_stub_only_partial/pkg-stubs/__init__.pyi
+0
-0
tests/masonry/builders/fixtures/pep_561_stub_only_partial/pkg-stubs/module.pyi
+4
-0
tests/masonry/builders/fixtures/pep_561_stub_only_partial/pkg-stubs/py.typed
+1
-0
tests/masonry/builders/fixtures/pep_561_stub_only_partial/pkg-stubs/subpkg/__init__.pyi
+0
-0
tests/masonry/builders/fixtures/pep_561_stub_only_partial/pyproject.toml
+14
-0
tests/masonry/builders/fixtures/pep_561_stub_only_src/pyproject.toml
+14
-0
tests/masonry/builders/fixtures/pep_561_stub_only_src/src/pkg-stubs/__init__.pyi
+0
-0
tests/masonry/builders/fixtures/pep_561_stub_only_src/src/pkg-stubs/module.pyi
+4
-0
tests/masonry/builders/fixtures/pep_561_stub_only_src/src/pkg-stubs/subpkg/__init__.pyi
+0
-0
tests/masonry/builders/test_sdist.py
+18
-0
tests/masonry/builders/test_wheel.py
+30
-0
tests/masonry/utils/fixtures/pep_561_stub_only/bad/__init__.pyi
+0
-0
tests/masonry/utils/fixtures/pep_561_stub_only/bad/module.pyi
+5
-0
tests/masonry/utils/fixtures/pep_561_stub_only/good-stubs/__init__.pyi
+0
-0
tests/masonry/utils/fixtures/pep_561_stub_only/good-stubs/module.pyi
+5
-0
tests/masonry/utils/test_package_include.py
+17
-0
No files found.
poetry/masonry/utils/package_include.py
View file @
9a283965
...
...
@@ -33,6 +33,21 @@ class PackageInclude(Include):
return
self
.
check_elements
()
def
is_stub_only
(
self
):
# type: () -> bool
# returns `True` if this a PEP 561 stub-only package,
# see [PEP 561](https://www.python.org/dev/peps/pep-0561/#stub-only-packages)
return
self
.
package
.
endswith
(
"-stubs"
)
and
all
(
el
.
suffix
==
".pyi"
or
(
el
.
parent
.
name
==
self
.
package
and
el
.
name
==
"py.typed"
)
for
el
in
self
.
elements
if
el
.
is_file
()
)
def
has_modules
(
self
):
# type: () -> bool
# Packages no longer need an __init__.py in python3, but there must
# at least be one .py file for it to be considered a package
return
any
(
element
.
suffix
==
".py"
for
element
in
self
.
elements
)
def
check_elements
(
self
):
# type: () -> PackageInclude
if
not
self
.
_elements
:
raise
ValueError
(
...
...
@@ -43,20 +58,18 @@ class PackageInclude(Include):
if
len
(
self
.
_elements
)
>
1
:
# Probably glob
self
.
_is_package
=
True
self
.
_package
=
root
.
parent
.
name
# Packages no longer need an __init__.py in python3, but there must
# at least be one .py file for it to be considered a package
if
not
any
([
element
.
suffix
==
".py"
for
element
in
self
.
_elements
]):
if
not
self
.
is_stub_only
()
and
not
self
.
has_modules
():
raise
ValueError
(
"{} is not a package."
.
format
(
root
.
name
))
self
.
_package
=
root
.
parent
.
name
else
:
if
root
.
is_dir
():
# If it's a directory, we include everything inside it
self
.
_package
=
root
.
name
self
.
_elements
=
sorted
(
list
(
root
.
glob
(
"**/*"
)))
if
not
any
([
element
.
suffix
==
".py"
for
element
in
self
.
_elements
]
):
if
not
self
.
is_stub_only
()
and
not
self
.
has_modules
(
):
raise
ValueError
(
"{} is not a package."
.
format
(
root
.
name
))
self
.
_is_package
=
True
...
...
tests/masonry/builders/fixtures/pep_561_stub_only/pkg-stubs/__init__.pyi
0 → 100644
View file @
9a283965
tests/masonry/builders/fixtures/pep_561_stub_only/pkg-stubs/module.pyi
0 → 100644
View file @
9a283965
"""Example module"""
from typing import Tuple
version_info = Tuple[int, int, int]
tests/masonry/builders/fixtures/pep_561_stub_only/pkg-stubs/subpkg/__init__.pyi
0 → 100644
View file @
9a283965
tests/masonry/builders/fixtures/pep_561_stub_only/pyproject.toml
0 → 100644
View file @
9a283965
[tool.poetry]
name
=
"pep-561-stubs"
version
=
"0.1"
description
=
"PEP 561 stub package example"
authors
=
[
"Oleg Höfling <oleg.hoefling@gmail.com>"
]
license
=
"MIT"
packages
=
[
{include
=
"pkg-stubs"
}
]
[tool.poetry.dependencies]
python
=
"^3.6"
tests/masonry/builders/fixtures/pep_561_stub_only_partial/pkg-stubs/__init__.pyi
0 → 100644
View file @
9a283965
tests/masonry/builders/fixtures/pep_561_stub_only_partial/pkg-stubs/module.pyi
0 → 100644
View file @
9a283965
"""Example module"""
from typing import Tuple
version_info = Tuple[int, int, int]
tests/masonry/builders/fixtures/pep_561_stub_only_partial/pkg-stubs/py.typed
0 → 100644
View file @
9a283965
partial
tests/masonry/builders/fixtures/pep_561_stub_only_partial/pkg-stubs/subpkg/__init__.pyi
0 → 100644
View file @
9a283965
tests/masonry/builders/fixtures/pep_561_stub_only_partial/pyproject.toml
0 → 100644
View file @
9a283965
[tool.poetry]
name
=
"pep-561-stubs"
version
=
"0.1"
description
=
"PEP 561 stub package example with the py.typed marker file"
authors
=
[
"Oleg Höfling <oleg.hoefling@gmail.com>"
]
license
=
"MIT"
packages
=
[
{include
=
"pkg-stubs"
}
]
[tool.poetry.dependencies]
python
=
"^3.6"
tests/masonry/builders/fixtures/pep_561_stub_only_src/pyproject.toml
0 → 100644
View file @
9a283965
[tool.poetry]
name
=
"pep-561-stubs"
version
=
"0.1"
description
=
"PEP 561 stub package example with an src layout"
authors
=
[
"Oleg Höfling <oleg.hoefling@gmail.com>"
]
license
=
"MIT"
packages
=
[
{include
=
"pkg-stubs"
,
from
=
"src"
}
]
[tool.poetry.dependencies]
python
=
"^3.6"
tests/masonry/builders/fixtures/pep_561_stub_only_src/src/pkg-stubs/__init__.pyi
0 → 100644
View file @
9a283965
tests/masonry/builders/fixtures/pep_561_stub_only_src/src/pkg-stubs/module.pyi
0 → 100644
View file @
9a283965
"""Example module"""
from typing import Tuple
version_info = Tuple[int, int, int]
tests/masonry/builders/fixtures/pep_561_stub_only_src/src/pkg-stubs/subpkg/__init__.pyi
0 → 100644
View file @
9a283965
tests/masonry/builders/test_sdist.py
View file @
9a283965
...
...
@@ -488,3 +488,21 @@ def test_excluded_subpackage():
exec
(
compile
(
setup_ast
,
filename
=
"setup.py"
,
mode
=
"exec"
),
ns
)
assert
ns
[
"packages"
]
==
[
"example"
]
def
test_sdist_package_pep_561_stub_only
():
root
=
fixtures_dir
/
"pep_561_stub_only"
poetry
=
Factory
()
.
create_poetry
(
root
)
builder
=
SdistBuilder
(
poetry
,
NullEnv
(),
NullIO
())
builder
.
build
()
sdist
=
root
/
"dist"
/
"pep-561-stubs-0.1.tar.gz"
assert
sdist
.
exists
()
with
tarfile
.
open
(
str
(
sdist
),
"r"
)
as
tar
:
names
=
tar
.
getnames
()
assert
"pep-561-stubs-0.1/pkg-stubs/__init__.pyi"
in
names
assert
"pep-561-stubs-0.1/pkg-stubs/module.pyi"
in
names
assert
"pep-561-stubs-0.1/pkg-stubs/subpkg/__init__.pyi"
in
names
tests/masonry/builders/test_wheel.py
View file @
9a283965
...
...
@@ -162,3 +162,33 @@ def test_dist_info_file_permissions():
z
.
getinfo
(
"my_package-1.2.3.dist-info/entry_points.txt"
)
.
external_attr
==
0
o644
<<
16
)
@pytest.mark.parametrize
(
"package"
,
[
"pep_561_stub_only"
,
"pep_561_stub_only_partial"
,
"pep_561_stub_only_src"
],
)
def
test_wheel_package_pep_561_stub_only
(
package
):
root
=
fixtures_dir
/
package
WheelBuilder
.
make
(
Factory
()
.
create_poetry
(
root
),
NullEnv
(),
NullIO
())
whl
=
root
/
"dist"
/
"pep_561_stubs-0.1-py3-none-any.whl"
assert
whl
.
exists
()
with
zipfile
.
ZipFile
(
str
(
whl
))
as
z
:
assert
"pkg-stubs/__init__.pyi"
in
z
.
namelist
()
assert
"pkg-stubs/module.pyi"
in
z
.
namelist
()
assert
"pkg-stubs/subpkg/__init__.pyi"
in
z
.
namelist
()
def
test_wheel_package_pep_561_stub_only_includes_typed_marker
():
root
=
fixtures_dir
/
"pep_561_stub_only_partial"
WheelBuilder
.
make
(
Factory
()
.
create_poetry
(
root
),
NullEnv
(),
NullIO
())
whl
=
root
/
"dist"
/
"pep_561_stubs-0.1-py3-none-any.whl"
assert
whl
.
exists
()
with
zipfile
.
ZipFile
(
str
(
whl
))
as
z
:
assert
"pkg-stubs/py.typed"
in
z
.
namelist
()
tests/masonry/utils/fixtures/pep_561_stub_only/bad/__init__.pyi
0 → 100644
View file @
9a283965
tests/masonry/utils/fixtures/pep_561_stub_only/bad/module.pyi
0 → 100644
View file @
9a283965
"""Example module"""
from typing import Tuple
version_info = Tuple[int, int, int]
tests/masonry/utils/fixtures/pep_561_stub_only/good-stubs/__init__.pyi
0 → 100644
View file @
9a283965
tests/masonry/utils/fixtures/pep_561_stub_only/good-stubs/module.pyi
0 → 100644
View file @
9a283965
"""Example module"""
from typing import Tuple
version_info = Tuple[int, int, int]
tests/masonry/utils/test_package_include.py
View file @
9a283965
...
...
@@ -50,3 +50,20 @@ def test_package_include_with_non_existent_directory():
err_str
=
str
(
with_includes
/
"not_a_dir"
)
+
" does not contain any element"
assert
str
(
e
.
value
)
==
err_str
def
test_pep_561_stub_only_package_good_name_suffix
():
pkg_include
=
PackageInclude
(
base
=
fixtures_dir
/
"pep_561_stub_only"
,
include
=
"good-stubs"
)
assert
pkg_include
.
elements
==
[
fixtures_dir
/
"pep_561_stub_only/good-stubs/__init__.pyi"
,
fixtures_dir
/
"pep_561_stub_only/good-stubs/module.pyi"
,
]
def
test_pep_561_stub_only_package_bad_name_suffix
():
with
pytest
.
raises
(
ValueError
)
as
e
:
PackageInclude
(
base
=
fixtures_dir
/
"pep_561_stub_only"
,
include
=
"bad"
)
assert
str
(
e
.
value
)
==
"bad is not a package."
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment