Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

develop mode does not respect src structure #230

Closed
ghost opened this issue Jul 8, 2014 · 14 comments
Closed

develop mode does not respect src structure #230

ghost opened this issue Jul 8, 2014 · 14 comments

Comments

@ghost
Copy link

ghost commented Jul 8, 2014

Originally reported by: marscher (Bitbucket: marscher, GitHub: marscher)


Assume you have project with a src folder:

#!python

root/
root/setup.py
root/src/my_pkg/__init__.py
....

in setup.py one have mapped the src folder, so it can be found during installation.

#!python

setup( ....
   package_dir = { 'my_pkg' : 'src' } 
)

If one tries to install an egg link to the pkg via setup.py develop, this mapping is happily ignored. I'am not sure, if this is an issue either with setuptools or distutils. Symlinking my_pkg to the root fixes the problem.


@ghost
Copy link
Author

ghost commented Jul 11, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


This is a long-standing issue, originally reported as Distribute 177. If you read the background there, you'll see that the problem doesn't have an obvious general solution.

Edit: Distribute 177 is here.

@ghost
Copy link
Author

ghost commented Oct 20, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Issue #276 was marked as a duplicate of this issue.

@ghost
Copy link
Author

ghost commented Nov 28, 2014

Original comment by mgedmin (Bitbucket: mgedmin, GitHub: mgedmin):


@marscher: your setup.py looks wrong. AFAIU it should say

package_dir = { 'my_pkg' : 'src/my_pkg' }

A simple workaround exists, as long as the package name matches the directory name: strip the last name from both sides of the mapping and use

package_dir = { '' : 'src' }

@jaraco: perhaps it'd be good to have 'python setup.py develop' fail with an error message instead of resulting in a broken .pth file? As long as it doesn't break the workaround, which is widely used in thousands of packages, of course.

I think it should be possible to solve this for all cases where the directory names in the source tree match package names, with a little bit of programming.

(EDIT: updated @-mentions to use people's bitbucket usernames rather than first names. Sorry unrelated people who were probably pinged by mail, I didn't know that bitbucket actually parsed @-mentions in comments!)

@ghost
Copy link
Author

ghost commented Nov 20, 2015

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Issue #463 was marked as a duplicate of this issue.

@ghost ghost added minor bug labels Mar 29, 2016
teto added a commit to teto/paperwork-backend that referenced this issue Feb 22, 2017
setuptools with develop does not support package_dir
pypa/setuptools#230

This commit renames folder so that the very useful develop mode works
out of the box.
teto added a commit to teto/paperwork-backend that referenced this issue Feb 22, 2017
setuptools with develop does not support package_dir
pypa/setuptools#230

This commit renames folder so that the very useful develop mode works
out of the box.
@jaraco
Copy link
Member

jaraco commented Sep 7, 2017

@RonnyPfannschmidt has suggested a few options:

  • symlink the packages during develop install
  • create shim file
  • create meta import hook

All of these run into challenges thinking about the total workflow (how are they registered/uninstalled).

If someone could put together a routine or package that demonstrates a technique for installing such a hook, then we can work to devise a workflow around it to use within the develop command and installers.

@RonnyPfannschmidt
Copy link
Contributor

i documented some of it in https://mail.python.org/pipermail/distutils-sig/2017-September/031498.html

i made a prior implementation in https://github.com/RonnyPfannschmidt/gumby_elf/blob/03391bdf0cc66faaa2a5e034769e557c31974fd9/src/packing.py#L34-L43

i believe the best prospect is building/installing the dist info alongside a bootstrapped and a altered record file

cript0nauta added a commit to cript0nauta/sampleproject that referenced this issue Mar 14, 2019
It is working with `setup.py install` and `pip install .`, but not with
`setup.py develop` or `pip install -e .`

See:
pypa/pip#3160
pypa/setuptools#230
edran added a commit to edran/MinAtar that referenced this issue Apr 5, 2019
This is done to enable using `pip install -e .`, and to follow standard
packaging rules.

See:
pypa/pip#3160
pypa/setuptools#230
kenjyoung pushed a commit to kenjyoung/MinAtar that referenced this issue Apr 8, 2019
* Move package requirements in setup.py for ease of installation

* s/minatar_environment/minatar/, move environments into main package

This is done to enable using `pip install -e .`, and to follow standard
packaging rules.

See:
pypa/pip#3160
pypa/setuptools#230

* Update installation instructions in README.md

* setup uses setuptools rather than disutils
rmorshea added a commit to reactive-python/reactpy that referenced this issue Apr 29, 2019
ap-- added a commit to loopbio/FreemooVR that referenced this issue Jun 14, 2019
Annoyingly, there's a long outstanding bug in setuptools that
prevents editable installs to work with python projects which
use the src folder structure.

pypa/setuptools#230

for now, just symlink to the module root to make it work.
ap-- added a commit to loopbio/FreemooVR that referenced this issue Jun 14, 2019
So after reading
https://bitbucket.org/tarek/distribute/issues/177#comment-4133779
and again reading
pypa/setuptools#230 (comment)
I realized the correct fix is this.
And it only works, because the package name
'freemoovr' is equal to the folder 'src/freemoovr'.

So setting package_dir in setuptools.setup() can work with
`pip install -e` (or `python setup.py develop`) if you go
from a mapping like:
{'mypkg': 'subfolder/mypkg'} to {'': 'subfolder'}
This works because the egg file and the easy-install.pth file
will then correctly resolve to '/PATH-TO-SETUP-PY/subfolder'.
ArkaneMoose added a commit to ArkaneMoose/BotBot that referenced this issue Dec 17, 2019
First, venvs are cool, so add them to the .gitignore.
Second, if I do python3 setup.py develop, it doesn't work properly
because of the package_dirs entry (see pypa/setuptools#230). So, rename
the source directory to botbot so as to not need package_dirs (uglier
in my opinion, but whatever).
Third, use relative imports, because relative imports are cool (and
because DRY).
nikonikoniko pushed a commit to circularfashion/cf-circularity-id-standard that referenced this issue Jan 14, 2020
TheJokersThief added a commit to TheJokersThief/simple-gcp-secrets-manager-puller that referenced this issue Jul 15, 2020
andrewdelong added a commit to andrewdelong/PySCIPOpt that referenced this issue Mar 29, 2021
- fixed `setup.py develop` using suggestion here: pypa/setuptools#230 (comment)
- release GIL when calling SCIPsolve, SCIPpresolve, and SCIPfreeTransform to facilitate thread-level parallelism (e.g., from `joblib`) when solving batches of instances.
@nthienan
Copy link

nthienan commented Nov 8, 2021

Hi there,

Any updates on this?

@jaraco
Copy link
Member

jaraco commented Nov 8, 2021

No updates, although the packaging standard have developed and now there is some standards for supporting editable installs. Perhaps supporting that PEP could open up opportunities for this use case.

@abravalheri
Copy link
Contributor

I believe v64.0.3+ solves the problem with package_dir and editable installs reported here.

mj-will added a commit to uofgravity/glasflow that referenced this issue Sep 21, 2022
This reverts commit dcb6ed2. Editable installs have been fixed as of setuptools v64.0.03 (pypa/setuptools#230) though this does require an up-to-date version of pip.
@gnaggnoyil
Copy link

I'm sorry I tried setuptools 65.5.0 with python 3.10.9 with the case provided by OP and the problem still seems to exist. I ran python setup.py develop and then ran import my_pkg in a python interpreter. I still got the "ModuleNotFoundError: No module named 'my_pkg'" error here.

@abravalheri
Copy link
Contributor

abravalheri commented Mar 16, 2023

Hi @gnaggnoyil please note that it is not possible to fix this problem if you are using python setup.py develop. This is well known limitation of develop.

If you want to give it a try to editable install, please use pip install -e .

@gnaggnoyil
Copy link

@abravalheri Hello, I also tried pip install -e . and the result was the same. I also tried to inspect the files that pip installed in my venv and the files seems to be same as those installed through setup.py develop.

@abravalheri
Copy link
Contributor

abravalheri commented Mar 17, 2023

In this case, pip might be handling your project with the legacy procedure.

You can try adding pyproject.toml or run pip with the --use-pep517 flag -- this is going to be the default in pip 23.1. Also, make sure that you are running an up-to-date version of pip.

If that does not work. Please open a new issue with a minimal example that reproduces your error.

@DaanVanVugt
Copy link

Using the --use-pep517 flag fixed this problem for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants