Skip to content

Commit

Permalink
fix(packaging): python module structure and dependencies (#29)
Browse files Browse the repository at this point in the history
Tracking issue: #28

- pin python-dateutil version to 2.8.1
- added python-dateutil as a dependency in setup.py
- added `__init__.py` in every directory under src/
- fixed README

Tests done:

```bash
# see https://packaging.python.org/tutorials/packaging-projects/#generating-distribution-archives
# this generates: google-events-0.1.1.tar.gz  google_events-0.1.1-py2.py3-none-any.whl under dist/
python3 setup.py sdist bdist_wheel

# install the package 
pip3 install dist/google_events-0.1.1-py2.py3-none-any.whl

# import successfully
Python 3.9.1 (default, Jan  5 2021, 14:05:22)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.events.cloud.pubsub.v1 import MessagePublishedData
>>> MessagePublishedData
<class 'google.events.cloud.pubsub.v1.MessagePublishedData.MessagePublishedData'>
>>>

```
  • Loading branch information
eclipselu committed Feb 22, 2021
1 parent 06075e0 commit 0d3b38b
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 53 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ At this moment the following types are available:
| Package | Python Class | Description |
| ------------- | ------------- | ------------- |
| google.events.cloud.scheduler.v1 | SchedulerJobData | Scheduler job data. |
| google.events.cloud.pubsub.v1 | MessagePublishedData | The event data when a message is published to a topic. |
| google.events.firebase.database.v1 | ReferenceEventData | The data within all Firebase Real Time Database reference events. |
| google.events.cloud.pubsub.v1 | MessagePublishedData | The event data when a message is published to a topic. |
| google.events.firebase.remoteconfig.v1 | RemoteConfigEventData | The data within all Firebase Remote Config events. |
| google.events.firebase.auth.v1 | AuthEventData | The data within all Firebase Auth events. |
| google.events.cloud.storage.v1 | StorageObjectData | An object within Google Cloud Storage. |
Expand All @@ -29,7 +29,7 @@ pip install --upgrade google-events
To use an event class, see the snippet below:

``` python
from google.events.cloud.pubsub.v1 import MessagePublishedEvent
from google.events.cloud.pubsub.v1 import MessagePublishedData

# Parses a Dict into an event
# The Dict may be an argument in a background Cloud Function,
Expand Down
25 changes: 23 additions & 2 deletions gen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const yargs = require('yargs');
const mkdirp = require('mkdirp');
const fs = require('fs');
const path = require('path')
const sqrl = require('squirrelly');

const qt = require('qt');
Expand All @@ -17,7 +18,7 @@ const INIT_PY_TEMPLATE = 'init_py.squirrelly';
const README_TEMPLATE = 'README.squirrelly';
const SETUP_PY_TEMPLATE = 'setup_py.squirrelly';
const DISCLAIMER_TEMPLATE = 'disclaimer';
const VERSION = '0.0.1';
const VERSION = '0.1.1';
const EXAMPLE_PATH_PREFIX = 'https://googleapis.github.io/google-cloudevents/testdata/';
const PY_TEST_TEMPLATE = 'pytest.squirrelly';
const PY_TEST_HELPER_TEMPLATE = 'pytest_helper.squirrelly';
Expand Down Expand Up @@ -62,7 +63,7 @@ async function main() {
`${OUT}/${SRC_DIRECTORY}/${pkgPath}/${eventName}.py`,
disclaimer + genFile
);

// Copy event data examples
const examplePaths: string[] = [];
for (const examplePath of schema.examples) {
Expand Down Expand Up @@ -102,6 +103,26 @@ async function main() {
});

// Write __init__.py scripts
// 1. Add empty __init__.py in each sub directory under src/
let allDirs: string[] = [];
const findAllSubdirs = (dir: string) => {
const files = fs.readdirSync(dir);
files.forEach((file: string) => {
var filepath = path.join(dir, file);
const stats = fs.statSync(filepath);
if (stats.isDirectory()) {
allDirs.push(filepath);
findAllSubdirs(filepath);
}
});
};
findAllSubdirs(path.join(OUT, SRC_DIRECTORY));
for (const dir of allDirs) {
const filename = path.join(dir, '__init__.py')
fs.closeSync(fs.openSync(filename, 'w'));
}

// 2. Write __init__.py in the innermost directories.
const initPySqrlTmpl = fs.readFileSync(
`${templateDirectoryPath}/${INIT_PY_TEMPLATE}`
);
Expand Down
2 changes: 1 addition & 1 deletion gen/templates/README.squirrelly
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pip install --upgrade google-events
To use an event class, see the snippet below:

``` python
from google.events.cloud.pubsub.v1 import MessagePublishedEvent
from google.events.cloud.pubsub.v1 import MessagePublishedData

# Parses a Dict into an event
# The Dict may be an argument in a background Cloud Function,
Expand Down
38 changes: 12 additions & 26 deletions gen/templates/setup_py.squirrelly
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
import io
import os
import re

from setuptools import find_packages, setup


name = "google-events"
description = "A collection of first party Google Cloud Platform event objects."
version = "{{ it.version }}"
release_status = "Development Status :: 3 - Alpha"
dependencies = []
extras = {
"dev": ["pylint", "pytest", "black"],
}

package_root = os.path.abspath(os.path.dirname(__file__))

readme_filename = os.path.join(package_root, "README.md")
with io.open(readme_filename, encoding="utf-8") as readme_file:
with open(readme_filename, encoding="utf-8") as readme_file:
readme = readme_file.read()

packages = find_packages("{{ it.srcDirectory }}")
package_dir = {"": "{{ it.srcDirectory }}"}

setup(
name=name,
version=version,
description=description,
name="google-events",
version="{{ it.version }}",
description="A collection of first party Google Cloud Platform event objects.",
long_description=readme,
long_description_content_type="text/markdown",
url="https://github.com/googleapis/google-cloudevents",
project_urls={
"Source": "https://github.com/googleapis/google-cloudevents",
"Documentation": "",
"Issue Tracker": "https://github.com/googleapis/google-cloudevents/issues",
"Source": "https://github.com/googleapis/google-cloudevents-python",
"Documentation": "https://github.com/googleapis/google-cloudevents-python",
"Issue Tracker": "https://github.com/googleapis/google-cloudevents-python/issues",
},
license="Apache License 2.0",
author="Google LLC",
author_email="googleapis-packages@oogle.com",
author_email="googleapis-packages@google.com",
classifiers=[
release_status,
"Environment :: Web Environment",
Expand All @@ -48,8 +33,9 @@ setup(
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
packages=packages,
package_dir=package_dir,
packages=find_packages("{{ it.srcDirectory }}"),
package_dir={"": "{{ it.srcDirectory }}"},
python_requires=">=3.7",
extras_require=extras,
install_requires=['python-dateutil==2.8.1'],
extras_require={"dev": ["pylint", "pytest", "black", "stringcase"]}
)
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-r requirements.txt
black==20.8b1
pylint==2.6.0
pytest==6.2.2
stringcase==1.2.0
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Required from types that reads/parses date and times (e.g. google.events.cloud.audit.v1.LogEntryData).
python-dateutil
python-dateutil==2.8.1
29 changes: 8 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import io
import os
import re

from setuptools import find_packages, setup


name = "google-events"
description = "A collection of first party Google Cloud Platform event objects."
version = "0.1.1"
release_status = "Development Status :: 3 - Alpha"
dependencies = []
extras = {
"dev": ["pylint", "pytest", "black"],
}

package_root = os.path.abspath(os.path.dirname(__file__))

readme_filename = os.path.join(package_root, "README.md")
with io.open(readme_filename, encoding="utf-8") as readme_file:
with open(readme_filename, encoding="utf-8") as readme_file:
readme = readme_file.read()

packages = find_packages("src")

setup(
name=name,
version=version,
description=description,
name="google-events",
version="0.1.1",
description="A collection of first party Google Cloud Platform event objects.",
long_description=readme,
long_description_content_type="text/markdown",
url="https://github.com/googleapis/google-cloudevents",
Expand All @@ -36,7 +22,7 @@
},
license="Apache License 2.0",
author="Google LLC",
author_email="googleapis-packages@oogle.com",
author_email="googleapis-packages@google.com",
classifiers=[
release_status,
"Environment :: Web Environment",
Expand All @@ -47,8 +33,9 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
packages=packages,
packages=find_packages("src"),
package_dir={"": "src"},
python_requires=">=3.7",
extras_require=extras,
install_requires=['python-dateutil==2.8.1'],
extras_require={"dev": ["pylint", "pytest", "black", "stringcase"]}
)
Empty file added src/google/__init__.py
Empty file.
Empty file added src/google/events/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 0d3b38b

Please sign in to comment.