-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
and install --single-version-externally-managed
are not compatible with each other for namespace packages
#250
Comments
Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco): Thanks for the detailed bug report. Well stated. I would say that anything with a That implies that Option (2) looks viable on its surface. Would that technique still work if there were multiple packages (of the same namespace) installed using Feel free to take a stab at tests and/or implementation toward that end. It sure would be nice to see pip issue 3 closed. I do suggest you draw attention to this ticket in distutils-sig and pypa-dev for broader feedback. |
Original comment by rbtcollins (Bitbucket: rbtcollins, GitHub: rbtcollins): Hi, I have a related situation: I'd like to be able to clone the source of a tree using a namespace package (say foo.bar) and have 'import foo.bar' work when other elements of foo are already installed. A pth file with: in it suffices to enable this, but ideally that wouldn't be needed. I'm poking around at the moment to figure out just whats up. |
Original comment by rbtcollins (Bitbucket: rbtcollins, GitHub: rbtcollins): (And such a .pth file also fixes importing foo.bar after doing pip install -e .) |
Original comment by rbtcollins (Bitbucket: rbtcollins, GitHub: rbtcollins): Further data; the key call is fixup_namespace_packages(''), everything else Just Works for both a simple clone on PYTHONPATH and for "pip install -e ." and for 'python setup.py develop'. I'm sure this indicates a race somewhere in site.py, digging deeper. But it suggests that fixing the race will be sufficient (e.g. ensure that by the end of site.py processing we've done a fixup_namespace_packages('') call). |
Original comment by EvaSDK (Bitbucket: EvaSDK, GitHub: EvaSDK): Got bitten by this a well after splitting my company's huge module into namespaces. |
Original comment by Guyverthree (Bitbucket: Guyverthree, GitHub: Guyverthree): I am also interested in the work on this. |
Original comment by ncoghlan (Bitbucket: ncoghlan, GitHub: ncoghlan): I have an alternative suggestion: give That is, I'd like to request the ability to disable the generation of namespace package If there's no |
Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):
I've tried to verify this assertion without success:
I helped contribute to the PEP-420 implementation (mostly in design discussions and tests), but my understanding was that PEP-420 required some foundational changes to the C-level import machinery itself, so couldn't be readily backported to Python 3.2 or earlier. @ncoghlan Have you seen or can you produce an example where the presence of |
Original comment by ncoghlan (Bitbucket: ncoghlan, GitHub: ncoghlan): Running "importlib2.install_import_hooks()" at startup should completely |
Original comment by rbtcollins (Bitbucket: rbtcollins, GitHub: rbtcollins): You may need to hook it as Nick says. I looked into supporting namespace packages in 2.x via this route about 6 months back and it wasn't quite there, but it certainly was the intent. I'd file a bug on this in the importlib2 tracker. |
Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco): Thanks @ncoghlan for the tip. I found that I was able to make the example succeed with this invocation:
I'm excited about this prospect and would like to continue to explore it. It seems like maybe this issue isn't the best forum for this discussion. I've opened a new one as #406. |
Original comment by embray (Bitbucket: embray, GitHub: embray): Still catching up on this thread, but I would love to see this fixed. I've been aware of this problem for years, and just worked around it whenever it affected me. I like some version of @hongqn's second proposal, but now I'll go back and see what others have said. Just wanted to add my 👍 to fixing this. |
Original comment by embray (Bitbucket: embray, GitHub: embray): Ran across this issue yet again, in light of recently experiencing this issue again, having a thought similar to this as to how to fix it, and being quite sure this has been discussed before.... Last time there was any activity on this, the discussion got derailed by the suggestion to use For the narrow case interoperability between the legacy setuptools The existing behavior of setuptools with respect to both namespace packages and dev installs are hacks. We just need to fix those hacks to be compatible with each other, and forget them in cases where they aren't needed at all. |
Original comment by embray (Bitbucket: embray, GitHub: embray): BTW, I can confirm that modifying |
@embray Did you have any luck working on a patch for this issue? |
Building on the draft in #789, and with the help of Barry, Andrew, and Eric today, I made some progress on the develop-nspkg branch. Initial testing indicates that this technique does work as long as the Some concerns still remain:
|
I've added a test that captures the basic expectation (linked above). In the develop-nspkg-always branch, I've removed the check for |
And he's right. The problem is that the presence of the If I revert the behavior introduced in #805, the tests in the develop-nspkg-always branch now pass. I think I want to write a test for #805 to demonstrate the use case and expectation. In the meantime, can @ncoghlan or any one else imagine a way that the |
I've done this and pushed the test into master. |
@jaraco Looking more closely at that, the problematic piece is this expression: So in 3.5+, what you probably want to be doing is:
I think the necessary parameters to replace the current types.ModuleType call in the template would look something like:
The current explicit version check would then be replaced by a check for If you wanted to handle 3.4 as well, then the simplest approach would likely be to extract the pieces of https://hg.python.org/cpython/file/3.5/Lib/importlib/_bootstrap.py#l570 that are applicable to |
Thanks @ncoghlan. That's really helpful. I've tested it and it appears to be working on Python 3.5 and 3.6. The problem is now Python 3.3 and 3.4 - since they don't have the interfaces, and since this code needs to be embedded in a .pth line, it's not really feasible to backport importlib machinery. I think it's also not viable to include the behavior in a library (like setuptools) -- because this logic runs at startup, it probably shouldn't have dependencies on any functionality not in the stdlib. I did draft an implementation using such a technique, but it would be very brittle in scenarios where setuptools is downgraded or possibly upgraded or uninstalled. Which leads me to think that we might have specifically not to support Python 3.3 and 3.4 for this use case. Can anyone thing of a way around this issue? |
@jaraco Limiting support for this to 3.5+ only seems like a reasonable decision to me. There were genuinely missing pieces in the initial iterations of PEP 420 and PEP 451, and they didn't get fully resolved until the new helper APIs were added in 3.5. |
# Changes ## Added - setuptools machinery to make this an installable package ([b0a68b5](b0a68b5)) - console entry point for `graph_parser3.py` which is now invokable by the command `graph_parser` when the npdependnecy package is installed ([1ed4e4c](1ed4e4c)) - a version number (0.1.0), I suggest using [semver](https://semver.org/) for future versions of the package ## Changed - The `src` dir has been renamed to `npdependency` because setuptools [makes](pypa/setuptools#250) everything harder when a package's parent directory is not named after the package - The readme has been changed to reflect the changes here and now advises to install this as a package (for now using pip and the git http url, but we should probably release it on Pypi at some point) and use the console entry point instead of calling the script directly (although that is still possible, although the path using `src` have to be rewritten, see above) - `DependencyDataset` is now in `deptree` rather than directly in `graph_parser3` ## Removed - The Profiterole and SPMRL stuff, which is not actually related (I think?) to the parser. It still lives in the git history anyway, but we could make it a dedicated repo (in fact, I already have a repo for the MCVF conversion stuff somewhere with improvements)
Originally reported by: hongqn (Bitbucket: hongqn, GitHub: hongqn)
To reproduce this issue, do the following in a virtualenv:
prepare source code of two packages with same namespace package
ns
:install pkg1 using --single-version-externally-managed
install pkg2 using develop
pkg1 is accessible
pkg2 is unexpectedly inaccessible
This was discussed in pip's issue tracker pypa/pip#3 years ago (because pip uses
install --single-version-externally-managed
forpip install
and usedevelop
forpip install --editable
), but they still have not gotten a resolution.I think this issue should be resolved in setuptools instead of pip.
install --single-version-externally-managed
creates a{pkg}-nspkg.pth
in site-packages directory. It will create a ns module and assign its__path__
to the ns directory in site-packages. Sopkg_resources.declare_namespace()
in pkg2's ns/init.py has no chance to run.I have two proposals to fix it:
Fix
install --single-version-exteranlly-managed
. Modify the{pkg}-nspkg.pth
file to append a lineat the end of it. So it will scan
sys.path
to gather other directories intons.__path__
.A tricky point is that we must ensure the
{pkg}-nspkg.pth
filename is alphabetically larger thaneasy-install.pth
, so that we have source code directory installed bydevelop
command insys.path
when runningdeclare_namespace
. Is to rename tozzz-{pkg}-nspkg.pth
a good idea?Fix
develop
command. Create a{pkg}-nspkg.pth
in site-packages directory when a namespace package is installed usingdevelop
command, like whatinstall --single-version-externally-managed
does. The content of the pth file could be:The
/path/to/sourcecode
line is duplicated with what is inserted in easy-install.pth. It is here to make suresys.path
contains it beforedeclare_namespace
runs. It could be omitted if we have azzz-
prefix for the pth filename.What's the dev team's opinion? I prefer to the second proposal because it only affects
develop
command which is mostly used in develop environment so it will not affect production systems.I'd like to contribute code fix if you agree with either one of the proposals.
The text was updated successfully, but these errors were encountered: