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
d2ed7d59
Unverified
Commit
d2ed7d59
authored
Aug 05, 2019
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix packaging with explicit packages and src directories
parent
775f38fd
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
82 additions
and
22 deletions
+82
-22
poetry/masonry/builders/builder.py
+23
-2
poetry/masonry/builders/complete.py
+37
-7
poetry/masonry/builders/sdist.py
+9
-8
poetry/masonry/builders/wheel.py
+3
-0
tests/masonry/builders/fixtures/with-include/pyproject.toml
+1
-0
tests/masonry/builders/fixtures/with-include/src/src_package/__init__.py
+0
-0
tests/masonry/builders/test_complete.py
+6
-3
tests/masonry/builders/test_sdist.py
+2
-2
tests/test_poetry.py
+1
-0
No files found.
poetry/masonry/builders/builder.py
View file @
d2ed7d59
...
@@ -37,16 +37,37 @@ class Builder(object):
...
@@ -37,16 +37,37 @@ class Builder(object):
AVAILABLE_PYTHONS
=
{
"2"
,
"2.7"
,
"3"
,
"3.4"
,
"3.5"
,
"3.6"
,
"3.7"
}
AVAILABLE_PYTHONS
=
{
"2"
,
"2.7"
,
"3"
,
"3.4"
,
"3.5"
,
"3.6"
,
"3.7"
}
def
__init__
(
self
,
poetry
,
env
,
io
):
# type: (Poetry, Env, IO) -> None
format
=
None
def
__init__
(
self
,
poetry
,
env
,
io
,
ignore_packages_formats
=
False
):
# type: (Poetry, Env, IO) -> None
self
.
_poetry
=
poetry
self
.
_poetry
=
poetry
self
.
_env
=
env
self
.
_env
=
env
self
.
_io
=
io
self
.
_io
=
io
self
.
_package
=
poetry
.
package
self
.
_package
=
poetry
.
package
self
.
_path
=
poetry
.
file
.
parent
self
.
_path
=
poetry
.
file
.
parent
packages
=
[]
for
p
in
self
.
_package
.
packages
:
formats
=
p
.
get
(
"format"
,
[])
if
not
isinstance
(
formats
,
list
):
formats
=
[
formats
]
if
(
formats
and
self
.
format
and
self
.
format
not
in
formats
and
not
ignore_packages_formats
):
continue
packages
.
append
(
p
)
self
.
_module
=
Module
(
self
.
_module
=
Module
(
self
.
_package
.
name
,
self
.
_package
.
name
,
self
.
_path
.
as_posix
(),
self
.
_path
.
as_posix
(),
packages
=
self
.
_package
.
packages
,
packages
=
packages
,
includes
=
self
.
_package
.
include
,
includes
=
self
.
_package
.
include
,
)
)
self
.
_meta
=
Metadata
.
from_package
(
self
.
_package
)
self
.
_meta
=
Metadata
.
from_package
(
self
.
_package
)
...
...
poetry/masonry/builders/complete.py
View file @
d2ed7d59
...
@@ -2,6 +2,9 @@ import os
...
@@ -2,6 +2,9 @@ import os
import
tarfile
import
tarfile
import
poetry.poetry
import
poetry.poetry
from
poetry.io.null_io
import
NullIO
from
poetry.utils._compat
import
Path
from
poetry.utils.helpers
import
temporary_directory
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
...
@@ -15,19 +18,46 @@ class CompleteBuilder(Builder):
...
@@ -15,19 +18,46 @@ class CompleteBuilder(Builder):
# We start by building the tarball
# We start by building the tarball
# We will use it to build the wheel
# We will use it to build the wheel
sdist_builder
=
SdistBuilder
(
self
.
_poetry
,
self
.
_env
,
self
.
_io
)
sdist_builder
=
SdistBuilder
(
self
.
_poetry
,
self
.
_env
,
self
.
_io
)
build_for_all_formats
=
False
for
p
in
self
.
_package
.
packages
:
formats
=
p
.
get
(
"format"
,
[])
if
not
isinstance
(
formats
,
list
):
formats
=
[
formats
]
if
formats
and
sdist_builder
.
format
not
in
formats
:
build_for_all_formats
=
True
break
sdist_file
=
sdist_builder
.
build
()
sdist_file
=
sdist_builder
.
build
()
self
.
_io
.
write_line
(
""
)
self
.
_io
.
write_line
(
""
)
dist_dir
=
self
.
_path
/
"dist"
dist_dir
=
self
.
_path
/
"dist"
with
self
.
unpacked_tarball
(
sdist_file
)
as
tmpdir
:
WheelBuilder
.
make_in
(
if
build_for_all_formats
:
poetry
.
poetry
.
Poetry
.
create
(
tmpdir
),
sdist_builder
=
SdistBuilder
(
self
.
_env
,
self
.
_poetry
,
self
.
_env
,
NullIO
(),
ignore_packages_formats
=
True
self
.
_io
,
dist_dir
,
original
=
self
.
_poetry
,
)
)
with
temporary_directory
()
as
tmp_dir
:
sdist_file
=
sdist_builder
.
build
(
Path
(
tmp_dir
))
with
self
.
unpacked_tarball
(
sdist_file
)
as
tmpdir
:
WheelBuilder
.
make_in
(
poetry
.
poetry
.
Poetry
.
create
(
tmpdir
),
self
.
_env
,
self
.
_io
,
dist_dir
,
original
=
self
.
_poetry
,
)
else
:
with
self
.
unpacked_tarball
(
sdist_file
)
as
tmpdir
:
WheelBuilder
.
make_in
(
poetry
.
poetry
.
Poetry
.
create
(
tmpdir
),
self
.
_env
,
self
.
_io
,
dist_dir
,
original
=
self
.
_poetry
,
)
@classmethod
@classmethod
@contextmanager
@contextmanager
...
...
poetry/masonry/builders/sdist.py
View file @
d2ed7d59
...
@@ -44,6 +44,9 @@ setup(**setup_kwargs)
...
@@ -44,6 +44,9 @@ setup(**setup_kwargs)
class
SdistBuilder
(
Builder
):
class
SdistBuilder
(
Builder
):
format
=
"sdist"
def
build
(
self
,
target_dir
=
None
):
# type: (Path) -> Path
def
build
(
self
,
target_dir
=
None
):
# type: (Path) -> Path
self
.
_io
.
write_line
(
" - Building <info>sdist</info>"
)
self
.
_io
.
write_line
(
" - Building <info>sdist</info>"
)
if
target_dir
is
None
:
if
target_dir
is
None
:
...
@@ -119,16 +122,17 @@ class SdistBuilder(Builder):
...
@@ -119,16 +122,17 @@ class SdistBuilder(Builder):
pkg_dir
,
_packages
,
_package_data
=
self
.
find_packages
(
include
)
pkg_dir
,
_packages
,
_package_data
=
self
.
find_packages
(
include
)
if
pkg_dir
is
not
None
:
if
pkg_dir
is
not
None
:
package_dir
[
""
]
=
os
.
path
.
relpath
(
pkg_dir
,
str
(
self
.
_path
))
for
p
in
_packages
:
package_dir
[
p
]
=
os
.
path
.
relpath
(
pkg_dir
,
str
(
self
.
_path
))
packages
+=
[
p
for
p
in
_packages
if
p
not
in
packages
]
packages
+=
[
p
for
p
in
_packages
if
p
not
in
packages
]
package_data
.
update
(
_package_data
)
package_data
.
update
(
_package_data
)
else
:
else
:
if
include
.
source
is
not
None
:
package_dir
[
""
]
=
str
(
include
.
base
.
relative_to
(
self
.
_path
))
module
=
include
.
elements
[
0
]
.
relative_to
(
include
.
base
)
.
stem
module
=
include
.
elements
[
0
]
.
relative_to
(
include
.
base
)
.
stem
if
include
.
source
is
not
None
:
package_dir
[
module
]
=
str
(
include
.
base
.
relative_to
(
self
.
_path
))
if
module
not
in
modules
:
if
module
not
in
modules
:
modules
.
append
(
module
)
modules
.
append
(
module
)
else
:
else
:
...
@@ -224,7 +228,6 @@ class SdistBuilder(Builder):
...
@@ -224,7 +228,6 @@ class SdistBuilder(Builder):
# Relative to the top-level package
# Relative to the top-level package
return
pkg_name
,
Path
(
rel_path
)
.
as_posix
()
return
pkg_name
,
Path
(
rel_path
)
.
as_posix
()
excluded_files
=
self
.
find_excluded_files
()
for
path
,
dirnames
,
filenames
in
os
.
walk
(
str
(
base
),
topdown
=
True
):
for
path
,
dirnames
,
filenames
in
os
.
walk
(
str
(
base
),
topdown
=
True
):
if
os
.
path
.
basename
(
path
)
==
"__pycache__"
:
if
os
.
path
.
basename
(
path
)
==
"__pycache__"
:
continue
continue
...
@@ -267,9 +270,7 @@ class SdistBuilder(Builder):
...
@@ -267,9 +270,7 @@ class SdistBuilder(Builder):
@classmethod
@classmethod
def
convert_dependencies
(
def
convert_dependencies
(
cls
,
cls
,
package
,
dependencies
# type: Package # type: List[Dependency]
package
,
# type: Package
dependencies
,
# type: List[Dependency]
):
):
main
=
[]
main
=
[]
extras
=
defaultdict
(
list
)
extras
=
defaultdict
(
list
)
...
...
poetry/masonry/builders/wheel.py
View file @
d2ed7d59
...
@@ -37,6 +37,9 @@ Tag: {tag}
...
@@ -37,6 +37,9 @@ Tag: {tag}
class
WheelBuilder
(
Builder
):
class
WheelBuilder
(
Builder
):
format
=
"wheel"
def
__init__
(
self
,
poetry
,
env
,
io
,
target_dir
=
None
,
original
=
None
):
def
__init__
(
self
,
poetry
,
env
,
io
,
target_dir
=
None
,
original
=
None
):
super
(
WheelBuilder
,
self
)
.
__init__
(
poetry
,
env
,
io
)
super
(
WheelBuilder
,
self
)
.
__init__
(
poetry
,
env
,
io
)
...
...
tests/masonry/builders/fixtures/with-include/pyproject.toml
View file @
d2ed7d59
...
@@ -27,6 +27,7 @@ packages = [
...
@@ -27,6 +27,7 @@ packages = [
{
include
=
"package_with_include"
}
,
{
include
=
"package_with_include"
}
,
{
include
=
"tests"
,
format
=
"sdist"
}
,
{
include
=
"tests"
,
format
=
"sdist"
}
,
{
include
=
"for_wheel_only"
,
format
=
["wheel"]
}
,
{
include
=
"for_wheel_only"
,
format
=
["wheel"]
}
,
{
include
=
"src_package"
,
from
=
"src"
}
,
]
]
include
=
[
include
=
[
...
...
tests/masonry/builders/fixtures/with-include/src/src_package/__init__.py
0 → 100644
View file @
d2ed7d59
tests/masonry/builders/test_complete.py
View file @
d2ed7d59
...
@@ -436,7 +436,8 @@ def test_package_with_include(mocker):
...
@@ -436,7 +436,8 @@ def test_package_with_include(mocker):
assert
"with-include-1.2.3/pyproject.toml"
in
names
assert
"with-include-1.2.3/pyproject.toml"
in
names
assert
"with-include-1.2.3/setup.py"
in
names
assert
"with-include-1.2.3/setup.py"
in
names
assert
"with-include-1.2.3/PKG-INFO"
in
names
assert
"with-include-1.2.3/PKG-INFO"
in
names
assert
"for_wheel_only/__init__"
not
in
names
assert
"with-include-1.2.3/for_wheel_only/__init__.py"
not
in
names
assert
"with-include-1.2.3/src/src_package/__init__.py"
in
names
setup
=
tar
.
extractfile
(
"with-include-1.2.3/setup.py"
)
.
read
()
setup
=
tar
.
extractfile
(
"with-include-1.2.3/setup.py"
)
.
read
()
setup_ast
=
ast
.
parse
(
setup
)
setup_ast
=
ast
.
parse
(
setup
)
...
@@ -444,11 +445,12 @@ def test_package_with_include(mocker):
...
@@ -444,11 +445,12 @@ def test_package_with_include(mocker):
setup_ast
.
body
=
[
n
for
n
in
setup_ast
.
body
if
isinstance
(
n
,
ast
.
Assign
)]
setup_ast
.
body
=
[
n
for
n
in
setup_ast
.
body
if
isinstance
(
n
,
ast
.
Assign
)]
ns
=
{}
ns
=
{}
exec
(
compile
(
setup_ast
,
filename
=
"setup.py"
,
mode
=
"exec"
),
ns
)
exec
(
compile
(
setup_ast
,
filename
=
"setup.py"
,
mode
=
"exec"
),
ns
)
assert
"package_dir"
not
in
ns
assert
ns
[
"package_dir"
]
==
{
"src_package"
:
"src"
}
assert
ns
[
"packages"
]
==
[
assert
ns
[
"packages"
]
==
[
"extra_dir"
,
"extra_dir"
,
"extra_dir.sub_pkg"
,
"extra_dir.sub_pkg"
,
"package_with_include"
,
"package_with_include"
,
"src_package"
,
"tests"
,
"tests"
,
]
]
assert
ns
[
"package_data"
]
==
{
""
:
[
"*"
]}
assert
ns
[
"package_data"
]
==
{
""
:
[
"*"
]}
...
@@ -470,4 +472,5 @@ def test_package_with_include(mocker):
...
@@ -470,4 +472,5 @@ def test_package_with_include(mocker):
assert
"my_module.py"
in
names
assert
"my_module.py"
in
names
assert
"notes.txt"
in
names
assert
"notes.txt"
in
names
assert
"package_with_include/__init__.py"
in
names
assert
"package_with_include/__init__.py"
in
names
assert
"with-include-1.2.3/tests/__init__.py"
not
in
names
assert
"tests/__init__.py"
not
in
names
assert
"src_package/__init__.py"
in
names
tests/masonry/builders/test_sdist.py
View file @
d2ed7d59
...
@@ -315,7 +315,7 @@ def test_with_src_module_file():
...
@@ -315,7 +315,7 @@ def test_with_src_module_file():
setup_ast
.
body
=
[
n
for
n
in
setup_ast
.
body
if
isinstance
(
n
,
ast
.
Assign
)]
setup_ast
.
body
=
[
n
for
n
in
setup_ast
.
body
if
isinstance
(
n
,
ast
.
Assign
)]
ns
=
{}
ns
=
{}
exec
(
compile
(
setup_ast
,
filename
=
"setup.py"
,
mode
=
"exec"
),
ns
)
exec
(
compile
(
setup_ast
,
filename
=
"setup.py"
,
mode
=
"exec"
),
ns
)
assert
ns
[
"package_dir"
]
==
{
""
:
"src"
}
assert
ns
[
"package_dir"
]
==
{
"
module_src
"
:
"src"
}
assert
ns
[
"modules"
]
==
[
"module_src"
]
assert
ns
[
"modules"
]
==
[
"module_src"
]
builder
.
build
()
builder
.
build
()
...
@@ -340,7 +340,7 @@ def test_with_src_module_dir():
...
@@ -340,7 +340,7 @@ def test_with_src_module_dir():
setup_ast
.
body
=
[
n
for
n
in
setup_ast
.
body
if
isinstance
(
n
,
ast
.
Assign
)]
setup_ast
.
body
=
[
n
for
n
in
setup_ast
.
body
if
isinstance
(
n
,
ast
.
Assign
)]
ns
=
{}
ns
=
{}
exec
(
compile
(
setup_ast
,
filename
=
"setup.py"
,
mode
=
"exec"
),
ns
)
exec
(
compile
(
setup_ast
,
filename
=
"setup.py"
,
mode
=
"exec"
),
ns
)
assert
ns
[
"package_dir"
]
==
{
""
:
"src"
}
assert
ns
[
"package_dir"
]
==
{
"
package_src
"
:
"src"
}
assert
ns
[
"packages"
]
==
[
"package_src"
]
assert
ns
[
"packages"
]
==
[
"package_src"
]
builder
.
build
()
builder
.
build
()
...
...
tests/test_poetry.py
View file @
d2ed7d59
...
@@ -125,6 +125,7 @@ def test_poetry_with_packages_and_includes():
...
@@ -125,6 +125,7 @@ def test_poetry_with_packages_and_includes():
{
"include"
:
"package_with_include"
},
{
"include"
:
"package_with_include"
},
{
"include"
:
"tests"
,
"format"
:
"sdist"
},
{
"include"
:
"tests"
,
"format"
:
"sdist"
},
{
"include"
:
"for_wheel_only"
,
"format"
:
[
"wheel"
]},
{
"include"
:
"for_wheel_only"
,
"format"
:
[
"wheel"
]},
{
"include"
:
"src_package"
,
"from"
:
"src"
},
]
]
assert
package
.
include
==
[
"extra_dir/vcs_excluded.txt"
,
"notes.txt"
]
assert
package
.
include
==
[
"extra_dir/vcs_excluded.txt"
,
"notes.txt"
]
...
...
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