PSF GSoC students blogs: Google Summer of Code with Nuitka 4th Blog Post

<meta charset=”utf-8″>

<meta charset=”utf-8″>

This week, I continued to work on my script which automates the testing of nuitka-wheel pytest. Details can be found on my pull request: https://github.com/Nuitka/Nuitka/pull/440

 

The script automates the manual testing of comparing pytest results of a nuitka compiled wheel using `python setup.py bdist_nuitka` to the pytest results of an uncompiled wheel built using `python setup.py bdist_wheel` for the most popular PyPI packages. Testing is done to ensure that nuitka is building the wheel correctly. If the pytests pass/fail in the same way, that means Nuitka built the wheel properly. Else if the tests differ, then something is wrong. Virtualenv is used to create a clean environment with no outside pollution.

 

There were a lot of changes made this week.

  • Added an `__import__` check to make sure pytest used the correct (uncompiled or compiled) package

  • Added a mechanism to ignore certain tests which are unimportant (fixed the comparison issue for urllib3)

  • Added coloring to output for better visuals

  • Added a summary of all packages at the very end of testing

  • Extended testing to many more packages

  • Added local caching of `git clone`

  • Many run time improvements

 

Very proud of the work I have done this week. The plan for next week is to extend the automation to more PyPI packages.

 

Planet Python

Mike Driscoll: Intro to Black – The Uncompromising Python Code Formatter

There are several Python code checkers available. For example, a lot of developers enjoy using Pylint or Flake8 to check their code for errors. These tools use static code analysis to check your code for bugs or naming issues. Flake8 will also check your code to see if you are adhering to PEP8, Python’s style guide.

However there is a new tool that you can use called Black. Black is a Python code formatter. It will reformat your entire file in place according to the Black code style, which is pretty close to PEP8.


Installation

Installing Black is easy. You can just use pip for that:

pip install black

Now that it’s installed, let’s give Black a try!


Using Black

Black requires you to have some code to run it against. Let’s create a simple function that has lots of parameters and then run Black on that script.

Here’s an example:

def long_func(x, param_one=None, param_two=[], param_three={}, param_four=None, param_five="", param_six=123456):     print("This function has several params")

Now in your terminal, try running black against your code file like this:


black long_func.py

When you run this command, you should see the following output:


reformatted long_func.py
All done! ✨ 🍰 ✨
1 file reformatted.

This means that your file has been reformatted to follow the Black standard.

Let’s open the file up and see what it looks like:

def long_func(     x,     param_one=None,     param_two=[],     param_three={},     param_four=None,     param_five="",     param_six=123456, ):     print("This function has several params")

As you can see, Black has put each of the parameters on their own line.


Checking Files for Formatting

If you don’t want Black to change your file, but you want to know if Black thinks a file should be changed, you can use one of the following command flags:

  • –check – which checks if the file should be reformatted, but doesn’t actually modify the file
  • –diff – which writes out a diff of what Black would do to the file, but doesn’t modify the file

I like to use these to do a test run on my files and see how Black will reformat my code. I haven’t been using Black a long time, so this let’s me see if I like what Black is going to do without actually doing anything.


Wrapping Up

I like Black. I think it could be really useful, especially in an organization when it comes to enforcing a certain Python style. Note that Black defaults to 88 characters for its line length, but you can change that using -l or --line-length if you need to. There are also a few other options you might find useful listed on the project’s page. If you get a chance, I think you should give Black a try!


Related Reading

The post Intro to Black – The Uncompromising Python Code Formatter appeared first on The Mouse Vs. The Python.

Planet Python

PyBites: Code Challenge 62 – Women @ Pycon ES

There is an immense amount to be learned simply by tinkering with things. – Henry Ford

Hey Pythonistas,

Coming thursday, the 18th of July 2019, we will organize a special challenge in collaboration with Python Alicante.

Spin up your favorite editor and start coding in Python!

The Challenge

We’d like to keep to a PyCon theme so let’s find out how many female speakers have been at PyCon ES and what the trend is:

  • Scrape 5 year’s worth of Pycon ES sites, years 2013-2018, and for each year extract all of the speakers. They are usually located under “schedule”, “agenda” or “charlas”.

  • Once you have a list of all of the speakers per year, use a Python lib or API of choice to determine if the speaker is female or not.

  • Bonus 1: How does this data compare to Pycon US and/or EU?

  • Bonus 2: Plot the data with your favorite data viz library – did the % of female speakers at Pycon ES go up or down in the past years? How does it compare to the Pycon US/EU findings in Bonus 1?

  • PR your work on our platform no later than 19th of July midnight AoE.

  • The Pybites / Python Alicante jury will only look at solutions from Ninjas that PR their work and include code for both bonus items. Submission speed and elegance will be looked at in particular. Winners will receive one of 3 prizes at random:

We encourage you to join our PyBites Slack Community and hop in the #pyday channel to collaborate. Please do not post solutions in this channel.

Last but not least: the intent is not to just focus on the best solution. Rather, the priority for all should be to learn and improve your Python skills. Keep it cool like Fonzie and enjoy the ride!

Ideas for future challenges, channel ideas / requests can be submitted via GH Issues.


Get serious, take your Python to the next level …

At PyBites we’re all about creating Python ninjas through challenges and real-world exercises. Read more about our story.

We are happy and proud to share that we now hear monthly stories from our users that they’re landing new Python jobs. For many this is a dream come true, especially as they’re often landing roles with significantly higher salaries!

Our 200 Bites of Py exercises are geared toward instilling the habit of coding frequently, if not daily which will dramatically improve your Python and problem solving skills. This is THE number one skillset necessary to becoming a linchpin in the industry and will enable you to crush it wherever codes need to be written.

Take our free trial and let us know on Slack how it helps you improve your Python!


>>> from pybites import Bob, Julian  Keep Calm and Code in Python! 

Planet Python

Test and Code: 79: Fixing misinformation about software testing

Some information about software testing is just wrong.
I’m not talking about opinions. I have lots of opinions and they differ from other peoples opinions. I’m talking about misinformation and old information that is no longer applicable.

I’ve ran across a few lateley that I want to address.

All of the following are wrong:

  1. Integrated tests can’t work. I can prove it with wacky math.
  2. Tests have to be blazing fast or they won’t get run.
  3. TDD is about design, not about testing.

This episode discusses why these are wrong.

Sponsored By:

Support Test & Code – Python Testing & Development

Links:

<p>Some information about software testing is just wrong.<br> I&#39;m not talking about opinions. I have lots of opinions and they differ from other peoples opinions. I&#39;m talking about misinformation and old information that is no longer applicable.</p> <p>I&#39;ve ran across a few lateley that I want to address.</p> <p>All of the following are wrong:</p> <ol> <li>Integrated tests can&#39;t work. I can prove it with wacky math. </li> <li>Tests have to be blazing fast or they won&#39;t get run.</li> <li>TDD is about design, not about testing.</li> </ol> <p>This episode discusses why these are wrong.</p><p>Sponsored By:</p><ul><li><a href=”https://pantheon.io/testandcode” rel=”nofollow”>Pantheon</a>: <a href=”https://pantheon.io/testandcode” rel=”nofollow”>Pantheon makes building, managing, and optimizing websites simpler. Get started for free at pantheon.io/testandcode.</a></li></ul><p><a href=”https://www.patreon.com/testpodcast” rel=”payment”>Support Test & Code – Python Testing & Development</a></p><p>Links:</p><ul><li><a href=”https://aquestionofcode.com/22-why-should-you-write-tests/” title=”Why should you write tests? – A Question of Code Podcast” rel=”nofollow”>Why should you write tests? – A Question of Code Podcast</a></li><li><a href=”https://www.destroyallsoftware.com/talks/boundaries” title=”Boundaries talk by Gary Bernhardt” rel=”nofollow”>Boundaries talk by Gary Bernhardt</a></li><li><a href=”https://www.youtube.com/watch?v=VDfX44fZoMc” title=”Integrated Tests Are A Scam – J B Rainsberger” rel=”nofollow”>Integrated Tests Are A Scam – J B Rainsberger</a></li><li><a href=”https://martinfowler.com/bliki/UnitTest.html” title=”UnitTest – Solitary or Sociable – and speed – Martin Fowler” rel=”nofollow”>UnitTest – Solitary or Sociable – and speed – Martin Fowler</a></li><li><a href=”http://wiki.c2.com/?PrematureOptimization” title=”Premature optimization is the root of all evil — DonaldKnuth” rel=”nofollow”>Premature optimization is the root of all evil — DonaldKnuth</a></li><li><a href=”http://pythontesting.net/agile/is-tdd-dead/” title=”My reaction to “Is TDD Dead?” – Python Testing” rel=”nofollow”>My reaction to “Is TDD Dead?” – Python Testing</a></li><li><a href=”https://dhh.dk/2014/test-induced-design-damage.html” title=”Test-induced design damage – DHH” rel=”nofollow”>Test-induced design damage – DHH</a></li><li><a href=”https://dhh.dk/2014/slow-database-test-fallacy.html” title=”Slow database test fallacy – DHH” rel=”nofollow”>Slow database test fallacy – DHH</a></li><li><a href=”https://www.youtube.com/watch?v=9LfmrkyP81M” title=”RailsConf 2014 – Keynote: Writing Software – DHH” rel=”nofollow”>RailsConf 2014 – Keynote: Writing Software – DHH</a></li><li><a href=”https://agilemanifesto.org/” title=”Manifesto for Agile Software Development” rel=”nofollow”>Manifesto for Agile Software Development</a></li><li><a href=”https://cwiki.apache.org/confluence/display/BEAM/Contribution+Testing+Guide” title=”Apache Beam Contrib Guide, including post commit testing” rel=”nofollow”>Apache Beam Contrib Guide, including post commit testing</a></li></ul>
Planet Python