How can I test my python module without installing it - python

I'm in the process of redesigning/refactoring my Python quantum chemistry package (pyquante). One of the things I don't like about the existing release is that I have to install the package to run the test suite. That is, the test suite has statements like from PyQuante import SCF, and, of course, this PyQuante could refer to the installed version or a local version.
I know about virtualenv, and realize this is an option for me. But I was wondering whether anything else might be appropriate. In the past I've hacked sys.path for things like this, and have been told by better Python programmers that I shouldn't ever to this.
Does anyone have any suggestions for how I can do this? The point is that I want to test the current version of the code without installing it.
Thanks in advance for anyone who can see through my babbling and offer suggestions!

Create a proper package for your stuff and use
python setup.py develop
to make it a proper dev-package.
See:
https://stackoverflow.com/a/19048754/548039
http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode

I would honestly insist on using virtualenv, its designed for this exact reason in mind. very small overhead, and if you ever mess up just delete directory. I am sure as you grow, things won't be as simple as they are now for your current situation. Take it as an opportunity to learn.

Altering sys.path much in production environment may be unwise. Altering it for testing is usually OK.
If you don't want to tinker with the variable from sys, use an environment variable named PYTHONPATH, it's a clean and documented way.

Related

Why aren't my imports for Python working in VSCode?

First of all, I am new to both Python as well as the world of VSCode (recently moved over from Atom). I will also say that I am using an Early 2014 MacBook Air running macOS Catalina. I really do love VSCode! It's amazing in many ways, but this... this is just too unclear.
Okay, I have tried literally almost everything and I don't understand why my imports won't work! I have looked at the documentation on the issue on Github (I will say I may have something with the directory wrong there, referring to the docs). I have tried the "python.autoComplete.extraPaths": [], thing. I have tried changing my (virtual) environment and, of course, setting up a new one myself. I have tried setting "python.languageServer:" to Jedi and back to Microsoft. I can't even find the "python.jediEnabled: false" comment that everybody is telling me to uncomment.
Yet, my imports are still "unresolved (Microsoft language server)" or "not found (Terminal)" or "unable to be imported (Pylint)". It just makes me so angry and I don't understand what I've done wrong!
I've seen modules like pygame and requests work just fine on VSCode for many others (YouTube), yet mine has yet to work.
Can someone please tell me the secret that I don't apparently know? Thanks.
Update Post: My Virtual Environment is using my System Python rather than my Venv's Python
Thank you for everyone who has helped (so far). I am getting a lot closer to solving this. ^-^
They had removed "python.jediEnabled" setting instead of "python.languageServer", you can refer to here.
Maybe you haven't installed the package which you want to import, because you had used the wrong 'pip'. When you select the right environment, you need to activate it(Ctrl+Shift+`), otherwise, you'd use the wrong 'pip'. You can type 'pip --version' to check which 'pip' you are using. Then you can try to install the package you want to import.

How do I run python without an OS

I read somewhere you could run python without an OS. How would I do this? Would I need to compile it? Can I run it raw? And if I did need to compile it, what tool would I use and what format would I compile it to?
As far as I know there's not really any way to do this easily but I could be wrong. There are "portable" versions of python but these are operating system dependent. I think what you're referencing is some guys at PyCon managed to run python from the GRUB Bootloader. Your best bet would be installing some minimalist Linux distribution, with essentially only Python and some core packages required to run. The problem is that there's a lot of types of hardware out there, all with their own drivers and assembly language. Python can work as a low level language when you need it to but it seems like configuration would be a nightmare. I haven't looked into it super thoroughly but it seems difficult and impractical. Having an OS above python gives you access to the package managers IDEs and compilier options that make python worth using.
yea that's one of the options, pretty much all the "light" distros will be similar, if you want more to try out try here. Not sure why you're worried about speed though, if you're having speed issues it's far more likely to be the IDE you're using or your code bogging down the computer, not any sort of compiler issues.

How to manage multiple ironpython versions?

I have the following issue:
I have some software that installs a particular version of IronPython to GAC. But I need to install a newer version of IronPython without affecting GAC. Hence the need for somehow using pyenv on windows with IronPython.
I am not from a programming background, more of a brick and mortar background, so please bear with me here.
[pyenv-win][1] doesn't support IronPython yet, and given my background, I have no idea how to modify a GIT repository and then install it (I'm trying to learn all that, but first I need to set this environment up, so that I don't mess things up, its a vicious cycle :P).
I downloaded a copy of the code and I was looking into how it is addressing different python versions.
It seems in [this file][2]
there are variables:
mirror, mirrorEnvPath, listEnv
that point to location of the exe that pyenv-win is using to install and maintain python version
So I somehow need to add an iron python mirror location and another array to the list that reads something like this
ironmirror = "https://github.com/IronLanguages/ironpython2/releases/download"
and add a line to listEnv
Array("ipy-2.7.9", ironmirror&"/ipy-2.7.9/", "IronPython-2.7.9.msi", "x64")_
That's how far I can get. If someone could help me put all this together, that would be nice. I have no idea how to run this modified code from my local hard drive. I would also like to somehow add this functionality to the package on GitHub as well so that others can use the same. Also, I am not sure if I am allowed to look into the code that others have shared and modify it. This is a new world for me. Apologies if that's the case.
Any help is appreciated.
[1]: https://github.com/pyenv-win/pyenv-win
[2]: https://github.com/pyenv-win/pyenv-win/blob/master/pyenv-win/libexec/pyenv-install.vbs

What is the best way to get Python auto-completions/intellisense in Vim dynamically?

I have looked at pydiction, pysmell and vim-ipython. Both pydiction and pysmell require generating the index before we can use it, and vim-ipython requires loading back and forth before the autocompletion works. However, none of them give the on-the-fly auto-completion working in different virtualenv, like what Aptana can do.
Would an experienced Python-vimmer let us know please?
Try this: https://github.com/klen/python-mode
Dynamic omnicompletion from Rope and many other features.
I really like neocomplcache it's an ultimate completion system for vim.
For python it uses internal vim's python omni-completion which is pretty good doing it's job.
You should give it a try.

organizing many python scripts, in a large corporate environment

We've been doing a fair amount of Python scripting, and now we have a
directory with almost a hundred loosely related scripts. It's
obviously time to organize this, but there's a problem. These scripts
import freely from each other and although code reuse is generally a
good thing it makes it quite complicated to organize them into
directories.
There's a few things that you should know about our corporate environment:
I don't have access to the users'
environment. Editing the PYTHONPATH
is out, unless it happens in the
script itself.
Users don't install things. Systems
are expected to be already
installed and working on, so setup.py
is not a solution unless I can run it once for all users.
I'm quite willing to edit my import statements and do some minor refactoring, but the solutions I see currently require me to divide all the code strictly between "user runnable scripts" and "libraries", which isn't feasible, considering the amount of code.
Has anyone out there solved a similar problem? Are you happy with it?
--Buck
Another way to state the same question:
When looking at google code search, this kind of code is rampant (below). Is everyone happy with this? Is there a good alternative?
sys.path.insert(0, os.path.dirname(os.path.dirname(
os.path.dirname(os.path.abspath(__file__))
)))

Categories