Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8bff839

Browse files
committed
Merge pull request ua-parser#27 from mattrobenolt/install
Fix install from sdist and bdist_wheel
2 parents 112eefc + 297b039 commit 8bff839

File tree

7 files changed

+30
-32
lines changed

7 files changed

+30
-32
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.pyc
2+
*.egg-info/
3+
.eggs/
4+
build/
5+
dist/
6+
tmp/
7+
regexes.yaml
8+
regexes.json

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
sudo: false
12
language: python
23
python:
34
- "2.6"
@@ -9,7 +10,8 @@ before_install:
910
- cp uap-core/regexes.yaml ua_parser/regexes.yaml
1011

1112
install:
12-
- pip install .
13+
- pip install pyyaml
14+
- pip install -e .
1315

1416
script:
1517
- python ua_parser/user_agent_parser_test.py

MANIFEST.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include ua_parser/regexes.yaml
2-
include ua_parser/regexes.json
1+
include README.md
2+
include ua_parser/regexes.json

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ test:
1515
@#python ua_parser/user_agent_parser_test.py ParseTest.testStringsDeviceBrandModel
1616

1717
clean:
18-
@rm ua_parser/user_agent_parser.pyc\
18+
@rm -f ua_parser/user_agent_parser.pyc\
1919
ua_parser/regexes.yaml\
2020
ua_parser/regexes.json
2121
@rm -rf tmp\
22-
ua_parser.egg-info
22+
ua_parser.egg-info\
23+
dist\
24+
build
2325

2426
.PHONY: all clean

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[bdist_wheel]
2+
universal = 1

setup.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,23 @@
22
from setuptools import setup
33
from setuptools.command.develop import develop as _develop
44
from setuptools.command.sdist import sdist as _sdist
5-
from setuptools.command.install import install as _install
65

76

87
def install_regexes():
98
print('Copying regexes.yaml to package directory...')
109
import os
11-
import shutil
1210
cwd = os.path.abspath(os.path.dirname(__file__))
1311
yaml_src = os.path.join(cwd, 'uap-core', 'regexes.yaml')
1412
if not os.path.exists(yaml_src):
1513
raise RuntimeError(
1614
'Unable to find regexes.yaml, should be at %r' % yaml_src)
17-
yaml_dest = os.path.join(cwd, 'ua_parser', 'regexes.yaml')
18-
shutil.copy2(yaml_src, yaml_dest)
1915

2016
print('Converting regexes.yaml to regexes.json...')
2117
import json
2218
import yaml
23-
json_dest = yaml_dest.replace('.yaml', '.json')
24-
regexes = yaml.safe_load(open(yaml_dest))
19+
json_dest = os.path.join(cwd, 'ua_parser', 'regexes.json')
20+
with open(yaml_src, 'rb') as fp:
21+
regexes = yaml.safe_load(fp)
2522
with open(json_dest, "w") as f:
2623
json.dump(regexes, f)
2724

@@ -38,11 +35,6 @@ def run(self):
3835
_sdist.run(self)
3936

4037

41-
class install(_install):
42-
def run(self):
43-
install_regexes()
44-
_install.run(self)
45-
4638
setup(
4739
name='ua-parser',
4840
version='0.5.0',
@@ -55,13 +47,12 @@ def run(self):
5547
zip_safe=False,
5648
url='https://github.com/ua-parser/uap-python',
5749
include_package_data=True,
58-
package_data={'ua_parser': ['regexes.yaml', 'regexes.json']},
50+
package_data={'ua_parser': ['regexes.json']},
5951
setup_requires=['pyyaml'],
60-
install_requires=['pyyaml'],
52+
install_requires=[],
6153
cmdclass={
6254
'develop': develop,
6355
'sdist': sdist,
64-
'install': install,
6556
},
6657
classifiers=[
6758
'Development Status :: 4 - Beta',

ua_parser/user_agent_parser.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -434,31 +434,24 @@ def GetFilters(user_agent_string, js_user_agent_string=None,
434434
if not UA_PARSER_YAML:
435435
try:
436436
from pkg_resources import resource_filename
437-
yamlPath = resource_filename(__name__, 'regexes.yaml')
438437
json_path = resource_filename(__name__, 'regexes.json')
439438
except ImportError:
440-
yamlPath = os.path.join(ROOT_DIR, 'regexes.yaml')
441439
json_path = os.path.join(ROOT_DIR, 'regexes.json')
442440
else:
441+
# This will raise an ImportError if missing, obviously since it's no
442+
# longer a requirement
443443
import yaml
444444

445445
with open(UA_PARSER_YAML) as yamlFile:
446446
regexes = yaml.safe_load(yamlFile)
447447

448448

449-
# If UA_PARSER_YAML is not specified, load regexes from regexes.json before
450-
# falling back to yaml format
449+
# If UA_PARSER_YAML is not specified, load regexes from regexes.json
451450
if regexes is None:
452-
try:
453-
import json
454-
455-
with open(json_path) as fp:
456-
regexes = json.load(fp)
457-
except IOError:
458-
import yaml
451+
import json
459452

460-
with open(yamlPath) as fp:
461-
regexes = yaml.safe_load(fp)
453+
with open(json_path) as fp:
454+
regexes = json.load(fp)
462455

463456

464457
USER_AGENT_PARSERS = []

0 commit comments

Comments
 (0)