Python homework for Introduction to Computer (計算機概論), Fall 2018
In this homework, you will learn some basic techniques for Python, Git and CI/CD.
If you are using Linux, perfect! Please ignore this part.
If you are using MacOS, good for you. Don't you consider using Linux?
If you are using other operation systems (I suppose it's Windows), you will probably have some troubles for this homework.
Windows is good for many things, but not for programming. Note that TA will not answer any homework problem if you are using Windows, so please have Linux installed. Ubuntu 16.04 or 18.04 is preferred.
If you are using Windows, please choose one of the following ways to use Linux:
- (For Windows10 users) Use the Windows Subsystem for Linux (WSL). Instructions could be found here It is the most convinient way as you could use both Linux terminal and Windows at the same time. However, WSL dose not support CUDA drivers, which means you could not use your GPU in WSL, but GPU is not needed for this homework.
- (For CSIE students) Use the CSIE workstation by SSH. See NTU CSIE System Administration Team for details. This is the easiest way but you could not install packages that requires root access in the future.
- (For all users) Dual boot your OS with Ubuntu. Google key words like "Win10 dual boot Ubuntu". This is a bit tricky and may take a while, but you could enjoy the full utilities of Linux!
- (For all users) Use a portable Ubuntu USB to boot. It is ligth-weighted and you could bring your Linux everywhere, but the memory is limited.
- (Not suggested) Use vitual machines.
- (Not suggested) Borrow a laptop with Linux.
For 2 and 3, use <ctrl>+<alt>+T
to open the terminal after booting your Linux.
-
Please create a GitHub account.
It would be better to use your NTU mail so that you would have the privilege to create private repositories. You could add an SSH key so that you don't need to verify the password every time when push/pull.
-
Fork this repository by clicking
fork
on the top-right of this page. -
Clone your forked repository to local.
git clone git@github.com:<your_github_account_name>/PythonHomework.git cd PythonHomework
"Package, dependency and environment management for any language—Python, R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, FORTRAN" -- https://conda.io/docs/
Conda is a very powerful package for development. You could easily switch between environments (e.g, Python2/3, Pytorch0.2/0.4.1 ...), which is extremely helpful when you are working on several projects as they may have conflicts with one another. Conda also help you solve the package dependencies.
Miniconda is a light-weighted version of Conda. Installing Miniconda for Python3.7 is highly suggested. You could use Anaconda as well but it requires way more space and time.
-
Download installation file from Miniconda and install accrodingly, or run
wget repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh
in your command line, and follow the instruction.
-
After installation, use
conda -V
to check.It should display something like
conda 4.5.11
. If you foundconda: command not found
or similar message, it probably means you did not add the path to the conda binary to the environment variablePATH
. Don't worry; just typeexport PATH=~/miniconda3/bin:$PATH
and try it again. It would be better to addexport PATH=~/anaconda3/bin:$PATH
to your~/.bashrc
-
Create a new environment from scatch
conda create -n <any name>
or from file (suggested)conda env create -f environement.yaml
-
Activate the environment by
source activate <name>
. Your terminal should now look like this:(your_environment_name) user@PC-name $
which means you are in the environment
your_environment_name
now. If you want to change to another environment, typesource deactivate
-
Install Flake8 in the environment
(your_environment_name) user@PC-name $ conda install flake8 (your_environment_name) user@PC-name $ flake8 .
It should prompt some warning messages regarding to Python style and syntax:
./src/sample_code.py:1:1: E902 IndentationError: unindent does not match any outer indentation level ./src/sample_code.py:38:17: E225 missing whitespace around operator ./src/sample_code.py:39:22: E999 IndentationError: unindent does not match any outer indentation level
You need to fix them later to get the points of Flake8.
The following tools would significantly improve your coding efficiency if you learn how to use it. Please at least give oh-my-zsh a try.
- Install oh-my-zsh. OMZ is a wonderful command line configuration. It includes auto-completion, alias, beautiful display and many more utilities.
- Use Vim > 8.0 and install good vimrc
- Install ALE for syntax/style check
- Install YouCompleteMe for code auto-completion
- Install ack to search local code
- Use tmux and install oh-my-tmux
Please copy src/students/sample_code.py
to src/students/<your student ID>.py
first and edit that file.
├── client
│ ├── package.json
│ ├── package-lock.json
│ ├── public
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ └── manifest.json
│ ├── README.md
│ └── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── index.css
│ ├── index.js
│ ├── logo.svg
│ ├── python.png
│ ├── results.js
│ └── serviceWorker.js
├── .gitignore
├── .travis.yml
├── environment.yaml
├── netlify.toml
├── Procfile
├── README.md
├── LICENSE
├── requirements.txt
└── src
├── autograder.py
├── logging_config.py
├── server.py
├── students
│ └── sample_code.py
└── utils.py
client/
is for the frontend. It is written in ReactJS, based on facebook/create-react-app
src/
is for the backend and homework. The server.py
uses Flask to build a backend server. The rest are files for homework. Students should only create a file under src/students
to submit their homework.
environment.yaml
is for conda environemnt.
netlify.toml
is for the Netlify settings. It is used to deploy the frontend.
.travis.yml
is for travis CI.
Procfile
is for the Heroku settings. It is used to deploy the backend.
requirements.txt
is for pip environemnt, required by Heroku.
Please send a Pull Request (PR) to the master branch.
Your PR should include only 1 file change (i.e., <your student ID>.py
).
Please name the title as [status] studentID name
(e.g., [test] r07944019 張雅量
)
TA would review your code once you mark your PR as [Needs Review]
.
The CI test will tell you if your code is runnable.
If the PR is merged, you will be graded immediately for the tasks and get this 20%.
The results could be seen here
If you are not satisfied with your score, you could send another PR.
However, each following make-up PR would result in 10 points off.
-
Task 1 (4%, no private data)
-
Task 2 ~ 8 (each 4% for public data, 4% for private data)
You could use python autograder.py -student_id <student ID>
to see if you pass all the tasks for the public data.
You will know the score for the private data once the PR is merged.
Please use flake8 src/<student ID>.py
to see if your file has passed the Flake8 checker.
Please write readable code and commit message.
Some examples:
-
Rebase before the Pull Request (10%)
-
Create an issue for a bug / unclear part of this repository (10%)
-
Create an issue for a technical problem that could not be solved easily (e.g. by Google) (10%)
-
Answer an issue that could not be solved easily (10%)
-
Send a PR and solve a bug in this repository (30%)
1a.(Recommended) If you are using miniconda, please make sure that you have create the environment
By using conda env create -f environment.yaml
, you can create an environment to meet the need for this homework.
To activate your environment:source activate your_environment_name
1b.If you have problem or can't install miniconda (e.g. Arm-based linux such as Raspbian),please make sure that Python3 version is 3.6 or later.You could use python3 -V
to check your Python version. And if you want to install python package, we recommended to create a virtual environment first with python3 -m venv your_env_name
and activate the environment with
source ~/envs/your_env_name/bin/activate
then use pip3 install <package_name>
to install packages.
- To install Python packages, we recommended to use "conda" to install needed modules.
conda install <package_name>
If you have not installed miniconda, you can usepip
.
-
To solve
ModuleNotFoundError: No module named 'yaml'
, please make sure you have already installpyyaml
by usingconda install pyyaml
-
If you are using Python 2.7, you might got an error message:
File "autograder.py", line 70
assert os.path.exists(student_file), f"{student_file} not exists"
^
SyntaxError: invalid syntax
If you want to clone a remote repository (e.g. Github) to local, you can use git clone
a. Clone via SSH (Recommended)
To use SSH to clone, please read the article first: (https://help.github.com/articles/connecting-to-github-with-ssh/)
Example:
$ git clone git@github.com:<owner_of_repo>/<repo_name>
b. clone via Https
$ git clone https://github.com/<owner_of_repo>/<repo_name>.git
No matter which method you choose to use, you may see some message like:
Cloning into 'repo_name'...
remote: Enumerating objects: 669, done.
remote: Total 669 (delta 0), reused 0 (delta 0), pack-reused 669
Receiving objects: 100% (669/669), 600.65 KiB | 335.00 KiB/s, done.
Resolving deltas: 100% (368/368), done.
Checking connectivity... done.
It will create a directory <repo_name> under your current directory, and you can modify the files now.
If you want to store current contents of the index, you can use git commit
Before making a commit, you should add modified files first, using git add <file_name>
After adding modified files, you can make a commit to describe what you change in the repo.
If you only want to describe the commit only, you can use git commit -m "your_message"
After making a commit, you can push your commit to remote by using git push origin <branch_name>
Note:Default name of the branch is master
So that your remote repository will be up-to-date with your local repository.
Example:
$ git add b07902999.py
$ git commit -m "Pass task 1"
[master ba496b5] Pass task 1
1 file changed, 2 insertions(+)
create mode 100644 b07902999.py
$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 303 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:b07902999/PythonHomework
608fe24..ba496b5 master -> master
Since this repository is frequently updated, you may need to update your repository to latest version but also keep your changes. To do this:
# Set 'upstream' to the original repo
$ git remote add upstream git@github.com:amjltc295/PythonHomework.git
# Change to the branch you want to update. If you are already in that branch, this command is not needed.
$ git checkout <your-working-branch>
# Fetch data from the remote
$ git fetch upstream master
# Rebase current branch on the latest remote branch
$ git rebase upstream/master
If you only modify src/students/<student-id>.py
, conflicts should not happen. If there are conflicts, just fix it and use git add <conflicted-file>
and git rebase --continue
to complete rebase.
After rebase your local git, git push
may not work since your git tree has changed. Use git push -f
to force push to remote instead. Notice that don't use this command to a branch if there are somebody else is using this branch, unless you exactly know what you are doing.
To read more: merging vs rebasing.
- Merge Multiple Commits into One Commit
- Send PR with only one commit https://medium.com/@s950449/git-advanced-operation-c1d56ac4d920
MIT
Ya-Liang Chang (Allen) amjltc295 - Homework design, backend, frontend, CI/CD