Question: Steps to Complete Information Before working on this task, make sure that you have obtained a full score from Task 1 . This task builds

Steps to Complete
Information
Before working on this task, make sure that you have obtained a full score from Task 1. This task builds on top of that work.
In this task you will re-organize the code base. Your goal is to separate the code that is strictly related to running the application in CLI from the more general code that can be leveraged by any interface (e.g., CLI or GUI). As an example, consider the run method of the AppEngine class.
def run(self):
while True:
prompt = 'What would you like to do?'
if self.correct_answer is not None:
prompt = 'What amount should replace the questionmarks? $'
cmd = input(prompt)
self.execute_command(cmd)
print(f'{self.message}
')
self.message = None
if not self.continue_execution:
break
Clearly, this method is very specific to the CLI. It is almost certainly not suitable for the GUI where a user is mostly expected to click buttons, fill in text fields, etc. On the other hand, consider the remove_item method of the ItemPool class.
def remove_item(self, item_name):
if item_name not in self.items:
raise NonExistingItemError(item_name)
del self.items[item_name]
This method is responsible for removing an item from the pool. It is not specific to CLI. It is likely to be used by both CLI and GUI. While from CLI it can be invoked via, e.g., a del command, from GUI it can be invoked, e.g., via a Remove button.
Danger
The steps that you are about to perform will change the application in such a way that a submission to Task 1 will no longer be possible. If for whatever reason you plan to make submissions to Task 1 in future, you should create a backup of your code base before proceeding further.
Restructure Codebase
Currently, the codebase has the following flat layout:
+ ppp-p5-debug-refactor-test-package
|-- app.py
|-- errors.py
|-- items.py
|-- shoppinglist.py
Your goal is to reorganize the codebase so that the following layout is achieved:
+ ppp-p5-debug-refactor-test-package
|-- app_cli.py
|-+ core
|--__init__.py
|-- appengine.py
|-- errors.py
|-- items.py
|-- shoppinglist.py
This means that you will:
Rename the app.py file to app_cli.py.
Create a new directory core and move the errors.py, items.py, and shoppinglist.py files to this directory. Note that VS Code may prompt you about some automatic changes to be done based on these actions. We recommend you do NOT accept those changes. First of all, this is because you would like to practice making such changes. Second, it is quite likely that the changes proposed by the VS Code may not be exactly what is needed. If you do not have enough experience with refactoring these changes may result in confusion.
Create empty __init__.py and appengine.py files in the core directory.
After you have moved the files around as described above, the application may no longer be working.
python app_cli.py
Traceback (most recent call last):
File "...\app_cli.py", line 2, in
from errors import *
ModuleNotFoundError: No module named 'errors'
This is expected and it is no reason for concern. All you will have to do is to fix the import statements in all the application files. You have to realize that before the files were located in the same directory but this is no longer the case. It is up to you to figure what changes are needed to the import statements (in all the files) to make the application work again.
For example, the following no longer works:
from errors import InvalidItemNameError
It needs to be replaced with the following:
from core.errors import InvalidItemNameError
After making the changes, convince yourself that the application works by engaging in some non-trivial interaction.
python app_cli.py
What would you like to do? l
Shopping list with 2 items has been created.
What would you like to do? show list
SHOPPING LIST
- Beef Steak (1x)... $0025.18
- Macbook (4x)...... $7999.96
------------------------------
TOTAL ............... $8025.14
What would you like to do? a
SHOPPING LIST
- Beef Steak (1x)... $????.??
- Macbook (4x)...... $7999.96
------------------------------
TOTAL ............... $8025.14
What amount should replace the questionmarks? $100
Not Correct! (Expected $25.18)
You answered $100.00.
What would you like to do? q
Have a nice day!
In addition convince yourself that the following statements work:
python
>>> import core.errors
>>> import core.items
>>> import core.shoppinglist
Information
Do not proceed further unless you have convinced yourself that the application works. Be careful about leaving the original files in their original place. It is necessary to move the files (not copy) to the new location. If you would like to preserve the original files for future reference, you may keep the copies but keep them out of the project directory to minimize c

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!