-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Read the existing MANIFEST.in file for files to ignore. #19
Read the existing MANIFEST.in file for files to ignore. #19
Conversation
Use this to support ignoring patterns that are in MANIFEST.in with the 'exclude' keyword.
Strange: the above comment by coveralls says the coverage increased, but I got a mail from coveralls and that said: "Coverage remained the same when pulling 76e42db on mauritsvanrees:maurits-read-manifest into c8e785a on mgedmin:master." The percentage is 78 in both cases. I had this difference with a previous pull request too. Oh well. |
# XXX modifies global state, which is kind of evil | ||
if not os.path.isfile('MANIFEST.in'): | ||
return | ||
contents = open('MANIFEST.in').read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the with
statement to avoid ResourceWarnings on Python 3.x and leaking file descriptors on PyPy.
Thank you for the pull request. I'd like to see some examples of projects that have files contained in the version control system that must be excluded from source distributions. Can you satisfy my curiosity? |
This avoids ResourceWarnings on Python 3.x and leaking file descriptors on PyPy.
'split' already ignores leading and trailing whitespace.
Remove leading whitespace programmatically with textwrap.dedent.
Thanks for your detailed feedback on the code. I have pushed the improvements. The example that caused me to have a look at this, is plone.app.contenttypes. When I run check-manifest in a clone, I get this output:
There is a MANIFEST.in already. It has no relevant excludes yet, but with the code in this pull request I could add these lines to the manifest and then check-manifest no longer complains:
An argument against this would be that these are files that are not normally included by Python, so it may be better to tell check-manifest to ignore these by adding a few lines to setup.cfg. But someone may have installed the setuptools-git package and then these files would be included. Perhaps a better example is that some packages prune the tests directory, for example Products.TinyMCE. Without the code from this pull request, check-manifest complains:
|
# Regular expressions for filename to ignore. This is useful for | ||
# filename patterns where the '*' part must not search in | ||
# directories. | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The closing ]
should be unindented.
I believe pep8 warns about this, but even if it doesn't, let's keep it consistent with the rest of the file.
As for your project examples, I think all those are source files that should be included in source distributions. Tests are part of the source code! Build configuration is something you need if you want to work on a package. Even .travis.yml, while functionally useless in a tarball, can act as documentation for people telling them how to run the tests. |
It seems tabs are accepted in the manifest. We now split each line to check for a command (exclude, prune, etc) and arguments.
I am done with the fixes. I actually never exclude the tests in my packages, but I can imagine that in some projects people think they bloat the package too much. And lots of source code packages have the same Anyway, the pull request does not advocate excluding or pruning stuff, but only helps in not letting check-manifest complain about missing those files, but I think you got that point. |
elif cmd == 'global-exclude': | ||
ignore.extend(rest.split()) | ||
elif cmd == 'recursive-exclude': | ||
dirname, patterns = rest.split(None, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can raise ValueError if you've got a malformed MANIFEST.in with recursive-exclude dir
but no patterns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I was thinking: if this is wrong then python itself will complain when trying to use the manifest.
Well, python prints a warning but happily continues:
warning: manifest_maker: MANIFEST.in, line 6: 'recursive-exclude' expects <dir> <pattern1> <pattern2> ...
I have changed to code to print the same warning (without line number) when we get a ValueError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I have added a test for this. This means that running the tests will print a warning. Not sure if that is a thing to avoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer tests to pass without warnings or in fact any extra output to stdout/stderr. This should be easy to arrange by adding a
with warnings.catch_warnings():
self.assertEqual(function_that_causes_the_warning(...), ...)
We could even test the spelling of the warning with
with warnings.catch_warnings(record=True) as w:
self.assertEqual(function_that_causes_the_warning(...), ...)
self.assertEqual(w, ['...'])
but I'm not convinced it's worth the effort.
Thanks for your continuing constructive feedback. I have pushed the commits based on your remarks. I am now running tox with all four supported pythons and the tests all pass. Should you finally decide not to accept this pull request, I have at least learned a lot about |
Incidentally I came up with a really good use-case for the 'exclude' feature: buildout. It has two packages in one source tree (zc.buildout and zc.recipe.egg), with separate setup.py files and everything. Ironically, its MANIFEST.in does not use the exclude feature. |
I keep wondering about one thing: if one has a setuptools version control system plugin that tells it to include some file, but the MANIFEST in tells it to exclude the same file, what will setuptools do? I hope it'll exclude that file, in which case I have no further reservations for merging this PR. Well, except those two small fixes I asked about: shutting up warnings and handling Eh, we can deal with those issues when the bugs get filed. I'll wait for updates for warnings and prefix*, then merge this. Or if you're tired of complying with my unreasonable demands, I can merge and do the fixes myself. |
I notice one nasty thing that seems really unexpected in MANIFEST.in. If for example in plone.app.contenttypes I add this line I expect that the sdist will exclude
That is correct, but a file like With the current status of this pull request, check-manifest complains that |
headdesk distutils |
Ignore warnings in one known spot in the tests. This keeps the test output clean.
Quoting you: "I keep wondering about one thing: if one has a setuptools version control system plugin that tells it to include some file, but the MANIFEST in tells it to exclude the same file, what will setuptools do?" It excludes them. If I use a clean python without setuptools plugins and use it to create an sdist of a plone package without MANIFEST.in, it will not contain for example the zcml files. If I install The warnings are ignored now in the tests, which means I had to change the existing warning function, because it simply printed to I'm not tired of unreasonable or reasonable demands yet. ;-) |
Gah! Sorry, I completely forgot that there was an existing |
Read the existing MANIFEST.in file for files to ignore.
0.17 is released I see. Thanks! |
I guess this accomplishes what I originally wanted in #10. Thanks! |
By the way, if you ever want to get rid of the |
The existing MANIFEST.in can have been setup to ignore some files or complete directories. check-manifest should not complain that those are in version control but not in the sdist.
If MANIFEST.in exists, we read it and add relevant entries to the IGNORE definition. To properly support the
exclude
directive I needed to add an IGNORE_REGEXPS definition.Tests pass on the two supported pythons that I have: 2.7 and 3.3.