Advice on Python build tools
Hi Looking at the wiki list of build tools https://wiki.python.org/moin/ConfigurationAndBuildTools Has anyone much experience in build tools as i have no preference or experience to lean on. Off descriptions only i would choose invoke. My requirements, simply i want to learn and build a simple static website generator. Many i am not liking design of or are overkill so its a good opportunity to learn, logya is a good starting point for what i think a good python static generator should be. Second i want to use Jade templates (js) as i think they are more pythonic than jinja and mako so being able to have mixed js and python support would be needed. Thoughts? Sayth -- https://mail.python.org/mailman/listinfo/python-list
Re: OT: Anyone here use the ConEmu console app?
Win 10 will have full bash provided by project between Ubuntu and MS so that's pretty cool Sayth -- https://mail.python.org/mailman/listinfo/python-list
Re: Advice on Python build tools
On Tuesday, 12 April 2016 19:48:43 UTC+10, Sayth Renshaw wrote: > Hi > > Looking at the wiki list of build tools > https://wiki.python.org/moin/ConfigurationAndBuildTools > > Has anyone much experience in build tools as i have no preference or > experience to lean on. > > Off descriptions only i would choose invoke. > > My requirements, simply i want to learn and build a simple static website > generator. Many i am not liking design of or are overkill so its a good > opportunity to learn, logya is a good starting point for what i think a good > python static generator should be. > > Second i want to use Jade templates (js) as i think they are more pythonic > than jinja and mako so being able to have mixed js and python support would > be needed. > > Thoughts? > > Sayth Just to add if would affect your opinion I will be using Python 3 only so no py2 dependency and this is the project logya I was referring to https://github.com/yaph/logya Sayth -- https://mail.python.org/mailman/listinfo/python-list
Re: Advice on Python build tools
Sayth Renshaw writes: > Looking at the wiki list of build tools > https://wiki.python.org/moin/ConfigurationAndBuildTools > > Has anyone much experience in build tools as i have no preference or > experience to lean on. I'm quite fine with GNU Make, so haven't really tried a lot of others. I am fascinated by what I've seen of Meson http://mesonbuild.com/>. It claims to behave very well with operating system package managers, which if true makes it unique among Python-based build systems. -- \ “It is … incumbent upon us to recognize that it is | `\inappropriate for religion to play any role in issues of state | _o__)[of] a modern democracy.” —Lawrence M. Krauss, 2012-05-28 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
sys.exit(1) vs raise SystemExit vs raise
I m on python 2.7 and Linux , I have a simple code need suggestion if I
I could replace sys.exit(1) with raise SystemExit .
==Actual code==
def main():
try:
create_logdir()
create_dataset()
unittest.main()
except Exception as e:
logging.exception(e)
sys.exit(EXIT_STATUS_ERROR)
if __name__ == '__main__':
main()
==Changed Code==
def main():
try:
create_logdir()
create_dataset()
unittest.main()
except Exception as e:
logging.exception(e)
raise SystemExit
if __name__ == '__main__':
main()
2. All the functions in try block have exception bubbled out using raise
Example for create_logdir() here is the function definition
def create_logdir():
try:
os.makedirs(LOG_DIR)
except OSError as e:
sys.stderr.write("Failed to create log directory...Exiting !!!")
raise
print "log file: " + corrupt_log
return True
def main():
try:
create_logdir()
except Exception as e:
logging.exception(e)
raise SystemExit
(a) In case if create_logdir() fails we will get the below error ,is
this fine or do I need to improve this code.
Failed to create log directory...Exiting !!!ERROR:root:[Errno 17] File
exists: '/var/log/dummy'
Traceback (most recent call last):
File "corrupt_test.py", line 245, in main
create_logdir()
File "corrupt_test.py", line 53, in create_logdir
os.makedirs(LOG_DIR)
File "/usr/local/lib/python2.7/os.py", line 157, in makedirs
OSError: [Errno 17] File exists: '/var/log/dummy'
3. Can I have just raise , instead of SystemExit or sys.exit(1) . This
looks wrong to me
def main():
try:
create_logdir()
except Exception as e
logging.exception(e)
raise
Regards,
Ganesh
--
https://mail.python.org/mailman/listinfo/python-list
Re: sys.exit(1) vs raise SystemExit vs raise
On Tue, Apr 12, 2016, at 08:50, Ganesh Pal wrote: > I m on python 2.7 and Linux , I have a simple code need suggestion if > I > I could replace sys.exit(1) with raise SystemExit . No; raise SystemExit is equivalent to sys.exit(0); you would need raise SystemExit(1) to return 1. Why do you want to do this, though? What do you think you gain from it? -- https://mail.python.org/mailman/listinfo/python-list
Re: [Twisted-Python] Twisted 16.1 Release Announcement
Hi, Are there any plans to get back 32-bit wheels for Twisted? -- https://mail.python.org/mailman/listinfo/python-list
Strange urlopen error
Hi,
I have recently run into an issue at work where we are having intermittent
problems with an internal website not loading due to an interrupted system
call. We are using urllib2 to access the website. I can't share the exact code,
but here is basically how we do it:
payload = {'userName': user_name,
'emailAddress': email_address,
'password': password}
headers = {'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token}
values = json.dumps(payload)
req = urllib2.Request(url, values, headers)
try:
response = urllib2.urlopen(req, timeout=30)
break
except IOError, e:
if e.errno != errno.EINTR:
print e.errno
raise
We log the errono and the raised exception. The exception is:
IOError:
And the errno is None. I expected it to be 4.
Is there a better way to catch this error in Python 2? I am aware of PEP475,
but we cannot upgrade to Python 3 right now.
Thanks,
Mike
--
https://mail.python.org/mailman/listinfo/python-list
Re: sys.exit(1) vs raise SystemExit vs raise
> > > No; raise SystemExit is equivalent to sys.exit(0); you would need raise > SystemExit(1) to return 1. > Thanks will replace SystemExit with SystemExit(1) . > Why do you want to do this, though? What do you think you gain from it? > Iam trying to have a single exit point for many functions: example create_logdir() , create_dataset() and unittest.main() will bubble out an exception using raise I would want to terminate the program when this happens . Do you see any problem if *raise *SystemExit(1) is used in the except block ? *def *main(): *try*: create_logdir() create_dataset() unittest.main() *except *Exception *as *e: logging.exception(e) *raise *SystemExit(1) I see the below error only on pdb so thinking whats wrong in the above code ? “*Exception AttributeError: "'NoneType' object has no attribute 'path'" in ignored “ * (Pdb) n SystemExit: SystemExit() > /var/crash/local_qa/bin/corrupt_test.py(253)() -> main() (Pdb) n --Return-- > /var/crash/local_qa/bin/corrupt_test.py(253)()->None -> main() (Pdb) n Exception AttributeError: "'NoneType' object has no attribute 'path'" in ignored -- https://mail.python.org/mailman/listinfo/python-list
Re: sys.exit(1) vs raise SystemExit vs raise
On Tue, Apr 12, 2016, at 10:12, Ganesh Pal wrote: > > > > > > No; raise SystemExit is equivalent to sys.exit(0); you would need raise > > SystemExit(1) to return 1. > > > > Thanks will replace SystemExit with SystemExit(1) . > > > > > Why do you want to do this, though? What do you think you gain from it? > > > > Iam trying to have a single exit point for many functions: example > create_logdir() , create_dataset() and unittest.main() will bubble out > an > exception using raise How is this not accomplished by using sys.exit(1) in the except block? > I would want to terminate the program when this happens . > > Do you see any problem if *raise *SystemExit(1) is used in the except > block ? I still don't understand what you think you gain from this. -- https://mail.python.org/mailman/listinfo/python-list
Re: Advice on Python build tools
On Tuesday, April 12, 2016 at 4:41:15 PM UTC+5:30, Ben Finney wrote: > Sayth Renshaw writes: > > > Looking at the wiki list of build tools > > https://wiki.python.org/moin/ConfigurationAndBuildTools > > > > Has anyone much experience in build tools as i have no preference or > > experience to lean on. > > I'm quite fine with GNU Make, so haven't really tried a lot of others. Do people use 'make' for websites?? As far as I know they use tools like puppet, tox, fabric etc eg http://www.slideshare.net/adrian_nye/a-fabricpuppet-builddeploy-system http://www.slideshare.net/tanihito/automated-deployment-with-fabric > > I am fascinated by what I've seen of Meson http://mesonbuild.com/>. > It claims to behave very well with operating system package managers, > which if true makes it unique among Python-based build systems. Interesting! -- https://mail.python.org/mailman/listinfo/python-list
Re: "unable to find vcvarsall.bat"
On 04/11/2016 04:15 PM, Terry Reedy wrote: Blog post by Steve Dower of Microsoft and CPython core developer. '''How to deal with the pain of “unable to find vcvarsall.bat”''' https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/ Informative post, thanks! -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: "unable to find vcvarsall.bat"
On 4/12/2016 3:27 PM, Ethan Furman wrote: On 04/11/2016 04:15 PM, Terry Reedy wrote: Blog post by Steve Dower of Microsoft and CPython core developer. '''How to deal with the pain of “unable to find vcvarsall.bat”''' https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/ Informative post, thanks! -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: sys.exit(1) vs raise SystemExit vs raise
Ganesh Pal writes: > I m on python 2.7 and Linux , I have a simple code need suggestion if I > I could replace sys.exit(1) with raise SystemExit . No, but you can replace:: sys.exit(1) with:: raise SystemExit(1) As you know from reading the ‘sys.exit’ documentation https://docs.python.org/3/library/sys.html#sys.exit>, ‘sys.exit’ is implemented by performing ‘raise SystemExit(exit_status)’. So those do virtually the same thing. > ==Actual code== > > def main(): > try: > create_logdir() > create_dataset() > unittest.main() > except Exception as e: > logging.exception(e) > sys.exit(EXIT_STATUS_ERROR) > > if __name__ == '__main__': > main() This is good practice, putting the mainline code into a ‘main’ function, and keeping the ‘if __name__ == '__main__'’ block small and obvious. What I prefer to do is to make the ‘main’ function accept the command-line arguments, and return the exit status for the program:: def main(argv): exit_status = EXIT_STATUS_SUCCESS try: parse_command_line(argv) setup_program() run_program() except SystemExit as exc: exit_status = exc.code except Exception as exc: logging.exception(exc) exit_status = EXIT_STATUS_ERROR return exit_status if __name__ == '__main__': exit_status = main(sys.argv) sys.exit(exit_status) That way, the ‘main’ function is testable like any other function: specify the command line arguments, and receive the exit status. But the rest of the code doesn't need to know that's happening. -- \ “Programs must be written for people to read, and only | `\incidentally for machines to execute.” —Abelson & Sussman, | _o__) _Structure and Interpretation of Computer Programs_ | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: sys.exit(1) vs raise SystemExit vs raise
Hello all, Apologies for this post which is fundamentally, a 'me too' post, but I couldn't help but chime in here. >This is good practice, putting the mainline code into a ‘main’ >function, and keeping the ‘if __name__ == '__main__'’ block small >and obvious. > >What I prefer to do is to make the ‘main’ function accept the >command-line arguments, and return the exit status for the program:: > >def main(argv): >exit_status = EXIT_STATUS_SUCCESS >try: >parse_command_line(argv) >setup_program() >run_program() >except SystemExit as exc: >exit_status = exc.code >except Exception as exc: >logging.exception(exc) >exit_status = EXIT_STATUS_ERROR > >return exit_status > >if __name__ == '__main__': >exit_status = main(sys.argv) >sys.exit(exit_status) > >That way, the ‘main’ function is testable like any other function: >specify the command line arguments, and receive the exit status. >But the rest of the code doesn't need to know that's happening. This is only a riff or a variant of what Ben has written. Here's what I like to write: def run(argv): if program_runs_smoothly: return os.EX_OK else: # -- call logging, report to STDERR, or just raise an Exception return SOMETHING_ELSE def main(): sys.exit(run(sys.argv[1:])) if __name__ == '__main__': main() Why do I do this? * the Python program runs from CLI because [if __name__ == '__main__'] * I can use main() as an entry point with setuptools * my unit testing code can pass any argv it wants to the function run() * the run() function never calls sys.exit(), so my tests can see what WOULD have been the process exit code The only change from what Ben suggests is that, once I found os.EX_OK, I just kept on using it, instead of difining my own EXIT_SUCCESS in every program. Clearly, in my above example the contents of the run() function look strange. Usually it has more different kinds of stuff in it. Anyway, best of luck! -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list
Re: sys.exit(1) vs raise SystemExit vs raise
"Martin A. Brown" writes: > The only change from what Ben suggests is that, once I found os.EX_OK, > I just kept on using it, instead of difining my own EXIT_SUCCESS in > every program. Ah, thank you! I was unaware of the exit-status constants in ‘os’:: The following exit codes are defined and can be used with _exit(), although they are not required. These are typically used for system programs written in Python […] https://docs.python.org/3/library/os.html#os._exit> That defines a whole lot of exit status values with mnemonic names. I will try to make use of those instead of re-inventing them. -- \ “Let others praise ancient times; I am glad I was born in | `\ these.” —Ovid (43 BCE–18 CE) | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
real time FM synthesizer
It seems that Python is fast enough [1] to create a real time FM music synthesizer (think Yamaha DX-7). I made one that you can see here: https://github.com/irmen/synthesizer The synthesizer can create various waveforms (sine, sawtooth, pulse etc.) and lets you modify them in various ways. You can apply FM (frequency modulation), PWM (pulse-width modulation), volume envelopes, vibrato, and reverb/echo. It is primarily based around oscillators that are represented as generator functions in the code. A GUI is provided that gives access to most of the features interactively, and lets you play a tune with your created FM instrument on a piano keyboard. You will need Python 3.x and pyaudio to be able to hear sound, and matplotlib if you want to see graphical diagrams of generated waveforms. I can't create nice music myself but this was a fun project to build and to learn how FM synthesizers work internally :) Irmen [1]: meaning it can generate and play fairly complex waveforms based on multiple oscillators and filters in real time in one 44.1 kHz audio channel. That is on a 3.2 ghz machine. With enough oscillator/filters combined however it starts to stutter and cannot do it anymore in real time. However you can still generate those waveforms and save them to a .wav on disk to play afterwards. The code only uses one CPU core though so maybe there's room for improvement. -- https://mail.python.org/mailman/listinfo/python-list
hourly weather forecast data
Is there a way to get hourly weather forecast data (temperature, chance of precipitation) from the command line in Debian Linux? Basically, I am trying to write a python program that will send myself an email if it is going to rain at say 7:00 am the next day. The idea is to trigger the emails only on rainy days (but not on all days). Currently, I check for this manually at https://www.wunderground.com/cgi-bin/findweather/getForecast?query=Hackensack%2C+NJ&MR=1 . However, the website only shows graphs but does not give any data. Checking the website every day is laborious. raju -- Kamaraju S Kusumanchi | http://raju.shoutwiki.com/wiki/Blog -- https://mail.python.org/mailman/listinfo/python-list
Re: hourly weather forecast data
On Tue, 12 Apr 2016 23:36:26 -0400, kamaraju kusumanchi wrote: > Is there a way to get hourly weather forecast data (temperature, > chance of precipitation) from the command line in Debian Linux? > > Basically, I am trying to write a python program that will send myself > an email if it is going to rain at say 7:00 am the next day. The idea > is to trigger the emails only on rainy days (but not on all days). > > Currently, I check for this manually at > https://www.wunderground.com/cgi-bin/findweather/getForecast?query=Hackensack%2C+NJ&MR=1 > . However, the website only shows graphs but does not give any data. > Checking the website every day is laborious. > > raju If you have your own weather station, there is wview and WeeWX. Otherwise, this might be what you are looking for: http://www.ncdc.noaa.gov/wct/ -- GNU/Linux user #557453 "We have to build a political consensus of that requires people to give up a little bit of their own... in order to create this common ground." -Hillary Clinton -- https://mail.python.org/mailman/listinfo/python-list
Re: hourly weather forecast data
> Is there a way to get hourly weather forecast data (temperature, > chance of precipitation) from the command line in Debian Linux? If you Google for "weather API" you'll find several sites who give programmatic access to weather data. -- https://mail.python.org/mailman/listinfo/python-list
The reason I uninstalled Python 3.5.1 (32-bit) for Windows
Hello, I am providing feedback as to why I just uninstalled Python. I could not use pip. My command line would not recognize pip.exe as a file, even though I could see the file listed when I type "dir" in the Scripts folder. I tried to repair Python; however, then the file did not show up at all. I'm going to try to download the 64-bit version and see if that helps. Kind Regards, Jason Honeycutt -- https://mail.python.org/mailman/listinfo/python-list
Re: hourly weather forecast data
On 2016-04-13, Miki Tebeka wrote: > >> Is there a way to get hourly weather forecast data (temperature, >> chance of precipitation) from the command line in Debian Linux? https://forecast.io may be the solution. It provides a JSON feed, which you can parse using jq, for example. The link you want to look at is https://developer.forecast.io/docs/v2. If you should need further assistance, post a followup or write me privately. If you do the latter, do note that I will provide a summary for the group within a week of the first response. -- H -- https://mail.python.org/mailman/listinfo/python-list
Re: The reason I uninstalled Python 3.5.1 (32-bit) for Windows
Jason Honeycutt writes: > I am providing feedback as to why I just uninstalled Python. Thank you for taking the time. I feel you should know that this is a community discussion forum only: posting the message here is unlikely to do anything but engage some people in discussion. If you have enough information to suggest specific fixes that would improve the situation, perhaps a bug report at the Python bug tracker http://bugs.python.org/> will be more productive. But again, only if there is enough information that people can reproduce the problem and investigate a solution. > I'm going to try to download the 64-bit version and see if that helps. I wish you good hunting with that. Feel free to discuss here, but know that this is merely a community discussion forum, not a support channel. -- \ “Ours is a world where people don't know what they want and are | `\ willing to go through hell to get it.” —Donald Robert Perry | _o__) Marquis | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: The reason I uninstalled Python 3.5.1 (32-bit) for Windows
On Tue, Apr 12, 2016, at 07:57 PM, Jason Honeycutt wrote: > I am providing feedback as to why I just uninstalled Python. I could not > use pip. My command line would not recognize pip.exe as a file, even > though > I could see the file listed when I type "dir" in the Scripts folder. If you can't use pip while in the same directory as pip.exe, I don't even know what is wrong. That said, you can access pip via 'python -m pip args' instead of using the pip executable. -- Stephen Hansen m e @ i x o k a i . i o -- https://mail.python.org/mailman/listinfo/python-list
Re: hourly weather forecast data
On Tue, Apr 12, 2016, at 08:36 PM, kamaraju kusumanchi wrote: > Is there a way to get hourly weather forecast data (temperature, > chance of precipitation) from the command line in Debian Linux? Personally, the last time I wanted to do something like this, I used the requests library to fetch a RSS feed from Wunderground. But that was awhile ago and I don't see the obvious RSS links banymore. Did you see: https://www.wunderground.com/weather/api/d/docs -- Stephen Hansen m e @ i x o k a i . i o -- https://mail.python.org/mailman/listinfo/python-list
