File tree 8 files changed +82
-79
lines changed
8 files changed +82
-79
lines changed Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ __pycache__
6
6
site
7
7
dist
8
8
* .egg-info
9
+ build
Original file line number Diff line number Diff line change 8
8
@rm -rf "py_database_url.egg-info"
9
9
10
10
tests : clean fmt lint
11
- @PYTHONPATH=py_database_url pytest --cov=py_database_url tests/
11
+ @pytest --cov=py_database_url
12
12
13
13
lint :
14
14
@pycodestyle --ignore=E501 .
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .base import parse
4
+ from .schemas import orator
5
+
6
+ __version__ = "0.0.4"
7
+
8
+ __all__ = ["parse" , "orator" ]
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ try :
4
+ # Python 3
5
+ from urllib .parse import urlparse
6
+
7
+ except ImportError :
8
+ # Python 2
9
+ from urlparse import urlparse
10
+
11
+
12
+ DEFAULT_ENV = "DATABASE_URL"
13
+
14
+
15
+ def parse (url = None ):
16
+ """
17
+ Parses a database URL.
18
+ """
19
+
20
+ if url :
21
+ return urlparse (url )
22
+
23
+ url = os .environ .get (DEFAULT_ENV )
24
+ return urlparse (url )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .base import parse
4
+
5
+
6
+ def orator (url = None , prefix = None ):
7
+ """
8
+ Function to parser for orator format.
9
+ """
10
+
11
+ url = parse (url )
12
+
13
+ config = {
14
+ f"{ url .scheme } " : {
15
+ "driver" : url .scheme ,
16
+ "host" : url .hostname ,
17
+ "database" : url .path [1 :],
18
+ "user" : url .username ,
19
+ "password" : url .password ,
20
+ "prefix" : prefix or "" ,
21
+ }
22
+ }
23
+
24
+ return config
Original file line number Diff line number Diff line change
1
+ import os
2
+ import re
3
+
1
4
from setuptools import find_packages , setup
2
5
6
+
7
+ def get_version (package ):
8
+ """
9
+ Return package version as listed in `__version__` in `init.py`.
10
+ """
11
+ init_py = open (os .path .join (package , "__init__.py" )).read ()
12
+ return re .search ("__version__ = ['\" ]([^'\" ]+)['\" ]" , init_py ).group (1 )
13
+
14
+
15
+ version = get_version ("py_database_url" )
16
+
17
+
3
18
setup (
4
19
name = "py-database-url" ,
5
20
description = "A universal database URLs for Python applications." ,
6
- version = "0.0.2" ,
21
+ version = version ,
7
22
url = "https://github.com/jairojair/py-database-url" ,
8
23
license = "MIT" ,
9
24
author = "Jairo Jair" ,
Original file line number Diff line number Diff line change 1
- import pytest
1
+ from py_database_url import parse , orator
2
2
3
- from py_database_url import config
4
3
5
-
6
- def test_config_without_url ():
7
-
8
- assert config .parse () is None
4
+ def test_parse_database_url_wrong ():
5
+ """
6
+ Describe
7
+ """
8
+ pass
9
9
10
10
11
11
def test_parse_database_url ():
@@ -15,7 +15,7 @@ def test_parse_database_url():
15
15
16
16
url = "postgres://user:password@hostname:5432/db-name"
17
17
18
- ret = config . parse (url )
18
+ ret = parse (url )
19
19
20
20
assert ret .username == "user"
21
21
assert ret .password == "password"
@@ -36,4 +36,4 @@ def test_config_database_url_orator():
36
36
}
37
37
}
38
38
39
- assert config . orator == expected
39
+ assert orator () == expected
You can’t perform that action at this time.
0 commit comments