[BUG] Building Wheel for project with src dir not working
Short description
Creating a wheel package from python package with src folder layout, is not possible.
When trying to build a project with following structure, building and testing the package will not work properly.
dephellbug
├── dist
│ ├── dephellbug-0.1.0-py3-none-any.whl
│ └── dephellbug-0.1.0.tar.gz
├── pyproject.toml
├── README.rst
├── setup.py
├── src
│ └── dephellbug
│ └── __init__.py
└── tests
├── __init__.py
└── test_dephellbug.py
Even though, the path was correctly specified in the pyproject.toml using the packages variable and the generated setup.py file is correct, the wheel is still not generated properly.
packages = [
{ include = "dephellbug", from = "src" },
]
Output
Observed Behaviour
The generated sdist package contains a correct setup.py file and can be installed with pip so that the package is available with
from dephellbug import ...
but when building the wheel and installing the wheel, this package will not be available. You will have to import this package using
from src.dephellbug import ...
which will always fail due to the fact, that no submodule of the project will be able to import any other module in the project.
Expected Output
Generating the wheel package will result in a proper aligned package, which can be installed using pip without a problem.
Steps to reproduce
Using poetry and dephell
# create a new directory
mkdir dephellbug
# init project with src folder
cd dephellbug
poetry new --src .
Now we need to update the pyproject.toml file
Add following line to the setting [tool.poetry]
packages = [
{ include = "dephellbug", from = "src" },
]
Now you can either copy the next lines to the file too, or just run the echo command.
echo '# Default section.
# Convert dephell metainfo and dependencies from poetry to setup.py:
# $ dephell deps convert
[tool.dephell.main]
# read from poetry format
from = {format = "poetry", path = "pyproject.toml"}
# and convert into setup.py
to = {format = "setuppy", path = "setup.py"}
# to define a venv we can use later on
[tool.dephell.dephellbug]
' >> pyproject.toml
# create virtualenv
dephell venv create --env=dephellbug
dephell venv shell --env=dephellbug
# build package
dephell project build
# after we bulit the package, pip says, it is installed, but it is not in the site-packages.
# --> also very strange. !
# install the wheel, we built using dephell
# -I forces pip to use the new wheel package and overwrite all old files
python -m pip install dist/*.whl -I
Now we have built and installed the misbehaving wheel package. To verify, that we have the src folder in our path, just find it in the site-packages directory.
# we can find the src dir ... which should NOT be there
ls -la $VIRTUAL_ENV/lib/python3.8/site-packages | grep src
# and we CANNOT find the dephell folder ... which should be there
ls -la $VIRTUAL_ENV/lib/python3.8/site-packages | grep dephellbug
Therefore, we can see the src folder in our site-packages directory, but not our intended package.
Traceback
Traceback does not show any error.
dephell project build --level=DEBUG --format=full --traceback
INFO 2020-02-29 10:01:44 dumping... (format=setuppy)
INFO 2020-02-29 10:01:44 dumping... (format=egginfo)
INFO 2020-02-29 10:01:44 dumping... (format=sdist)
INFO 2020-02-29 10:01:44 dumping... (format=wheel)
INFO 2020-02-29 10:01:44 builded
Config
This config will be generated, following the steps to reproduce.
[tool.poetry]
name = "dephellbug"
version = "0.1.0"
description = ""
authors = ["Username <[email protected]>"]
packages = [
{ include = "dephellbug", from = "src" },
]
[tool.poetry.dependencies]
python = "^3.8"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
# Default section.
# Convert dephell metainfo and dependencies from poetry to setup.py:
# $ dephell deps convert
[tool.dephell.main]
# read from poetry format
from = {format = "poetry", path = "pyproject.toml"}
# and convert into setup.py
to = {format = "setuppy", path = "setup.py"}
[tool.dephell.dephellbug]
Versions
This version was installed on 2020.02.29 using
curl -L dephell.org/install | python3
Version information:
{
"cache": "6.02Mb",
"path": "/usr/share/dephell/venvs/dephell/lib/python3.8/site-packages/dephell",
"python": "/usr/share/dephell/venvs/dephell/bin/python3",
"version": "0.8.1",
"versions": {
"dephell-archive": "0.1.6",
"dephell-argparse": "0.1.2",
"dephell-changelogs": "0.0.1",
"dephell-discover": "0.2.10",
"dephell-licenses": "0.1.6",
"dephell-links": "0.1.5",
"dephell-markers": "1.0.3",
"dephell-pythons": "0.1.14",
"dephell-setuptools": "0.2.3",
"dephell-shells": "0.1.4",
"dephell-specifier": "0.2.1",
"dephell-venvs": "0.1.17",
"dephell-versioning": "0.1.1"
}
}
I seem to be also having this problem. Surely there is a simple work around?
I tried to find one but it was easier, to just dump using dephell for my project. There were also some issues with updating the version, where I opened an issue and also submitted a solution but it seems, those are not taken into consideration from the developers (keep in mind, I posted those things in February - 3 month ago ... )
It's an OSS, and is community-driven, there is no "the developers". If someone wants to hunt down and fix this bug, I'll merge the PR and build a release. In fact, I fix most of the bugs here, and eventually will get here and fix, if nobody will done it before. Also, we are on the track of fixing bugs over introducing new features, the latest release was with bugfixes only. So, we understand that every such report is important. However, I had no time for this one yet since I have other projects as well as a job that I must do to pay for my bills.
So, if this is important for you, feel free to debug, fix and send pr. My guess is that it's somewhere in dephell_discovery. If you have no time for it as well, no worries, it will be fixed eventually. Thank you for your understanding.
I do appreciate open source projects and also like contributing if it is in my capabilities. For this particular bug, I was pretty lost at the first glance and had no idea how I could fix it. I might have a second look with your hint, the bug might be in dephell_discovery, in consideration :)
And about pull requests. I still have one pr open in dephell_versioning which introduces alpha and beta versioning.