Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102641
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2016-02-07 16:38 -0800 |
| References | <e324ce71-1f90-4727-b7e8-eaa13c4ecc08@googlegroups.com> <CAPTjJmr6771LUFCa5fNwUkLwfBzqGu83anruax705fzhtXQ1hQ@mail.gmail.com> <mailman.61.1454826898.2317.python-list@python.org> <51b52cf3-0b0a-451e-a232-d9a671f7cd20@googlegroups.com> <mailman.75.1454861364.2317.python-list@python.org> |
| Message-ID | <14095c33-b5d4-419f-aaf4-e6f293d0cbf9@googlegroups.com> (permalink) |
| Subject | Re: Python's import situation has driven me to the brink of imsanity |
| From | dimva13@gmail.com |
Running python setup.py develop doesn't work, it gives me this error: error: invalid command 'develop' Running pip install -e . does work. This is somewhat reasonable, and I think may work for my purposes, but it has the following drawbacks: - you have to create a fake package with a fake version, and all the setup.py boilerplate - to get to your python files, you have to go through an additional subdirectory (ex: project_name/project_name/package.py) - you have to remember to run pip install -e . before you can use anything inside the project - you should be using a virtualenv (I am), otherwise things can get messy if you have these fake projects installed in a global location All in all, this seems like a hack - I'm creating a fake package with a fake version just so I can do imports sanely. Still less of a hack than imsanity, though. Thanks for the advice! I just wish it was better documented and easier to find. I have several years of professional python experience at 3 different companies, and I've never seen this solution anywhere - all the companies solved it by setting PYTHONPATH to the base directory. I'll try to spread the word. On Sunday, February 7, 2016 at 11:09:35 AM UTC-5, Kevin Conway wrote: > You can use 'setup.py develop' or 'pip install -e' to install your package > in editable mode. It makes it so your local code is used. Modifications are > seen immediately. > > On Sun, Feb 7, 2016, 08:16 <dimva13@gmail.com> wrote: > > > I see that this would work once you've installed the package, but how do > > you develop it? Say you are working on a change that modifies both email.py > > and reports.py. Do you run setup.py every time you make a change in > > email.py? > > > > On Sunday, February 7, 2016 at 1:35:15 AM UTC-5, Kevin Conway wrote: > > > > My question is: is this crazy? Please tell me there's a better way and > > I > > > just wasted my time creating this package. > > > > > > There is a better way and you have wasted your time creating this > > package. > > > > > > I hear your problem statement as asking two questions. The first is: What > > > is the right way to include executable content in my Python project? The > > > second is: How do I expose executable content from a Python project? > > > > > > As to the first question, from your project README: > > > > Say you have a python project (not a package), with the following > > > structure: > > > > > > All Python code that you want to install and make available in any form, > > > import or executable, _must_ be contained within a Python package. > > > Organizing Python code in any way other than Python packages will result > > in > > > the challenges you have described. The correct way to include executable > > > content is to place the Python code within the package structure. It > > should > > > not be put in other directories within the repository root. > > > > > > As to the second question, once all Python code is contained within a > > > package that can be installed you can use setuptools entry points to > > expose > > > the executable code. The setup() function from setuptools that is used to > > > create setup.py files has an argument called 'entry_points' that allows > > you > > > to expose executable content over the command line. See [1] and [2] for > > > more details. > > > > > > Feel free to reach out to me off-list if you have a specific project you > > > need advice on. The rules for organizing and packaging Python code aren't > > > complex but they tend to cause new Python developers to stumble at > > first. A > > > general rule I give everyone when talking about packaging or importing > > > code: If you have to modify sys.path to makes something work then you > > have > > > most certainly made a mistake. > > > > > > [1] > > > > > https://pythonhosted.org/setuptools/setuptools.html#automatic-script-creation > > > [2] > > > > > http://python-packaging.readthedocs.org/en/latest/command-line-scripts.html#the-console-scripts-entry-point > > > > > > > > > On Sat, Feb 6, 2016 at 8:54 PM Chris Angelico <rosuav@gmail.com> wrote: > > > > > > > On Sun, Feb 7, 2016 at 1:47 PM, <dimva13@gmail.com> wrote: > > > > > Imsanity allows you to make imports usable (not ideal, but at least > > > > usable) for python projects without having to manage PYTHONPATHs or do > > > > whacky stuff like running files with python -m or put even whackier > > > > boilerplate at the top of every file. And all it requires is 'import > > > > imsanity' at the top of every file. You can put it in a macro or even > > just > > > > type it because it's short and easy to remember. > > > > > > > > > > My question is: is this crazy? Please tell me there's a better way > > and I > > > > just wasted my time creating this package. There's nothing I'd like to > > hear > > > > more. > > > > > > > > Well, anything that makes you type "import imsanity" at the top of > > > > every script MUST be crazy. :) I don't know about the actual > > > > content/purpose though. Good luck with it! > > > > > > > > ChrisA > > > > -- > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > >
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python's import situation has driven me to the brink of imsanity dimva13@gmail.com - 2016-02-06 18:47 -0800
Re: Python's import situation has driven me to the brink of imsanity Chris Angelico <rosuav@gmail.com> - 2016-02-07 13:52 +1100
Re: Python's import situation has driven me to the brink of imsanity Kevin Conway <kevinjacobconway@gmail.com> - 2016-02-07 06:34 +0000
Re: Python's import situation has driven me to the brink of imsanity dimva13@gmail.com - 2016-02-07 06:13 -0800
Re: Python's import situation has driven me to the brink of imsanity Kevin Conway <kevinjacobconway@gmail.com> - 2016-02-07 16:09 +0000
Re: Python's import situation has driven me to the brink of imsanity dimva13@gmail.com - 2016-02-07 16:38 -0800
Re: Python's import situation has driven me to the brink of imsanity Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-02-10 00:31 +0000
Re: Python's import situation has driven me to the brink of imsanity Sivan Greenberg <sivan@vitakka.co> - 2016-02-10 21:05 +0200
Re: Python's import situation has driven me to the brink of imsanity Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-02-10 21:16 +0000
Re: Python's import situation has driven me to the brink of imsanity Sivan Greenberg <sivan@vitakka.co> - 2016-02-07 18:15 +0200
Re: Python's import situation has driven me to the brink of imsanity Sivan Greenberg <sivan@vitakka.co> - 2016-02-07 13:43 +0200
csiph-web