How to eliminate on part of a package?
![](https://secure.gravatar.com/avatar/885d5fc8213fece359b36f2bf53608cd.jpg?s=120&d=mm&r=g)
I recently ported a package to Python 3. The overall structure is pretty straightforward: top/ client/ module.py server/ server.py There's more to it, but that's enough for demonstration. I am retaining Python 2.7 compatibility on the client side, but have dispensed with that business on the server. (I run the server, not my users.) Accordingly, I would like the py27 version of the package to not have a subpackage named "server". I thought it would be easy peasy to just trim the server bits from setuptools.find_packages() in my setup.py file (I have 36.5.0.post20170921 of setuptools), something like this: packages = setuptools.find_packages() if sys.version_info.major < 3: packages.remove("top.server") In either case, I pass the resulting list as the packages argument of setuptools.setup(...). That doesn't work though. I get some sort of mish-mash where part of the top/server tree is copied, part not. I eventually get an error from a cp command, something about ".../server is not a directory". It would seem there is more I need to do, but nothing jumped out at me in the online documentation (http://setuptools.readthedocs.io/en/latest/setuptools.html). FWIW, while I see a section on that page titled, "New and Changed setup() Keywords", I didn't see a corresponding "Old and Unchanged setup() Keywords" there or up a level. Any pointers, hints, or suggestions appreciated... Skip Montanaro
![](https://secure.gravatar.com/avatar/a3193139ea494c45e63752504f5ff1f2.jpg?s=120&d=mm&r=g)
On 2018 Apr 25, at 16:02, Skip Montanaro <skip.montanaro@gmail.com> wrote:
I recently ported a package to Python 3. The overall structure is pretty straightforward:
top/ client/ module.py server/ server.py
There's more to it, but that's enough for demonstration. I am retaining Python 2.7 compatibility on the client side, but have dispensed with that business on the server. (I run the server, not my users.) Accordingly, I would like the py27 version of the package to not have a subpackage named "server".
I thought it would be easy peasy to just trim the server bits from setuptools.find_packages() in my setup.py file (I have 36.5.0.post20170921 of setuptools), something like this:
packages = setuptools.find_packages() if sys.version_info.major < 3: packages.remove("top.server")
In either case, I pass the resulting list as the packages argument of setuptools.setup(...).
That doesn't work though. I get some sort of mish-mash where part of the top/server tree is copied, part not. I eventually get an error from a cp command, something about ".../server is not a directory".
If by "top/server tree" you mean that there are more subpackages under top.server (not just a server.py file as your diagram shows), then you need to filter out all of those subpackages as well, e.g.: packages = setuptools.find_packages() if sys.version_info.major < 3: packages = [ pkg for pkg in packages if pkg != "top.server" and not pkg.startswith("top.server.") ]
![](https://secure.gravatar.com/avatar/885d5fc8213fece359b36f2bf53608cd.jpg?s=120&d=mm&r=g)
If by "top/server tree" you mean that there are more subpackages under top.server (not just a server.py file as your diagram shows), then you need to filter out all of those subpackages as well, e.g.:
packages = setuptools.find_packages() if sys.version_info.major < 3: packages = [ pkg for pkg in packages if pkg != "top.server" and not pkg.startswith("top.server.") ]
Thanks, yes, there is another subpackage within top/server, but I eliminated it as well. I was simplifying for the email. The raw find_packages() output looks like this: ['tests', 'top', 'tests.python', 'top.client', 'top.server', 'top.server.db'] I was excising the last two elements from the returned list, so the argument of the packages keyword looked like this: ['tests', 'top', 'tests.python', 'top.client'] Does the presence of 'top' in the list imply everything under it will be copied (I do want 'top', as that's the top level package, not just a directory in my repo.) I'll keep messing with it. Skip
![](https://secure.gravatar.com/avatar/5dde29b54a3f1b76b2541d0a4a9b232c.jpg?s=120&d=mm&r=g)
frankly, I'd give up n find_packages -- it's not that magic, it's just a convenience function so you don't need to hand-specify them. But in this case, you're doing something weird, so I"d just be explicit. Though what I'd probably really do is make the client and server completely separate packages. After all, you say your users only want the client side anyway. and if the server depends on the client (which I"d hope it doesn't!) then you can simply make it a dependency. -CHB On Wed, Apr 25, 2018 at 1:28 PM, Skip Montanaro <skip.montanaro@gmail.com> wrote:
If by "top/server tree" you mean that there are more subpackages under
top.server (not just a server.py file as your diagram shows), then you need to filter out all of those subpackages as well, e.g.:
packages = setuptools.find_packages() if sys.version_info.major < 3: packages = [ pkg for pkg in packages if pkg != "top.server" and not
pkg.startswith("top.server.")
]
Thanks, yes, there is another subpackage within top/server, but I eliminated it as well. I was simplifying for the email. The raw find_packages() output looks like this:
['tests', 'top', 'tests.python', 'top.client', 'top.server', 'top.server.db']
I was excising the last two elements from the returned list, so the argument of the packages keyword looked like this:
['tests', 'top', 'tests.python', 'top.client']
Does the presence of 'top' in the list imply everything under it will be copied (I do want 'top', as that's the top level package, not just a directory in my repo.)
I'll keep messing with it.
Skip _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
![](https://secure.gravatar.com/avatar/885d5fc8213fece359b36f2bf53608cd.jpg?s=120&d=mm&r=g)
Yeah, splitting client and server packages is on my to-do list. Was just hoping to keep Python2 users from shooting themselves in the foot with a server subpackage which wouldn't work. S On Thu, Apr 26, 2018 at 10:59 AM, Chris Barker <chris.barker@noaa.gov> wrote:
frankly, I'd give up n find_packages -- it's not that magic, it's just a convenience function so you don't need to hand-specify them.
But in this case, you're doing something weird, so I"d just be explicit.
Though what I'd probably really do is make the client and server completely separate packages. After all, you say your users only want the client side anyway.
and if the server depends on the client (which I"d hope it doesn't!) then you can simply make it a dependency.
-CHB
On Wed, Apr 25, 2018 at 1:28 PM, Skip Montanaro <skip.montanaro@gmail.com> wrote:
If by "top/server tree" you mean that there are more subpackages under top.server (not just a server.py file as your diagram shows), then you need to filter out all of those subpackages as well, e.g.:
packages = setuptools.find_packages() if sys.version_info.major < 3: packages = [ pkg for pkg in packages if pkg != "top.server" and not pkg.startswith("top.server.") ]
Thanks, yes, there is another subpackage within top/server, but I eliminated it as well. I was simplifying for the email. The raw find_packages() output looks like this:
['tests', 'top', 'tests.python', 'top.client', 'top.server', 'top.server.db']
I was excising the last two elements from the returned list, so the argument of the packages keyword looked like this:
['tests', 'top', 'tests.python', 'top.client']
Does the presence of 'top' in the list imply everything under it will be copied (I do want 'top', as that's the top level package, not just a directory in my repo.)
I'll keep messing with it.
Skip _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig
--
Christopher Barker, Ph.D. Oceanographer
Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
![](https://secure.gravatar.com/avatar/97c543aca1ac7bbcfb5279d0300c8330.jpg?s=120&d=mm&r=g)
If you're lazy, you could distribute the server package to everyone and just make sure that if someone tries to import it on python 2 then they get a useful error. On Thu, Apr 26, 2018 at 9:17 AM, Skip Montanaro <skip.montanaro@gmail.com> wrote:
Yeah, splitting client and server packages is on my to-do list. Was just hoping to keep Python2 users from shooting themselves in the foot with a server subpackage which wouldn't work.
S
On Thu, Apr 26, 2018 at 10:59 AM, Chris Barker <chris.barker@noaa.gov> wrote:
frankly, I'd give up n find_packages -- it's not that magic, it's just a convenience function so you don't need to hand-specify them.
But in this case, you're doing something weird, so I"d just be explicit.
Though what I'd probably really do is make the client and server completely separate packages. After all, you say your users only want the client side anyway.
and if the server depends on the client (which I"d hope it doesn't!) then you can simply make it a dependency.
-CHB
On Wed, Apr 25, 2018 at 1:28 PM, Skip Montanaro <skip.montanaro@gmail.com> wrote:
If by "top/server tree" you mean that there are more subpackages under top.server (not just a server.py file as your diagram shows), then you need to filter out all of those subpackages as well, e.g.:
packages = setuptools.find_packages() if sys.version_info.major < 3: packages = [ pkg for pkg in packages if pkg != "top.server" and not pkg.startswith("top.server.") ]
Thanks, yes, there is another subpackage within top/server, but I eliminated it as well. I was simplifying for the email. The raw find_packages() output looks like this:
['tests', 'top', 'tests.python', 'top.client', 'top.server', 'top.server.db']
I was excising the last two elements from the returned list, so the argument of the packages keyword looked like this:
['tests', 'top', 'tests.python', 'top.client']
Does the presence of 'top' in the list imply everything under it will be copied (I do want 'top', as that's the top level package, not just a directory in my repo.)
I'll keep messing with it.
Skip _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig
--
Christopher Barker, Ph.D. Oceanographer
Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig
-- Nathaniel J. Smith -- https://vorpus.org
![](https://secure.gravatar.com/avatar/885d5fc8213fece359b36f2bf53608cd.jpg?s=120&d=mm&r=g)
If you're lazy, you could distribute the server package to everyone and just make sure that if someone tries to import it on python 2 then they get a useful error.
Thanks, yes, that's a good suggestion. I suspect they'd get a SyntaxError today, but as another currently active thread suggested, that probably would be considered more confusing than useful. Skip
participants (4)
-
Chris Barker
-
John Thorvald Wodder II
-
Nathaniel Smith
-
Skip Montanaro