Repository: googleapis/google-api-python-client

Issue:
pkg_resources.DistributionNotFound on v1.12.10
We are using bazel to build our app, and facing the following issue that is basically same with https://github.com/googleapis/google-api-python-client/issues/1622. 
I found #1622 was fixed by https://github.com/googleapis/google-api-python-client/pull/1623, but for some restriction on our environment, I cannot upgrade google-api-python-client to v2.x. 

May I create a pull request that apply the same fixes to the `v1` branch?

#### Environment details

Building a container image with Bazel python rules.

#### Code example

```python
from googleapiclient.model import JsonModel
```

#### Stack trace
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/app/googleapiclient/model.py", line 36, in <module>
    _LIBRARY_VERSION = pkg_resources.get_distribution("google-api-python-client").version
  File "/app/pkg_resources/__init__.py", line 466, in get_distribution
    dist = get_provider(dist)
  File "/app/pkg_resources/__init__.py", line 342, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/app/pkg_resources/__init__.py", line 886, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/app/pkg_resources/__init__.py", line 772, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'google-api-python-client' distribution was not found and is required by the application
```



Discussion:
Hello @kyohei3 ,

Yes, PRs are welcome!

Resolving patch:
diff --git a/googleapiclient/model.py b/googleapiclient/model.py
--- a/googleapiclient/model.py
+++ b/googleapiclient/model.py
@@ -27,13 +27,13 @@
 import json
 import logging
 import platform
-import pkg_resources
 
 from six.moves.urllib.parse import urlencode
 
+from googleapiclient import version as googleapiclient_version
 from googleapiclient.errors import HttpError
 
-_LIBRARY_VERSION = pkg_resources.get_distribution("google-api-python-client").version
+_LIBRARY_VERSION = googleapiclient_version.__version__
 _PY_VERSION = platform.python_version()
 
 LOGGER = logging.getLogger(__name__)
diff --git a/googleapiclient/version.py b/googleapiclient/version.py
new file mode 100644
--- /dev/null
+++ b/googleapiclient/version.py
@@ -0,0 +1,15 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+__version__ = "1.12.0" 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -53,7 +53,12 @@
 with io.open(readme_filename, encoding="utf-8") as readme_file:
     readme = readme_file.read()
 
-version = "1.12.10"
+package_root = os.path.abspath(os.path.dirname(__file__))
+
+version = {}
+with open(os.path.join(package_root, "googleapiclient/version.py")) as fp:
+    exec(fp.read(), version)
+version = version["__version__"]
 
 setup(
     name="google-api-python-client",


Test patch:
diff --git a/tests/test_json_model.py b/tests/test_json_model.py
--- a/tests/test_json_model.py
+++ b/tests/test_json_model.py
@@ -26,18 +26,18 @@
 import copy
 import json
 import os
-import pkg_resources
 import platform
 import unittest2 as unittest
 import httplib2
 import googleapiclient.model
 
+from googleapiclient import version as googleapiclient_version
 from googleapiclient.errors import HttpError
 from googleapiclient.model import JsonModel
 
 from six.moves.urllib.parse import parse_qs
 
-_LIBRARY_VERSION = pkg_resources.get_distribution("google-api-python-client").version
+_LIBRARY_VERSION = googleapiclient_version.__version__
 
 
 class Model(unittest.TestCase):