Skip to content

Commit 015855d

Browse files
authored
Remove azure namespace (#506)
1 parent 4dbf726 commit 015855d

Some content is hidden

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

49 files changed

+73
-171
lines changed

.flake8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
ignore = W503,E402,E731
33
exclude =
44
.git, __pycache__, build, dist, .eggs, .github, .local, docs/,
5-
Samples, azure/functions_worker/protos/,
6-
azure/functions_worker/typing_inspect.py,
5+
Samples, azure_functions_worker/protos/,
6+
azure_functions_worker/typing_inspect.py,
77
tests/unittests/test_typing_inspect.py

azure/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

azure/functions_worker/protos/_src/src/proto/google/protobuf/duration.proto

Lines changed: 0 additions & 117 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from azure.functions_worker import main
1+
from azure_functions_worker import main
22

33
if __name__ == '__main__':
44
main.main()

azure/functions_worker/dispatcher.py renamed to azure_functions_worker/dispatcher.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import sys
1313
import importlib
14+
import inspect
1415

1516
import grpc
1617
import pkg_resources
@@ -366,6 +367,11 @@ async def _handle__function_environment_reload_request(self, req):
366367

367368
func_env_reload_request = req.function_environment_reload_request
368369

370+
# Import before clearing path cache so that the default
371+
# azure.functions modules is available in sys.modules for
372+
# customer use
373+
import azure.functions # NoQA
374+
369375
sys.path_importer_cache.clear()
370376

371377
os.environ.clear()
@@ -376,7 +382,23 @@ async def _handle__function_environment_reload_request(self, req):
376382
os.environ[var] = env_vars[var]
377383

378384
# Reload azure namespace for customer's libraries
379-
importlib.reload(sys.modules['azure'])
385+
try:
386+
logger.info('Reloading azure module')
387+
importlib.reload(sys.modules['azure'])
388+
except Exception as ex:
389+
logger.info('Unable to reload azure: \n{}'.format(ex))
390+
logger.info('Reloaded azure module')
391+
392+
# Reload azure.functions to give user package precedence
393+
logger.info('Reloading azure.functions module at %s',
394+
inspect.getfile(sys.modules['azure.functions']))
395+
try:
396+
importlib.reload(sys.modules['azure.functions'])
397+
logger.info('Reloaded azure.functions module now at %s',
398+
inspect.getfile(sys.modules['azure.functions']))
399+
except Exception as ex:
400+
logger.info('Unable to reload azure.functions. '
401+
'Using default. Exception:\n{}'.format(ex))
380402

381403
success_response = protos.FunctionEnvironmentReloadResponse(
382404
result=protos.StatusResult(
@@ -453,7 +475,7 @@ def gen(resp_queue):
453475
class AsyncLoggingHandler(logging.Handler):
454476

455477
def emit(self, record):
456-
if not record.name.startswith('azure.functions_worker'):
478+
if not record.name.startswith('azure_functions_worker'):
457479
# Skip worker system logs
458480
msg = self.format(record)
459481
Dispatcher.current._on_logging(record, msg)
File renamed without changes.

azure/functions_worker/logging.py renamed to azure_functions_worker/logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import sys
44

55

6-
logger = logging.getLogger('azure.functions_worker')
7-
error_logger = logging.getLogger('azure.functions_worker_errors')
6+
logger = logging.getLogger('azure_functions_worker')
7+
error_logger = logging.getLogger('azure_functions_worker_errors')
88

99

1010
def setup(log_level, log_destination):
File renamed without changes.

azure/functions_worker/testutils.py renamed to azure_functions_worker/testutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from . import protos
3535

3636

37-
PROJECT_ROOT = pathlib.Path(__file__).parent.parent.parent
37+
PROJECT_ROOT = pathlib.Path(__file__).parent.parent
3838
TESTS_ROOT = PROJECT_ROOT / 'tests'
3939
E2E_TESTS_FOLDER = pathlib.Path('endtoend')
4040
E2E_TESTS_ROOT = TESTS_ROOT / E2E_TESTS_FOLDER
File renamed without changes.

python/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from azure.functions_worker import main
1+
from azure_functions_worker import main
22

33
if __name__ == '__main__':
44
main.main()

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ warn_return_any = True
1313
disallow_subclassing_any = False
1414
ignore_missing_imports = True
1515

16-
[mypy-azure.functions_worker.aio_compat]
16+
[mypy-azure_functions_worker.aio_compat]
1717
ignore_errors = True
1818

19-
[mypy-azure.functions_worker.protos.*]
19+
[mypy-azure_functions_worker.protos.*]
2020
ignore_errors = True
2121

22-
[mypy-azure.functions_worker.typing_inspect]
22+
[mypy-azure_functions_worker.typing_inspect]
2323
ignore_errors = True

setup.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ class BuildGRPC:
7171
def _gen_grpc(self):
7272
root = pathlib.Path(os.path.abspath(os.path.dirname(__file__)))
7373

74-
proto_root_dir = root / 'azure' / 'functions_worker' / 'protos'
74+
proto_root_dir = root / 'azure_functions_worker' / 'protos'
7575
proto_src_dir = proto_root_dir / '_src' / 'src' / 'proto'
7676
staging_root_dir = root / 'build' / 'protos'
77-
staging_dir = (staging_root_dir / 'azure'
78-
/ 'functions_worker' / 'protos')
79-
build_dir = staging_dir / 'azure' / 'functions_worker' / 'protos'
77+
staging_dir = (staging_root_dir
78+
/ 'azure_functions_worker' / 'protos')
79+
build_dir = staging_dir / 'azure_functions_worker' / 'protos'
8080

8181
if os.path.exists(build_dir):
8282
shutil.rmtree(build_dir)
@@ -85,11 +85,11 @@ def _gen_grpc(self):
8585

8686
subprocess.run([
8787
sys.executable, '-m', 'grpc_tools.protoc',
88-
'-I', os.sep.join(('azure', 'functions_worker', 'protos')),
88+
'-I', os.sep.join(('azure_functions_worker', 'protos')),
8989
'--python_out', str(staging_root_dir),
9090
'--grpc_python_out', str(staging_root_dir),
91-
os.sep.join(('azure', 'functions_worker', 'protos',
92-
'azure', 'functions_worker', 'protos',
91+
os.sep.join(('azure_functions_worker', 'protos',
92+
'azure_functions_worker', 'protos',
9393
'FunctionRpc.proto')),
9494
], check=True, stdout=sys.stdout, stderr=sys.stderr,
9595
cwd=staging_root_dir)
@@ -216,9 +216,9 @@ def run(self):
216216
'Development Status :: 4 - Beta',
217217
],
218218
license='MIT',
219-
packages=['azure.functions_worker',
220-
'azure.functions_worker.protos',
221-
'azure.functions_worker.bindings'],
219+
packages=['azure_functions_worker',
220+
'azure_functions_worker.protos',
221+
'azure_functions_worker.bindings'],
222222
setup_requires=[
223223
'grpcio~=1.20.1',
224224
'grpcio-tools~=1.20.1',

tests/endtoend/test_blob_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22

3-
from azure.functions_worker import testutils
3+
from azure_functions_worker import testutils
44

55

66
class TestBlobFunctions(testutils.WebHostTestCase):

tests/endtoend/test_cosmosdb_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import time
33

4-
from azure.functions_worker import testutils
4+
from azure_functions_worker import testutils
55

66

77
class TestCosmosDBFunctions(testutils.WebHostTestCase):

tests/endtoend/test_eventgrid_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import unittest
44
import uuid
55

6-
from azure.functions_worker import testutils
6+
from azure_functions_worker import testutils
77

88

99
class TestEventGridFunctions(testutils.WebHostTestCase):

tests/endtoend/test_eventhub_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import time
33

4-
from azure.functions_worker import testutils
4+
from azure_functions_worker import testutils
55

66

77
class TestEventHubFunctions(testutils.WebHostTestCase):

tests/endtoend/test_queue_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22

3-
from azure.functions_worker import testutils
3+
from azure_functions_worker import testutils
44

55

66
class TestQueueFunctions(testutils.WebHostTestCase):

tests/endtoend/test_servicebus_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import time
33

4-
from azure.functions_worker import testutils
4+
from azure_functions_worker import testutils
55

66

77
class TestServiceBusFunctions(testutils.WebHostTestCase):

tests/endtoend/test_table_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pathlib
33
import time
44

5-
from azure.functions_worker import testutils
5+
from azure_functions_worker import testutils
66

77

88
class TestTableFunctions(testutils.WebHostTestCase):

tests/unittests/azure_namespace_import/azure_namespace_import.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import shutil
44
import asyncio
55

6-
from azure.functions_worker import protos
7-
from azure.functions_worker import testutils
6+
from azure_functions_worker import protos
7+
from azure_functions_worker import testutils
88

99

1010
async def vertify_nested_namespace_import():

tests/unittests/path_import/path_import.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import shutil
44
import asyncio
55

6-
from azure.functions_worker import protos
7-
from azure.functions_worker import testutils
6+
from azure_functions_worker import protos
7+
from azure_functions_worker import testutils
88

99

1010
async def verify_path_imports():

tests/unittests/test_broken_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from azure.functions_worker import protos
2-
from azure.functions_worker import testutils
1+
from azure_functions_worker import protos
2+
from azure_functions_worker import testutils
33

44

55
class TestMockHost(testutils.AsyncTestCase):

tests/unittests/test_code_quality.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_mypy(self):
1616

1717
try:
1818
subprocess.run(
19-
[sys.executable, '-m', 'mypy', '-m', 'azure.functions_worker'],
19+
[sys.executable, '-m', 'mypy', '-m', 'azure_functions_worker'],
2020
check=True,
2121
stdout=subprocess.PIPE,
2222
stderr=subprocess.PIPE,

tests/unittests/test_http_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import filecmp
44
import os
55

6-
from azure.functions_worker import testutils
6+
from azure_functions_worker import testutils
77

88

99
class TestHttpFunctions(testutils.WebHostTestCase):

0 commit comments

Comments
 (0)