diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7591f0c..7b5ca291 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: Build Project [using jupyter-book] on: [push] jobs: - tests: + preview: runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 09182942..91864fb6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,8 +3,9 @@ on: push: branches: - master + - add-binder jobs: - tests: + publish: runs-on: ubuntu-latest steps: - name: Checkout @@ -24,19 +25,41 @@ jobs: - name: Display Pip Versions shell: bash -l {0} run: pip list - - name: Build HTML - shell: bash -l {0} - run: | - jb build lectures --path-output ./ + # - name: Build HTML + # shell: bash -l {0} + # run: | + # jb build lectures --path-output ./ - name: Build Download Notebooks (sphinx-tojupyter) shell: bash -l {0} run: | jb build lectures --path-output ./ --builder=custom --custom-builder=jupyter - mkdir _build/html/_notebooks - cp _build/jupyter/*.ipynb _build/html/_notebooks - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 + # - name: Copy Download Notebooks for GH-PAGES + # shell: bash -l {0} + # run: | + # mkdir _build/html/_notebooks + # cp _build/jupyter/*.ipynb _build/html/_notebooks + # - name: Deploy to gh-pages + # uses: peaceiris/actions-gh-pages@v3 + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # publish_dir: _build/html/ + # cname: python-programming.quantecon.org + - name: Prepare lecture-python-programming.notebooks sync + shell: bash -l {0} + run: | + mkdir -p _build/lecture-python-programming.notebooks + cp -a _notebook_repo/. _build/lecture-python-programming.notebooks + cp _build/jupyter/*.ipynb _build/lecture-python-programming.notebooks + ls -a _build/lecture-python-programming.notebooks + - name: Commit latest notebooks to lecture-python-programming.notebooks + uses: cpina/github-action-push-to-another-repository@master + env: + API_TOKEN_GITHUB: ${{ secrets.QUANTECON_SERVICES_PAT }} with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: _build/html/ - cname: python-programming.quantecon.org \ No newline at end of file + source-directory: '_build/lecture-python-programming.notebooks/' + destination-repository-username: 'QuantEcon' + destination-repository-name: 'lecture-python-programming.notebooks' + target-branch: 'update-notebooks' + commit-message: 'auto publishing updates to notebooks' + destination-github-username: 'quantecon-services' + user-email: services@quantecon.org diff --git a/_notebook_repo/README.md b/_notebook_repo/README.md new file mode 100644 index 00000000..3bd13ee4 --- /dev/null +++ b/_notebook_repo/README.md @@ -0,0 +1,7 @@ +# lecture-python-programming.notebooks + +[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/QuantEcon/lecture-python-programming.notebooks/master) + +Notebooks for https://python-programming.quantecon.org + +**Note:** This README should be edited [here](https://github.com/quantecon/lecture-python-programming.myst/.binder) diff --git a/_notebook_repo/environment.yml b/_notebook_repo/environment.yml new file mode 100644 index 00000000..de38000a --- /dev/null +++ b/_notebook_repo/environment.yml @@ -0,0 +1,17 @@ +name: lecture-python-programming +channels: + - default +dependencies: + - python=3.8 + - anaconda + - pip + - pip: + - git+https://github.com/executablebooks/jupyter-book.git + - sphinxext-rediraffe + - git+https://github.com/executablebooks/sphinx-multitoc-numbering + - git+https://github.com/executablebooks/sphinx-exercise.git + - joblib + - interpolation + - git+https://github.com/QuantEcon/sphinx-tojupyter.git + - git+https://github.com/QuantEcon/quantecon-book-theme.git + diff --git a/lectures/getting_started.md b/lectures/getting_started.md index c83d393b..327f44f0 100644 --- a/lectures/getting_started.md +++ b/lectures/getting_started.md @@ -364,7 +364,7 @@ One library we'll be using is [QuantEcon.py](http://quantecon.org/quantecon-py). You can install [QuantEcon.py](http://quantecon.org/quantecon-py) by starting Jupyter and typing -```{code-block} ipython3 +```ipython3 !conda install quantecon ``` @@ -372,7 +372,7 @@ into a cell. Alternatively, you can type the following into a terminal -```{code-block} bash +```bash conda install quantecon ``` @@ -380,7 +380,7 @@ More instructions can be found on the [library page](http://quantecon.org/quante To upgrade to the latest version, which you should do regularly, use -```{code-block} bash +```bash conda upgrade quantecon ``` @@ -388,7 +388,7 @@ Another library we will be using is [interpolation.py](https://github.com/EconFo This can be installed by typing in Jupyter -```{code-block} ipython3 +```ipython3 !conda install -c conda-forge interpolation ``` @@ -516,7 +516,7 @@ As the 1st task, try For example, if you've installed the command line version, open up a terminal and enter. -```{code-block} bash +```bash git clone https://github.com/QuantEcon/QuantEcon.py ``` diff --git a/lectures/need_for_speed.md b/lectures/need_for_speed.md index 602762b8..e54c4e58 100644 --- a/lectures/need_for_speed.md +++ b/lectures/need_for_speed.md @@ -197,7 +197,7 @@ Compiled languages avoid these overheads with explicit, static types. For example, consider the following C code, which sums the integers from 1 to 10 -```{code-block} c +```c #include int main(void) { diff --git a/lectures/pandas.md b/lectures/pandas.md index baf87644..039d650d 100644 --- a/lectures/pandas.md +++ b/lectures/pandas.md @@ -165,7 +165,7 @@ Let's look at an example that reads data from the CSV file `pandas/data/test_pwt Here's the content of `test_pwt.csv` -```{code-block} none +``` "country","country isocode","year","POP","XRAT","tcgdp","cc","cg" "Argentina","ARG","2000","37335.653","0.9995","295072.21869","75.716805379","5.5788042896" "Australia","AUS","2000","19053.186","1.72483","541804.6521","67.759025993","6.7200975332" @@ -292,7 +292,7 @@ For example, suppose that we are interested in the [unemployment rate](https://r Via FRED, the entire series for the US civilian unemployment rate can be downloaded directly by entering this URL into your browser (note that this requires an internet connection) -```{code-block} none +``` https://research.stlouisfed.org/fred2/series/UNRATE/downloaddata/UNRATE.csv ``` diff --git a/lectures/python_advanced_features.md b/lectures/python_advanced_features.md index ab93552b..c6f8c186 100644 --- a/lectures/python_advanced_features.md +++ b/lectures/python_advanced_features.md @@ -142,7 +142,7 @@ All iterators can be placed to the right of the `in` keyword in `for` loop state In fact this is how the `for` loop works: If we write -```{code-block} python3 +```python3 for x in iterator: ``` @@ -155,7 +155,7 @@ then the interpreter So now you know how this magical looking syntax works -```{code-block} python3 +```python3 f = open('somefile.txt', 'r') for line in f: # do something @@ -526,7 +526,7 @@ We are now working in the module `__main__`, and hence the namespace for `__main Next, we import a module called `amodule` -```{code-block} python3 +```python3 import amodule ``` @@ -1660,7 +1660,7 @@ Write a function to recursively compute the $t$-th Fibonacci number for any $t$. Complete the following code, and test it using [this csv file](https://raw.githubusercontent.com/QuantEcon/lecture-python-programming/master/source/_static/lecture_specific/python_advanced_features/test_table.csv), which we assume that you've put in your current working directory -```{code-block} python3 +```python3 def column_iterator(target_file, column_number): """A generator function for CSV files. When called with a file name target_file (string) and column number @@ -1680,7 +1680,7 @@ for date in dates: Suppose we have a text file `numbers.txt` containing the following lines -```{code-block} none +``` prices 3 8 diff --git a/lectures/python_by_example.md b/lectures/python_by_example.md index 44958ef5..7c586cd4 100644 --- a/lectures/python_by_example.md +++ b/lectures/python_by_example.md @@ -144,7 +144,7 @@ easily enough if you look around. On this machine, it's located in -```{code-block} ipython +```ipython anaconda3/lib/python3.7/site-packages/numpy ``` @@ -333,7 +333,7 @@ for animal in animals: This example helps to clarify how the `for` loop works: When we execute a loop of the form -```{code-block} python3 +```python3 for variable_name in sequence: ``` diff --git a/lectures/python_essentials.md b/lectures/python_essentials.md index 954e59d8..40ebb06e 100644 --- a/lectures/python_essentials.md +++ b/lectures/python_essentials.md @@ -314,7 +314,7 @@ Note that if `newfile.txt` is not in the present working directory then this cal In this case, you can shift the file to the pwd or specify the [full path](https://en.wikipedia.org/wiki/Path_%28computing%29) to the file -```{code-block} python3 +```python3 f = open('insert_full_path_to_file/newfile.txt', 'r') ``` @@ -620,7 +620,7 @@ After running this code, the docstring is available f? ``` -```{code-block} ipython +```ipython Type: function String Form: File: /home/john/temp/temp.py @@ -632,7 +632,7 @@ Docstring: This function squares its argument f?? ``` -```{code-block} ipython +```ipython Type: function String Form: File: /home/john/temp/temp.py @@ -692,7 +692,7 @@ Here the function created by `lambda` is said to be *anonymous* because it was n In a {ref}`previous lecture `, you came across the statement -```{code-block} python3 +```python3 plt.plot(x, 'b-', label="white noise") ``` diff --git a/lectures/python_oop.md b/lectures/python_oop.md index 3c0a778c..e67dd55d 100644 --- a/lectures/python_oop.md +++ b/lectures/python_oop.md @@ -776,7 +776,7 @@ Implement $F_n$ as a class called `ECDF`, where Your code should work as follows (modulo randomness) -```{code-block} python3 +```python3 from random import uniform samples = [uniform(0, 1) for i in range(10)] @@ -784,7 +784,7 @@ F = ECDF(samples) F(0.5) # Evaluate ecdf at x = 0.5 ``` -```{code-block} python3 +```python3 F.observations = [uniform(0, 1) for i in range(1000)] F(0.5) ```