The first thing we do in this video is start a new virtual environment.
python3.7 -m venv venv
source venv/bin/activate
This command uses the venv
module to create a new folder called venv
. After
it is created we source it. This way we can work on our project without having
to worry about other projects. If this is unfamiliar territory for you, feel
free to review our series on virtual environments.
Next we create our project folder clumper
. The __init__.py
file inside
of the clumper
folder is empty but the contents of the clump.py
file is:
class Clumper:
def __init__(self, blob):
self.blob = blob
def keep(self, *funcs):
data = self.blob
for func in funcs:
data = [d for d in data if func(d)]
return Clumper(data)
def head(self, n):
return Clumper([self.blob[i] for i in range(n)])
def tail(self, n):
return Clumper([self.blob[-i] for i in range(1, n+1)])
def select(self, *keys):
return Clumper([{k: d[k] for k in keys} for d in self.blob])
def mutate(self, **kwargs):
data = self.blob
for key, func in kwargs.items():
for i in range(len(data)):
data[i][key] = func(data[i])
return Clumper(data)
def sort(self, key, reverse=False):
return Clumper(sorted(self.blob, key=key, reverse=reverse))
The contents of the setup.py
file in this video is:
from setuptools import setup, find_packages
setup(
name="clumper",
version="0.1.0",
packages=find_packages(),
)
With all these files set up we can install the package in our virtual environment. You can use this pip command to achieve that:
python -m pip install -e .
Again, if this is unfamiliar territory for you, feel free to review our series on virtual environments.