Code Monkey home page Code Monkey logo

clean-code-in-python's Introduction

Clean Code in Python

Clean Code in Python

This is the code repository for Clean Code in Python, published by Packt.

Refactor your legacy code base

What is this book about?

Python is currently used in many different areas such as software construction, systems administration, and data processing. In all of these areas, experienced professionals can find examples of inefficiency, problems, and other perils, as a result of bad code. After reading this book, readers will understand these problems, and more importantly, how to correct them.

This book covers the following exciting features: Set up tools to effectively work in a development environment Explore how the magic methods of Python can help us write better code Examine the traits of Python to create advanced object-oriented design Understand removal of duplicated code using decorators and descriptors Effectively refactor code with the help of unit tests Learn to implement the SOLID principles in Python

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Instructions and Navigations

Setup

Create a virtual environment, and once activated run:

make setup

This will install the common dependencies. Besides this, each chapter might have additional ones, for which another make setup will have to be run inside that particular directory.

Each chapter has its corresponding directory given by its number.

Inside each chapter directory, tests can be run by:

make test

This requires the make application installed (in Unix environments). In environments without access to the make command, the same code can be tested by running the commands on the Makefile:

python -m doctest *.py
python -m unittest *.py

All of the code is organized into folders. For example, Chapter02.

The code will look like the following:

class Point:
    def __init__(self, lat, long):
        self.lat = lat
        self.long = long

Errata

  • In Chapter 2, page 41: Add the following import in the code: from datetime import date

Following is what you need for this book: This book will appeal to team leads, software architects and senior software engineers who would like to work on their legacy systems to save cost and improve efficiency. A strong understanding of Programming is assumed.

With the following software and hardware list you can run all code files present in the book (Chapter 1-10).

Software and Hardware List

Chapter Software required Hardware required
1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Python 3.7 System with 4GB RAM
10 Docker System with 4GB RAM

Related products

Get to Know the Author

Mariano Anaya is a software engineer who spends most of his time creating software with Python and mentoring fellow programmers. Mariano's main areas of interests besides Python are software architecture, functional programming, distributed systems, and speaking at conferences.

He was a speaker at Euro Python 2016 and 2017. To know more about him, you can refer to his GitHub account with the username rmariano.

His speakerdeck username is rmariano.

Suggestions and Feedback

Click here if you have any feedback or suggestions.

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781788835831

clean-code-in-python's People

Contributors

dependabot[bot] avatar gaurav-packt avatar manikandankurup-packt avatar mfaafm avatar murtazatinwala avatar packt-itservice avatar packtutkarshr avatar rajat-packt avatar ranggakd avatar rmariano avatar shoshan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clean-code-in-python's Issues

Installation Error

Collecting black==18.6b4
  Using cached black-18.6b4-py36-none-any.whl (81 kB)
Collecting flake8==3.5.0
  Using cached flake8-3.5.0-py2.py3-none-any.whl (69 kB)
Collecting pyflakes==1.6.0
  Using cached pyflakes-1.6.0-py2.py3-none-any.whl (227 kB)
Collecting isort==4.3.4
  Using cached isort-4.3.4-py3-none-any.whl (45 kB)
Collecting mypy==0.620
  Using cached mypy-0.620-py3-none-any.whl (1.4 MB)
Collecting pylint==2.1.1
  Using cached pylint-2.1.1-py3-none-any.whl (737 kB)
Collecting click>=6.5
  Using cached click-8.1.3-py3-none-any.whl (96 kB)
Collecting attrs>=17.4.0
  Using cached attrs-22.1.0-py2.py3-none-any.whl (58 kB)
Collecting appdirs
  Using cached appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)
Collecting toml>=0.9.4
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting pycodestyle<2.4.0,>=2.0.0
  Using cached pycodestyle-2.3.1-py2.py3-none-any.whl (45 kB)
Collecting mccabe<0.7.0,>=0.6.0
  Using cached mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)
Collecting typed-ast<1.2.0,>=1.1.0
  Using cached typed-ast-1.1.2.tar.gz (202 kB)
  Preparing metadata (setup.py) ... done
Collecting astroid>=2.0.0
  Using cached astroid-2.12.13-py3-none-any.whl (264 kB)
Collecting colorama
  Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting lazy-object-proxy>=1.4.0
  Using cached lazy_object_proxy-1.8.0-cp311-cp311-win_amd64.whl (22 kB)
Collecting wrapt<2,>=1.14
  Using cached wrapt-1.14.1-cp311-cp311-win_amd64.whl
Installing collected packages: typed-ast, pyflakes, pycodestyle, mccabe, appdirs, wrapt, toml, mypy, lazy-object-proxy, isort, flake8, colorama, attrs, click, astroid, pylint, black
  DEPRECATION: typed-ast is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for typed-ast ... error
  error: subprocess-exited-with-error

  × Running setup.py install for typed-ast did not run successfully.
  │ exit code: 1
  ╰─> [24 lines of output]
      running install
      C:\Users\dBerk\My Drive\Dev\Python\Clean-Code-in-Python\venv\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-311
      creating build\lib.win-amd64-cpython-311\typed_ast
      copying typed_ast\ast27.py -> build\lib.win-amd64-cpython-311\typed_ast
      copying typed_ast\ast3.py -> build\lib.win-amd64-cpython-311\typed_ast
      copying typed_ast\conversions.py -> build\lib.win-amd64-cpython-311\typed_ast
      copying typed_ast\__init__.py -> build\lib.win-amd64-cpython-311\typed_ast
      running build_ext
      building '_ast27' extension
      creating build\temp.win-amd64-cpython-311
      creating build\temp.win-amd64-cpython-311\Release
      creating build\temp.win-amd64-cpython-311\Release\ast27
      creating build\temp.win-amd64-cpython-311\Release\ast27\Custom
      creating build\temp.win-amd64-cpython-311\Release\ast27\Parser
      creating build\temp.win-amd64-cpython-311\Release\ast27\Python
      "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Iast27/Include "-IC:\Users\dBerk\My Drive\Dev\Python\Clean-Code-in-Python\venv\include" "-IC:\Program Files\Python311\include" "-IC:\Program Files\Python311\Include" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" /Tcast27/Custom/typed_ast.c /Fobuild\temp.win-amd64-cpython-311\Release\ast27/Custom/typed_ast.obj
      typed_ast.c
      c:\program files\python311\include\pyconfig.h(207): fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> typed-ast

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.```

Error in Chapter05

There is an error in Chapter05/decorator_wraps_2.py

line 16

return function(**kwargs, **kwargs)

should been

return function(*args, **kwargs)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.