Skip to content

Commit 54a564d

Browse files
committed
Format files in order 2 pull them into pyforchange
1 parent 54c8f54 commit 54a564d

File tree

124 files changed

+1087
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1087
-4
lines changed

.vscode/launch.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Docker: Python - General",
5+
"type": "docker",
6+
"request": "launch",
7+
"preLaunchTask": "docker-run: debug",
8+
"python": {
9+
"pathMappings": [
10+
{
11+
"localRoot": "${workspaceFolder}",
12+
"remoteRoot": "/app"
13+
}
14+
],
15+
"projectType": "general"
16+
}
17+
}
18+
]
19+
}

.vscode/tasks.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "docker-build",
6+
"label": "docker-build",
7+
"platform": "python",
8+
"dockerBuild": {
9+
"tag": "egg:latest",
10+
"dockerfile": "${workspaceFolder}/Dockerfile",
11+
"context": "${workspaceFolder}",
12+
"pull": true
13+
}
14+
},
15+
{
16+
"type": "docker-run",
17+
"label": "docker-run: debug",
18+
"dependsOn": [
19+
"docker-build"
20+
],
21+
"python": {
22+
"file": "egg\\app.py"
23+
}
24+
}
25+
]
26+
}
File renamed without changes.

MANIFEST.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
include README.md
2-
include LICENSE.txt
2+
include LICENSE
33
include examples/*
4+
include .vscode/*
5+
include github_com/*

examples/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<body>
3+
<h1>Hi</h1>
4+
<p>
5+
xd
6+
</p>
7+
</body>
8+
</html>

examples/main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pyforchange.egg import eggConsole
2+
3+
eggConsole()
4+
5+
"""
6+
document=Document("template")
7+
document.addTag("h1","Hi","aqui")
8+
document.write("xd","2")
9+
10+
covid=Repo("CovidPlot")
11+
cp=covid.pull("covidplot","CovidData")
12+
#pull("CovidPlot")
13+
covidata=cp.CovidData
14+
c=covidata()
15+
c.plot
16+
"""

examples/template.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<body>
3+
$egg aqui
4+
<p>
5+
$egg 2
6+
</p>
7+
</body>
8+
</html>

github_com/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Vladimir Iakovlev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

github_com/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Import from `github_com` (Please don't use it)
2+
3+
Experimental Python module finder/loader from github, like in golang.
4+
5+
So, in golang we can import like:
6+
7+
```go
8+
import "github.com/parnurzeal/gorequest"
9+
```
10+
11+
But in python we should install package by our hands:
12+
13+
```bash
14+
pip install requests
15+
```
16+
17+
And import it like:
18+
19+
```python
20+
import requests
21+
```
22+
23+
But with this magic package and power of [PEP-0302](https://www.python.org/dev/peps/pep-0302/) we can
24+
do it automatically:
25+
26+
```python
27+
from github_com.kennethreitz import requests
28+
29+
assert requests.get('https://github.com/nvbn/import_from_github_com').status_code == 200
30+
```
31+
32+
## Installation
33+
34+
You should have git, Python 3.2+ and pip:
35+
36+
```bash
37+
pip install import_from_github_com
38+
```
39+
40+
## License MIT
41+
Project License can be found [here](LICENSE).

github_com/__init__.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import sys
2+
import pip
3+
4+
5+
class IntermediateModule:
6+
"""Module for paths like `github_com.nvbn`."""
7+
8+
def __init__(self, fullname):
9+
self.__package__ = fullname
10+
self.__path__ = fullname.split('.')
11+
self.__name__ = fullname
12+
13+
14+
class GithubComFinder:
15+
"""Handles `github_com....` modules."""
16+
17+
def find_module(self, module_name, package_path):
18+
if module_name.startswith('github_com'):
19+
return GithubComLoader()
20+
21+
22+
class GithubComLoader:
23+
"""Installs and imports modules from github."""
24+
25+
def _is_installed(self, fullname):
26+
try:
27+
self._import_module(fullname)
28+
return True
29+
except ImportError:
30+
return False
31+
32+
def _import_module(self, fullname):
33+
actual_name = '.'.join(fullname.split('.')[2:])
34+
return __import__(actual_name)
35+
36+
def _install_module(self, fullname):
37+
if not self._is_installed(fullname):
38+
url = fullname.replace('.', '/') \
39+
.replace('github_com', 'git+https://github.com', 1)
40+
pip.main(['install', url])
41+
42+
def _is_repository_path(self, fullname):
43+
return fullname.count('.') == 2
44+
45+
def _is_intermediate_path(self, fullname):
46+
return fullname.count('.') < 2
47+
48+
def load_module(self, fullname):
49+
if self._is_repository_path(fullname):
50+
self._install_module(fullname)
51+
52+
if self._is_intermediate_path(fullname):
53+
module = IntermediateModule(fullname)
54+
else:
55+
module = self._import_module(fullname)
56+
57+
sys.modules[fullname] = module
58+
59+
60+
sys.meta_path.append(GithubComFinder())

0 commit comments

Comments
 (0)