Use relative imports for intra-package imports

Bug #1653126 reported by Jason R. Coombs
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pkginfo
Fix Released
Undecided
Unassigned

Bug Description

In [setuptools 848](https://github.com/pypa/setuptools/pull/848), a user is attempting to vendor pkginfo into setuptools as setuptools.extern.pkginfo, but the absolute imports prevent the relocated package from importing its own modules. Would you consider replacing these absolute imports with relative ones to ease the burden of relocating pkginfo?

Related branches

Revision history for this message
Tres Seaver (tseaver) wrote :

Sorry I missed seeing this when it was submitted: somehow my mail notifications got switched off. I would be willing to merge such a change.

Changed in pkginfo:
status: New → Confirmed
Revision history for this message
Tres Seaver (tseaver) wrote :

Note that there are tests which expect to be able to do 'import pkginfo', in order to then use the module for introspection. Relative import syntax doesn't support something like 'import .. as pkginfo', which would make it harder to do.

Revision history for this message
Jason R. Coombs (jaraco) wrote :

I'm trying to run the tests, but they always fail during the install of the sdist with:

```
Processing ./.tox/dist/pkginfo-1.4.1.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-6anodl25-build/setup.py", line 19, in <module>
        CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
    FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-6anodl25-build/CHANGES.txt'
```

This failure happens even in trunk. If I set `tox.skipsdist=True` in `tox.ini`, the tests then run. Is there a reason skipsdist isn't used? How do these tests work for others?

Revision history for this message
Jason R. Coombs (jaraco) wrote :

I'll open a separate ticket for that.

Revision history for this message
Jason R. Coombs (jaraco) wrote :

> Note that there are tests which expect to be able to do 'import pkginfo', in order to then use the module for introspection. Relative import syntax doesn't support something like 'import .. as pkginfo', which would make it harder to do.

In the PR, I've proposed only updating the core package with relative import support, and allow the tests to continue to assume the package is installed in the root. That minimal change is sufficient to satisfy the vendoring needs of a package like setuptools.

Tres Seaver (tseaver)
Changed in pkginfo:
status: Confirmed → Fix Committed
Revision history for this message
Jason R. Coombs (jaraco) wrote :

Thanks mate!

Revision history for this message
Tres Seaver (tseaver) wrote :

Fix released in pkginfo 1.4.2 (2018-03-14).

Changed in pkginfo:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.