-
Notifications
You must be signed in to change notification settings - Fork 932
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
New tutorials: make a package #203
Comments
While writing the description for #204, I realized this: the reader should decide what this package is named. If they use it in the next section, it probably needs to not have the same name as everyone else's test package or else confusion will likely follow. |
@ddbeck Hi! I'd like to tackle this one. The plan is:
|
@moigagoo That looks like a great start to me. I can't wait to see a first draft! About the editable thing, this was my thinking: it's one of those things that comes up again and again in various Python docs, blog posts, etc. I'd like the reader to be able to recognize and understand its use, even if it has limitations (just because it is a common practice). It just seemed like a natural fit here, since we'll have the reader work with package source anyway. But if you have an idea about how else we might cover it, I'd be interested in hearing about it! |
@ddbeck I think it's more natural for a beginner to install packages locally into a virtualenv with If you are in a real hurry and you really hate to reinstall packages after modifying the source code, use |
@moigagoo OK, you've convinced me. Don't mention the editable stuff here at all and I'll think up some other way to deal with this particular tacit knowledge problem. Thanks! |
I can provide context on the "Why does -e use a .pth file rather than symlinks?" question:
However, I also agree with @moigagoo - even using editable mode correctly to speed your edit/run cycles back up to where they are if you're not worried about package based distribution can still get you into all sorts of interesting potential problems with sys.path manipulation and module reloading, so there's value in avoiding it until you've developed some solid intuitions about how the import system works in the presence of code that is changing on disk. When editable mode does get introduced, it would likely make the most sense to do it in the context of an auto-reloading local web server like the development servers in Flask and Django (as that avoids the need to introduce manual module reloading at the interactive prompt). |
@ncoghlan Thanks a lot for the clarification! It all makes sense now. I'm currently half time on Windows, half on Mac, and I use symlinks to connect subpackages during development everywhere, works like charm. It is indeed silly of Microsoft to make symlinks an admin-only feature. |
Hi, I realize this is a recent issue - but is there any progress? I just started porting/hacking/forking a little cli-tool (basically moving it to python3, use docopt, and wrap it with a setup.py so it's easy to pip install in a venv). And on reading http://python-packaging-user-guide.readthedocs.org/en/latest/distributing/ in particular: http://python-packaging-user-guide.readthedocs.org/en/latest/single_source_version/#single-sourcing-the-version I found that it might be nice to have the version in a VERSION file. And all that's needed then is to make sure that the VERSION-file is installed along with the package...[1] So far so good, except there's a lot of contradictory information on how to actually do that. Basically I'd like to be able to (tell people to): pyvenv venv
./venv/bin/pip install -U pip setuptools
./venv/bin/pip install git+https://github.com/user/package
./venv/bin/package #yay! But then I don't (currently) get my VERSION file (or other resources, obviously). I managed to get it to work with FWIW the incomplete code/refactoring now lives here: https://github.com/e12e/b2/ I'm not opposed to eventually uploading that to the cheese shop (although in this particular case, it would probably make sense to coordinate with upstream, this fork is more of a personal project). What I could really need now, is a simple "This is how you make a python package with resource files that can easily be installed by pip in a virtualenv, and is expected to continue to work for python3. Bonus points if there's an appendix for code that runs on python2 and/or pypy as well. It might seem daunting, but I think the howistart-article for Ruby might be a great source of inspiration: http://howistart.org/posts/ruby/1 [1] I'm fully aware that using a single VERSION file might not be the best idea, but then I suppose someone(tm) should file a bug/update the official docs... |
@e12e The rewriting progress is still too small to share, I'm afraid. However, I won't cover this topic in the tutorial anyway—it's way out of the beginner's scope. Still, here's how I support multiple Python versions while keeping the version in one place. Maybe you'll find my approach useful. I'll illustrate the approach with my project Cliar: https://bitbucket.org/moigagoo/cliar/src/ Separate Source for Different PythonsI keep sources for different versions of Python in separate places: cliar/py2 and cliar/py3. Instead of a single source file with lots of On the downside, I have to implement the same feature twice. In the simplest case, I just copy-paste the code from one version to another. This is not as bad as it sounds: I'd have to check and possibly rewrite the implementation anyway. With this workflow, I'm forced to make sure I correctly implemented the feature for both versions. Switch Between the Sources GloballyThe sources for each Python version are subpackages in my package. I include both in the distribution with When the package is used, I check the Python version and import the proper source: https://bitbucket.org/moigagoo/cliar/src/a739240126ff2b750d66bb5b9617655e06da2975/cliar/__init__.py?at=default&fileviewer=file-view-default With this approach, when I release a new version, I update the version number only in setup.py and only once. There a single common changelog, too. Another advantage is that if I have to support more Python versions, say, 3.2, I'll just duplicate the code into py32 and slightly update the version check. The next step would be moving the meta data into cliar/init.py and importing it in setup.py. I do a similar thing in this package: https://bitbucket.org/moigagoo/sloth-ci/src/42406ee83e0a1fb3a49cfa3c0e732a271329ae6e/setup.py?at=default&fileviewer=file-view-default#setup.py-14 |
@moigagoo Thank you for your reply! I might have been unclear, I'm not (at this time) interested in supporting more than one version of python. I'm just trying to make sure my VERSION-file is installed when I pip-install my package. As it is, |
@e12e Sorry, I misunderstood you. The supported way to include data files in your package is with
For example, here's how I ship robots.txt with one of my packages: https://bitbucket.org/moigagoo/sloth-ci-extensions/src/d725682b4de28f1950d6b93220d6b5baa572cecb/robots_txt/setup.py?at=default&fileviewer=file-view-default#setup.py-19 |
I think it would also make sense to discuss in the packaging tutorial sample project how to structure the I recently tried making my own package from the official tutorial and ran into problems getting the For instance, the sample project seems to set up its imports in the
However, in my experience, not many Python packages are set up this way, and it would be helpful to give people the option of setting up their imports so that they can behave in the following manner:
For instance, as in:
In addition, the documentation doesn't mention other things that might go in the
I think some more guidance about what options are available for structuring the imports in If this isn't the appropriate place for this, please feel free to move this to a new issue. |
That's good feedback, @lgh2. I think at minimum we should link off to the Python doc's description of packages and imports. |
I agree that adding a link to the Python docs about how packages and imports work would be helpful, and it would make sense to link to it and not try to re-create it ourselves. However, I briefly looked in the Python documentation for distutils and they don't seem to provide the kind of information I was looking for about |
I meant more of this: https://docs.python.org/3/tutorial/modules.html But definitely useful for us to provide guidance on using |
I think having an explicit guide in PyPUG for this would make sense (we
have one for namespace packages, after all - we just took the design of
self-contained packages for granted, even though it's a surprisingly
complex topic, especially if you want to keep the internal package
structure from leaking into things like pickle files).
I don't believe it's tutorial level material though - at the tutorial
level, I'm still strongly inclined to favour "Leave your init files empty
or omit them entirely". As an example of how symbol re-export can cause
problems, reloading submodules of a parent package that exports submodule
attributes as package level attributes is one of the easiest ways to end up
with two different copies of a module attribute. That means you have to
reload the parent package as well to ensure both name bindings get updated.
|
Based on what you said in your second paragraph, @ncoghlan, and how complex the topic seems to be, I agree that it would make sense to split out the discussion of the |
(For more information about this issue, please see #194).
We need a short section to follow the section about making a distribution package (see #202) (i.e., as its own file) that will guide the reader through making a bare module or (import) package ready for installing with
pip
(and, in the following section, publishing on PyPI). The section should satisfy these goals:setup.py
file that usessetup()
README
file, a license, and using a PEP 440-compliant versioning scheme (link generously to resources that cover these things in detail)show how to install the package in editable/develop modePlease note that this section should not assume the reader already has modules to package (so provide some short sample code where applicable). Also, don't cover publishing the package to PyPI or elsewhere—that's going to be covered in the next tutorial section.
When opening pull requests for this issue, please submit to the
develop
branch. If you have questions that concern contributing more generally, please use issue #194. Otherwise, feel free to comment with questions or feedback. Thanks!The text was updated successfully, but these errors were encountered: