Giter Site home page Giter Site logo

rayluo / easter Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 1.0 98 KB

Shows Easters in a century. This repo is also a sample/tutorial to show how to use brip in your Brython project.

Home Page: https://rayluo.github.io/easter/

License: MIT License

HTML 51.27% JavaScript 29.62% Python 19.11%
brython brip sample

easter's Introduction

Easter Distribution

This project shows how Easters within a century are distributed among months and dates, and how Easter date swings back and forth, year after year. It is in action here.

This project is also designed to be a sample of how to use brip to pull in generic pure Python packages into your Brython-powered project.

How to develop a project like this?

We chose to implement the following features in this sample project, to showcase how generic Python packages could be pulled into your project by brip.

So, how to build a Brython project to utilize the above 2 generic Python packages?

  1. Prerequisite: You do NOT need to install those 2 packages by the normal pip. Instead, you use pip to install brip into a virtual environment, once and for all: such an environment can be shared among all your Brython projects.

    Installation on Linux and macOS:

    python3 -m venv ~/venv_central
    source ~/venv_central/bin/activate
    pip install brip
    

    Installation on Windows:

    py -m venv $HOME\venv_central
    $HOME\venv_central\Scripts\activate.bat
    pip install brip
    
  2. Create an empty Brython project. You can start from scratch, or clone or download this template Brython project.

  3. Inside your Brython project's webroot directory (i.e. the directory containing your index.html), create a brequirements.txt file containing your dependencies. After you finish that, your project structure could be something like this.

    easter
    ├── website
    │   ├── index.html
    │   ├── ...
    │   └── brequirements.txt
    └── README.md
    

    Your brequirements.txt declares dependencies, optionally with their version ranges.

    python-dateutil<3
    charts.css.py>=0.4.0,<1
    

    For what it's worth, the python-dateutil package has its own dependency on six, but you don't have to know, brip will automatically pull in all dependencies for you.

  4. Run brip install -r brequirements.txt. This will generate a site-packages.brython.js file, which contains the packages that you declared, as well as all their dependencies.

  5. In your Brython project's index.html, include the brython.js as usual, and you would typically also need to include the brython_stdlib.js, lastly you include the site-packages.brython.js that we generated just now.

    That is all. Now you can use import dateutil and import charts.css in your Brython project.

  6. Once you finish your project, you can deploy it with the generated site-packages.brython.js.

    Alternatively, this project chooses to run step 4 on-the-fly via Github Actions, and then deploy the website to Github Pages (with the help from another tool named Github Page Overwriter). The end result is you do not even need to hardcode a copy of site-packages.brython.js inside your project's code base. See how clean our code base is.

Caveat

The two external dependencies, python-dateutil and charts.css.py, work smooth inside Brython. But the reality is, not every PyPI packages would work fine. Please refer to the limitations of brip for more details.

easter's People

Contributors

rayluo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jacklinquan

easter's Issues

Cannot install brip

Bonjour Ray !

I would love to install and test brip on my PC (Windows 10), but I am currently unable to do it, despite a few trials.

Here is what I get:

C:\Users\PC>e:\Python39\python -m venv c:\Users\PC\venv_central

C:\Users\PC>c:\Users\PC\venv_central\Scripts\activate.bat

(venv_central) C:\Users\PC>e:\Python39\Scripts\pip install brip
Collecting brip
  Using cached brip-0.2.1-py2.py3-none-any.whl (7.2 kB)
Collecting pip>=21.1
  Using cached pip-21.2.2-py3-none-any.whl (1.6 MB)
Requirement already satisfied: brython<4,>=3.7.5 in e:\python39\lib\site-packages (from brip) (3.9.1)
Installing collected packages: pip, brip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.3
    Uninstalling pip-20.2.3:
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Accès refusé: 'e:\\python39\\scripts\\pip.exe'
Consider using the `--user` option or check the permissions.


(venv_central) C:\Users\PC>

It seems that brip tries to install pip, which is already installed (otherwise the command "pip install brip") could not start) and running.

Am I missing something ?

Also not that the extension ".bat" is required on Windows for activate.

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.