Skip to content

Commit f183e76

Browse files
committed
[*] Fixed Python 2.7 support
1 parent 8188319 commit f183e76

File tree

7 files changed

+42
-15
lines changed

7 files changed

+42
-15
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Commands for modifying and controlling nginx over the command-line.
1010

1111
## Install dependencies
1212

13-
pip install -r requirements.txt
13+
python -m pip install -r requirements.txt
1414

1515
## Install package
1616

17-
pip install .
17+
python -m pip install .
1818

1919
## Usage
2020

@@ -62,8 +62,8 @@ Commands for modifying and controlling nginx over the command-line.
6262
--server_name 'localhost' --listen '8080' \
6363
-b location '/' \
6464
--root '/tmp/wwwroot' \
65-
-} \
66-
-}
65+
-'}' \
66+
-'}'
6767
nginx is running. Stop with: /usr/local/bin/nginx -c /tmp/nginx.conf -s stop
6868
$ curl -Is http://localhost:8080 | head -n1
6969
127.0.0.1 - - [03/Apr/2020:01:21:45 +1100] "HEAD / HTTP/1.1" 200 0 "-" "curl/7.64.1"

nginxctl/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import yaml
99

1010
__author__ = "Samuel Marks"
11-
__version__ = "0.0.12-alpha"
11+
__version__ = "0.0.12-beta"
1212

1313

1414
def get_logger(name=None):

nginxctl/__main__.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
from enum import Enum
99
from itertools import chain
1010
from operator import itemgetter
11-
from shutil import which
11+
if sys.version_info[0] == 2:
12+
from whichcraft import which
13+
from itertools import ifilter as filter
14+
else:
15+
from shutil import which
1216
from subprocess import Popen
1317

1418
import crossplane
1519

1620
from nginxctl import __version__, get_logger
17-
from nginxctl.helpers import strings, unquoted_str
21+
from nginxctl.helpers import strings, unquoted_str, rpartial
1822

1923
if sys.version[0] == "2":
2024
from tempfile import mkdtemp as gettemp
@@ -67,7 +71,7 @@ def _build_parser():
6771
default_nginx_usage = next(
6872
line for line in strings(default_nginx) if "set prefix path" in line
6973
).split()
70-
default_conf = next(filter(lambda s: s.endswith('nginx.conf)'), default_nginx_usage))[:-1]
74+
default_conf = next(filter(rpartial(str.endswith, 'nginx.conf)'), default_nginx_usage))[:-1]
7175
default_prefix = os.path.dirname(default_conf)
7276

7377
parser = ArgumentParser(

nginxctl/helpers.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
from string import printable
44
from sys import version_info
55

6+
if version_info[0] == 2:
7+
from codecs import open
8+
from string import maketrans
9+
else:
10+
maketrans = str.maketrans
11+
612
string_types = (basestring,) if version_info.major == 2 else (str,) # noqa: F821
713
pp = PrettyPrinter(indent=4).pprint
814

915

1016
def unquoted_str(arg):
11-
return arg.translate(str.maketrans(dict.fromkeys("'\"", "")))
17+
return arg.translate(maketrans(dict.fromkeys("'\"", "")))
1218

1319

1420
def update_d(d, arg=None, **kwargs):
@@ -106,6 +112,8 @@ def get_dict_by_key_val(obj, key, value):
106112
"get_dict_by_key_val for {!r} {}".format(type(obj), obj)
107113
)
108114

115+
def rpartial(func, *args):
116+
return lambda *a: func(*(a + args))
109117

110118
def strings(filename, minimum=4):
111119
with open(filename, errors="ignore") as f:

nginxctl/pkg_utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3+
from __future__ import print_function
4+
35
import ast
46
import csv
57
import inspect

requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
crossplane
22
boltons
3-
pyyaml!=6.0.0,!=5.4.0,!=5.4.1
3+
enum34; python_version <= '2.7'
4+
whichcraft; python_version <= '2.7'
45
meta
6+
pyyaml!=6.0.0,!=5.4.0,!=5.4.1

setup.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,40 @@ def to_funcs(*paths):
6767
name=package_name,
6868
author=__author__,
6969
version=__version__,
70-
install_requires=["pyyaml"],
70+
install_requires=["crossplane", "boltons", "meta", "pyyaml!=6.0.0,!=5.4.0,!=5.4.1"],
7171
test_suite=package_name + ".tests",
7272
packages=find_packages(),
7373
package_dir={package_name: package_name},
7474
classifiers=[
7575
"Development Status :: 3 - Alpha",
7676
"Environment :: Console",
7777
"Intended Audience :: Developers",
78-
"License :: OSI Approved",
78+
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
7979
"License :: OSI Approved :: Apache Software License",
8080
"License :: OSI Approved :: MIT License",
81+
"License :: OSI Approved",
8182
"Natural Language :: English",
8283
"Operating System :: OS Independent",
84+
"Programming Language :: Python :: Implementation",
8385
"Programming Language :: Python :: 2.7",
8486
"Programming Language :: Python :: 3",
85-
"Programming Language :: Python :: Implementation",
87+
"Programming Language :: Python :: 3.5",
88+
"Programming Language :: Python :: 3.6",
89+
"Programming Language :: Python :: 3.7",
90+
"Programming Language :: Python :: 3.8",
91+
"Programming Language :: Python :: 3.9",
92+
"Programming Language :: Python :: 3.10",
93+
"Programming Language :: Python :: 3.11",
94+
"Programming Language :: Python :: 3.12",
95+
"Programming Language :: Python :: 3.13",
96+
"Topic :: Internet :: Proxy Servers"
97+
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
8698
"Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator",
87-
"Topic :: Software Development",
8899
"Topic :: Software Development :: Build Tools",
89100
"Topic :: Software Development :: Code Generators",
90101
"Topic :: Software Development :: Compilers",
91102
"Topic :: Software Development :: Pre-processors",
92-
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
103+
"Topic :: Software Development",
93104
],
94105
data_files=[
95106
(_data_install_dir(), list(map(_data_join, listdir(_data_join())))),

0 commit comments

Comments
 (0)