From 9cc3d9b6aea3ffd77b6b64344aa075af2cb60e35 Mon Sep 17 00:00:00 2001 From: halfcrazy Date: Tue, 5 May 2015 20:52:03 +0800 Subject: [PATCH 1/6] fix typo --- posts/new.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/new.md b/posts/new.md index c95ba62..8bab150 100644 --- a/posts/new.md +++ b/posts/new.md @@ -37,7 +37,7 @@ PS: virtualenv是一个虚拟环境, 主要解决多python环境下依赖不相 PS: 你需要Python Development Headers来作为依赖安装py-bcrypt包,如果你使用的是Mac OS或者Windows,你应该已经有了这个依赖。否则如果是Debian系的发行版需要安装python-dev包,如果是RedHat系的发行版需要安装python-devel包。 ``` -#### 初始化firfly的开发环境 +#### 初始化firefly的开发环境 ```python $git clone https://github.com/python-cn/firefly # 克隆代码到本地 From a057d8f38047aee4eced931ba5aee2e9ff99c462 Mon Sep 17 00:00:00 2001 From: dongweiming Date: Thu, 7 May 2015 23:14:39 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=86=99py3=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E4=BB=A3=E7=A0=81=E7=9A=84=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- posts/flow-and-standards.md | 6 +++++ posts/list.md | 3 +++ posts/porting3.md | 52 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 posts/porting3.md diff --git a/posts/flow-and-standards.md b/posts/flow-and-standards.md index e5f7cff..20319af 100644 --- a/posts/flow-and-standards.md +++ b/posts/flow-and-standards.md @@ -167,12 +167,18 @@ pr还有2种特殊的用法: 1. 写代码的时候尽量支持python2+python3 2. 希望更多愿意尝试python3的同学参与进来 +写兼容python3的代码可以参看 [python3兼容的代码](/#/post/porting3.md) + ### 代码规范 「无规矩不成方圆!」 我坚信一个健康成长的社区,需要一帮有自己品位, 态度的维护者和开发者. 为了保证社区代码的质量, 我希望每个开发者都能遵守以下一些准则 +#### 代码规范 + +要先读读 https://github.com/mdo/code-guide + #### CSS 项目使用scss, 不能直接修改css. 这样的代码修改是不会被merge的 diff --git a/posts/list.md b/posts/list.md index 96f842b..3de323e 100644 --- a/posts/list.md +++ b/posts/list.md @@ -10,6 +10,9 @@ url: new.md title: 开发流程&代码规范 url: flow-and-standards.md ------- +title: 写python3兼容的代码 +url: porting3.md +------- title: python学习之路 url: material.md ------- diff --git a/posts/porting3.md b/posts/porting3.md new file mode 100644 index 0000000..92d98b9 --- /dev/null +++ b/posts/porting3.md @@ -0,0 +1,52 @@ +title: 写python3兼容的代码 +------------------------- + +假如你想参与firefly的开发, 我们原则上要求写能支持py2且支持py3的代码. + +### 资料 + +从开发角度了解python3的意义: http://ncoghlan-devs-python-notes.readthedocs.org/en/latest/python3/questions_and_answers.html + +书: http://python3porting.com/ + +链接: https://docs.python.org/3.3/howto/pyporting.html + +### python-modernize + +如果你对python3不熟悉 可以使用[python-modernize](https://github.com/mitsuhiko/python-modernize)跑一下代码, 它会演示建议你需要修改的地方: + +```python +python-modernize --no-six -w firefly/app.py +``` + +### firefly目前的做法 + +我们既没有使用six, 也没有使用future, 而是维护了firefly/six.py + +原因是 我们遇到的坑还少, six/future需要开发者熟悉它的解决方案. 我们只需要添加有限的几种问题即可(自己添加会更熟悉和趁手) + +PS:不排除未来我们也会使用six/future作为我们的方案. + +### firefly兼容要求 + +1. 不要显式的使用u''. 因为在python3.3之前这是语法错误. +2. 有print的时候, `from __future__ import print_function`是必须的 +3. 每个新的py文件都要求 加上 `from __future__ import absolute_import`. 因为python3不支持隐式的相对import. 详见[PR#74](https://github.com/python-cn/firefly/pull/74) +5. open文件请使用` io.open()` +5. 类都要继承object(新式类) +6. 模块和方法改变的列表以及一些其他的要注意的点可以看这里: http://docs.pythonsprints.com/python3_porting/py-porting.html + +### python -3 + +可以使用-3启动web. Python会warn一些信息告诉你那些东西可能在py3已经被废弃或者有更新的用法 + +```python +python -3 manage.py runserver +``` + +### 链接 + +1. http://techspot.zzzeek.org/2011/01/24/zzzeek-s-guide-to-python-3-porting/ +2. http://dabeaz.blogspot.com/2011/01/porting-py65-and-my-superboard-to.html +3. http://lucumr.pocoo.org/2010/2/11/porting-to-python-3-a-guide/ +4. http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/ From f63fa20179dd043536d404197fc75c1b1dc83f35 Mon Sep 17 00:00:00 2001 From: dongweiming Date: Sun, 31 May 2015 16:21:50 +0800 Subject: [PATCH 3/6] modify pythonista.md --- posts/pythonista.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/posts/pythonista.md b/posts/pythonista.md index 095a3c3..3db727e 100644 --- a/posts/pythonista.md +++ b/posts/pythonista.md @@ -17,13 +17,13 @@ python-china现在还是很冷清, 远没有ruby-china和cnodejs这些社区的 原因很简单, 相同性价比下人太难招了. 我记得有一天, 一个猎头找我, 聊得过程中发现她对python有很多偏见, 它觉得中国搞python的人也就那几百个.. 虽然是个特例, 还是让我很有感触. 来豆瓣之前, 上一家公司有十多个产品线, python只有2-3个. 我都要离职了才发现, 好几个人竟然一直以为我是做ruby的. 囧 -不记得在哪里看过, 程序员有三种表白: +不记得在哪里看过, 程序员有三种(我重新润色了一下): 1. 拿钱干活, 不爽就换 - 程序员只是一份工作 -2. 只要能实现功能就好, 学习进步太累了. 这年代做技术没有管理挣钱多, 技术搞得再好有什么用? 还不是买不起房. 这年代关键是你认识多少人. 能不能唬住粉丝儿和投资人 -3. 热爱程序本身的人, 这些人可能只有1%, 他们有目标的写程序, 他们愿意思考, 愿意听取正确地/更好的方法, 他们会热爱学习新的东西 - Geek +2. 只要能实现功能就好, 学习进步太累了. 这年代做技术没有管理挣钱多, 技术搞得再好有什么用? 还不是买不起房. 这年代关键是你认识多少人. 你是不是有眼光去一个能上市会让你暴富的公司, 能不能唬住粉丝儿和投资人. +3. 热爱程序本身的人, 这些人可能只有1%, 他们有目标的写程序, 他们愿意思考, 愿意听取正确地/更好的方法, 他们会热爱学习新的东西 -人们都会把大部分的功劳交给产品, 销售和管理者. 只是程序员这个职业情况相对还好. 虽然架构师这个位置来说, 第二种人反而更多. +在生活中绝大多数都是前2种人. 尤其是第二种,我是可以理解的, 因为人们都会把大部分的功劳交给产品, 销售和管理者. 再说2个例子吧. From 9f195a8de5a19f857afafcc80c6ade51b4f794c5 Mon Sep 17 00:00:00 2001 From: mozillazg Date: Wed, 1 Jul 2015 06:23:35 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=B7=98=E5=AE=9D?= =?UTF-8?q?=E6=BA=90=E5=AE=89=E8=A3=85=20sass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- posts/new.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/posts/new.md b/posts/new.md index 8bab150..d5355d8 100644 --- a/posts/new.md +++ b/posts/new.md @@ -72,10 +72,17 @@ PS: pre-commit请放心使用, 代码是我写的. 2. 其次需要安装ruby(我们会使用gem), 可以到官网 https://www.ruby-lang.org/ 下载安装 3. 配置firefly的开发环境 - cd firefly/static - sudo gem install sass - npm install - node_modules/grunt-cli/bin/grunt # 如果你不喜欢占用一个终端, 可以使用tmux或者screen + + $ cd firefly/static + $ gem sources --remove https://rubygems.org/ + $ gem sources -a https://ruby.taobao.org/ + $ gem sources -l + *** CURRENT SOURCES *** + + https://ruby.taobao.org + $ sudo gem install sass -V + $ npm install + $ node_modules/grunt-cli/bin/grunt # 如果你不喜欢占用一个终端, 可以使用tmux或者screen #### 填充测试数据 From cb201f08cfefcecb8db4b1c6c0aa11ca5103b332 Mon Sep 17 00:00:00 2001 From: dongweiming Date: Fri, 3 Jul 2015 10:44:16 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=88=91=E4=BB=AC?= =?UTF-8?q?=E5=AF=B9plim&react=E7=9A=84=E6=80=81=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 3 +++ posts/flow-and-standards.md | 3 +++ posts/new.md | 2 -- posts/used.md | 7 +++++++ posts/welcome.md | 2 +- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 79cf34b..cf55a2b 100644 --- a/index.html +++ b/index.html @@ -20,6 +20,9 @@ 我们也欢迎在算法/前端/设计方面有能力的同学们, 这个社区同样有很多东西等你来 +**WARNING** 我们最近在做plim->jinja2的迁移和嵌入react的工作,其他工作暂停迭代(防止新的代码造冲突). +具体讨论可见: [Issue92](https://github.com/python-cn/firefly/issues/92),开发详情请关注[trello](https://trello.com/b/JM2OEXPA/firefly) + 愿景: * 社区不是一个人的或者几个人写的, 而是很多人贡献代码产生的(包含基本的功能). diff --git a/posts/flow-and-standards.md b/posts/flow-and-standards.md index 20319af..77c0499 100644 --- a/posts/flow-and-standards.md +++ b/posts/flow-and-standards.md @@ -3,6 +3,9 @@ title: 开发流程&代码规范 假如你想参与firefly的开发, 请详细阅读此文. +**WARNING** 我们最近在做plim->jinja2的迁移和嵌入react的工作,其他工作暂停迭代(防止新的代码造冲突). +具体讨论可见: [Issue92](https://github.com/python-cn/firefly/issues/92),开发详情请关注[trello](https://trello.com/b/JM2OEXPA/firefly) + ### 说在前面的话 「再牛掰的人写的程序也会有bug. 」 diff --git a/posts/new.md b/posts/new.md index d5355d8..942167a 100644 --- a/posts/new.md +++ b/posts/new.md @@ -46,9 +46,7 @@ $cp firefly/local_settings.py.example firefly/local_settings.py # local_settings 库, oauth2等不适合放入版本库敏感数据,以及对一些配置项的自定义 $virtualenv venv # 在当前目录下生成一个venv目录, 这个目录就是你的虚拟环境 $source venv/bin/activate # 激活环境, 如果你想从这个环境中离开, 可以执行`deactivate` -$pip install -r requirements.txt # 安装firefly的python依赖 $pip install -r py2-requirements.txt # 假如你是用python2还需要安装这个依赖 -# 安装开发依赖, 不做开发不需要安装 $pip install -r dev-requirements.txt # 安装开发依赖 $pre-commit install -t pre-push # 假如你希望对flake8做本地检查可以安装这个git-hook. 以后每次你的push都会跑一遍对当前提交代码中的检查 ``` diff --git a/posts/used.md b/posts/used.md index 2dd83a9..1687179 100644 --- a/posts/used.md +++ b/posts/used.md @@ -29,6 +29,8 @@ firefly的数据库. 选择Mongodb就是因为社区在早期可能功能特性 firefly的模板, plim我个人觉得是一个被严重低估的基于mako的模板. 这里用它其实是示范原因. 给想用plim的人一个范例. +**UPDATE** 我们目前准备把它替换成jinja2 具体讨论可见: [Issue92](https://github.com/python-cn/firefly/issues/92),开发详情请关注[trello](https://trello.com/b/JM2OEXPA/firefly) + #### pygments [pygments](https://bitbucket.org/birkenfeld/pygments-main)也是[pocoo](http://www.pocoo.org/)团队的作品, 提供各种语言的语法高亮, 他是基本所有python开源项目做语法高亮的底层库. 它有非常好的文档 @@ -42,6 +44,11 @@ firefly的模板, plim我个人觉得是一个被严重低估的基于mako的模 ### 前端的 +#### react + +[react](https://github.com/facebook/react)可能是目前最火的前端框架. firefly组件都由react来支持. 具体讨论可见: [Issue92](https://github.com/python-cn/firefly/issues/92). +目前进行中, 欢迎有兴趣得人一起来做. + #### grunt [grunt](https://github.com/gruntjs/grunt)是一个javascript的任务处理器(用了才知道). firefly用来做代码更改自动执行sass, 重载页面, 代码压缩等 diff --git a/posts/welcome.md b/posts/welcome.md index 18db44d..b0cd08f 100644 --- a/posts/welcome.md +++ b/posts/welcome.md @@ -40,7 +40,7 @@ title: 欢迎入伙 目前想做的一些东西: 1. 一个有社交元素的python社区(firefly) -2. 给[pythoncn-slack](https://pythoncn.slack.com)写个被调戏的机器人 +2. 给[pythoncn-slack](https://pythoncn.slack.com)写个被调戏的机器人 - 完成: [slack_bot](https://github.com/python-cn/slack_bot) 3. 用react重写本手册 4. 一个使用markdown可预览的博客应用 5. 一个web框架 From e516a2fcaefdf048bdbc136a68c1d4f5aa581743 Mon Sep 17 00:00:00 2001 From: dongweiming Date: Thu, 9 Jul 2015 23:54:16 +0800 Subject: [PATCH 6/6] =?UTF-8?q?jinja2=E5=B7=B2=E7=BB=8F=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E4=BA=86plim?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 3 ++- posts/flow-and-standards.md | 2 +- posts/pythonista.md | 3 +++ posts/used.md | 6 +++--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index cf55a2b..0abcb82 100644 --- a/index.html +++ b/index.html @@ -20,7 +20,8 @@ 我们也欢迎在算法/前端/设计方面有能力的同学们, 这个社区同样有很多东西等你来 -**WARNING** 我们最近在做plim->jinja2的迁移和嵌入react的工作,其他工作暂停迭代(防止新的代码造冲突). +**WARNING** 我们最近在做嵌入react的工作,其他工作暂停迭代(防止新的代码造冲突). + 具体讨论可见: [Issue92](https://github.com/python-cn/firefly/issues/92),开发详情请关注[trello](https://trello.com/b/JM2OEXPA/firefly) 愿景: diff --git a/posts/flow-and-standards.md b/posts/flow-and-standards.md index 77c0499..c2e4bf6 100644 --- a/posts/flow-and-standards.md +++ b/posts/flow-and-standards.md @@ -3,7 +3,7 @@ title: 开发流程&代码规范 假如你想参与firefly的开发, 请详细阅读此文. -**WARNING** 我们最近在做plim->jinja2的迁移和嵌入react的工作,其他工作暂停迭代(防止新的代码造冲突). +**WARNING** 我们最近在做嵌入react的工作,其他工作暂停迭代(防止新的代码造冲突). 具体讨论可见: [Issue92](https://github.com/python-cn/firefly/issues/92),开发详情请关注[trello](https://trello.com/b/JM2OEXPA/firefly) ### 说在前面的话 diff --git a/posts/pythonista.md b/posts/pythonista.md index 3db727e..bb89603 100644 --- a/posts/pythonista.md +++ b/posts/pythonista.md @@ -25,6 +25,9 @@ python-china现在还是很冷清, 远没有ruby-china和cnodejs这些社区的 在生活中绝大多数都是前2种人. 尤其是第二种,我是可以理解的, 因为人们都会把大部分的功劳交给产品, 销售和管理者. +尤其是最近, 身边总是会有很多声音: 你要创业其实更多的不是技术, 而是balabala... 我是部分认同的: 我不认同的是过于放低技术对创业期间的作用. 我很难相信一个视野不够高度, +不够宽度的人去创业的成功几率. 想想我自己还是蛮low的(我知道我前端能力还不够) + 再说2个例子吧. 1. 最开始我是做运维的, 当时在学perl, 有个经验很丰富的c++同事看我痛苦的啃那一千一百多页的<大骆驼>, 善意的告诉我: `你只是用这个语言的20%去完成80%的工作, diff --git a/posts/used.md b/posts/used.md index 1687179..260dcdb 100644 --- a/posts/used.md +++ b/posts/used.md @@ -25,11 +25,11 @@ firefly的数据库. 选择Mongodb就是因为社区在早期可能功能特性 在使用ORM这个问题上一直有很大的争议. 我以前试验过, 使用ORM会减低3-5%的性能. 但是能让代码好看简单很多. 出现问题也很容易定位. 给想学想用它的人作为一个范例吧. -#### plim +#### Jinja2 -firefly的模板, plim我个人觉得是一个被严重低估的基于mako的模板. 这里用它其实是示范原因. 给想用plim的人一个范例. +早期firefly使用了plim, 但是由于要使用react,以及plim被大家接受程度, 我们还是换回了jinja2. -**UPDATE** 我们目前准备把它替换成jinja2 具体讨论可见: [Issue92](https://github.com/python-cn/firefly/issues/92),开发详情请关注[trello](https://trello.com/b/JM2OEXPA/firefly) +有兴趣可以看具体讨论: [Issue92](https://github.com/python-cn/firefly/issues/92),开发详情请关注[trello](https://trello.com/b/JM2OEXPA/firefly) #### pygments