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

Fix for #693 #696

Merged
merged 4 commits into from
Mar 17, 2014
Merged

Fix for #693 #696

merged 4 commits into from
Mar 17, 2014

Conversation

jerynmathew
Copy link
Contributor

This fix will now accept .pyc files for config input from command line.
ie, gunicorn -c config.pyc app:main

This will greatly help production environments where python source are never shipped, only compiled ones.

  - Made changes to read and fetch code object from .pyc files.
  - Error message "Non-ASCII character '\xf3' in file" is resolved.
  - Override older behavior of execfile_ with one with pyc patch
@@ -286,6 +286,50 @@ def StringIO(buf=''):
_add_doc(u, """Text literal""")


def _check_if_pyc(fname):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a lot more readable if we used splitext

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, maybe we can use find_module and this wouldn't even need to check the suffix.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like imp.load_module is also able to load compiled files so a combination of both should probably work. @jerynmathew did you tried to use them already?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @benoitc,
Sorry for the delay, busy at my day job.
I tested the imp.load_module(); it returns a module-object type.
The exec (or execfile) expects string, file or code-object type. Hence I'm not sure imp.load_module() is the right choice here, because once we obtain the module object from imp.load_module(), we still need to convert it to code object (which is done as shown in my code).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I recommended only find_module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a commit again. Hope this is alright!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think that is easier to read. I particularly like the constants
instead of the file extensions.

It's unlikely to be a big problem in this case, but it would be good style
to bring the read call up above the conditional, wrap it in a try/finally
and close the file in the finally block.

As is, you duplicate the read and close call and don't guarantee to close
if there's an exception.

Could you make that change and then I'll merge this?

In gunicorn/six.py:

@@ -286,6 +286,50 @@ def StringIO(buf=''):
_add_doc(u, """Text literal""")

+def _check_if_pyc(fname):

I made a commit again. Hope this is alright!


Reply to this email directly or view it on
GitHubhttps://github.com//pull/696/files#r10633817
.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Sorry about the rookie mistake.
All done now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem at all! Thanks for the update.

	- Remodeled the logic to use imp module to validate the python
	  gunicorn config file
	- Added changes to file read, as per review comments
tilgovi added a commit that referenced this pull request Mar 17, 2014
@tilgovi tilgovi merged commit 21ea843 into benoitc:master Mar 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants