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

[REQUEST] Make it work within a virtualenv #106

Closed
faassen opened this issue Sep 7, 2020 · 6 comments
Closed

[REQUEST] Make it work within a virtualenv #106

faassen opened this issue Sep 7, 2020 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@faassen
Copy link

faassen commented Sep 7, 2020

Is your feature request related to a problem? Please describe.
I tried to install this in a virtualenv, like I install Python packages in general. I could, but it crashed with an error:

Traceback (most recent call last):
  File "/home/faassen/.virtualenvs/pytools3/bin/bpytop", line 5, in <module>
    from bpytop import main
  File "/home/faassen/.virtualenvs/pytools3/lib/python3.8/site-packages/bpytop.py", line 205, in <module>
    for td in site.getsitepackages() + [site.getusersitepackages()]:
AttributeError: module 'site' has no attribute 'getsitepackages'

The reason is because virtualenv don't (and I think cannot) support getsitepackages:

pypa/virtualenv#737

Describe the solution you'd like

I would like bpytop to work in a virtualenv. From the code it looks like the sitepackages are consulted to figure out to load up some kind of theme. Perhaps using a setuptools entry point would be a more compatible way to pick up theme packages that doesn't require this low level access?

https://setuptools.readthedocs.io/en/latest/setuptools.html#dynamic-discovery-of-services-and-plugins

Describe alternatives you've considered

I considered installing it in my system Python directly but I try to keep this clean of custom installations as much as possible.

@faassen faassen added the enhancement New feature or request label Sep 7, 2020
@aristocratos
Copy link
Owner

aristocratos commented Sep 7, 2020

@faassen
I can't reproduce this, tested with both virtualenv and venv on multiple virtual machines. Do you have latest version of virtualenv?

Both site.getsitepackages() and site.getusersitepackages() seem to be working fine on latest version.

@aristocratos
Copy link
Owner

aristocratos commented Sep 7, 2020

From the code it looks like the sitepackages are consulted to figure out to load up some kind of theme.

It places the theme folder in the site-packages folder at install. So getsitepackages is used to find the folder.

Perhaps using a setuptools entry point would be a more compatible way to pick up theme packages that doesn't require this low level access?

I'm not sure how to set that up since I need the absolute path to list the files and read the *.theme files. And changing the format of the theme files to be loaded as resources is not an option if they are gonna stay compatible between bashtop and bpytop.

If you know a good solution let me know or better yet, create a PR if you feel up for it.

@faassen
Copy link
Author

faassen commented Sep 7, 2020

It's been a while since I messed around with this and I don't quite know how your theme system works. I think the resource system of pkg_resources fits better than entry points.

https://setuptools.readthedocs.io/en/latest/pkg_resources.html#resourcemanager-api

should help, but it's rather intimidating as documentation.

But there's a simple API too. I think something like:

theme_data = pkg_resources.resource_string('mythemespackage', "theme.something")

would load the theme.something file from "mythemespackage", assuming it's been installed as a Python package.

See also resource_listdir to get all files in a directory in a distribution (installed Python package).

@aristocratos
Copy link
Owner

I realized it might actually work just using os.path.dirname(__file__), since if it's installed with pip the main file bpytop.py will be located in the same directory as bpytop-themes folder.

@aristocratos
Copy link
Owner

That seems to be working. Will be in next update.

@aristocratos
Copy link
Owner

@faassen
Should be fixed in v1.0.26

Reopen this otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants