Skip to content

Commit cdc026a

Browse files
author
Colossal Code
committed
Intial Commit
1 parent f140421 commit cdc026a

File tree

8 files changed

+347
-0
lines changed

8 files changed

+347
-0
lines changed

.gitignore

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
.idea/
6+
bin/
7+
version
8+
openapi_generator_cli/*.jar
9+
.DS_Store
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
32+
# PyInstaller
33+
# Usually these files are written by a python script from a template
34+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
35+
*.manifest
36+
*.spec
37+
38+
# Installer logs
39+
pip-log.txt
40+
pip-delete-this-directory.txt
41+
42+
# Unit test / coverage reports
43+
htmlcov/
44+
.tox/
45+
.coverage
46+
.coverage.*
47+
.cache
48+
nosetests.xml
49+
coverage.xml
50+
*.cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
63+
# Flask stuff:
64+
instance/
65+
.webassets-cache
66+
67+
# Scrapy stuff:
68+
.scrapy
69+
70+
# Sphinx documentation
71+
docs/_build/
72+
73+
# PyBuilder
74+
target/
75+
76+
# Jupyter Notebook
77+
.ipynb_checkpoints
78+
79+
# pyenv
80+
.python-version
81+
82+
# celery beat schedule file
83+
celerybeat-schedule
84+
85+
# SageMath parsed files
86+
*.sage.py
87+
88+
# Environments
89+
.env
90+
.venv
91+
env/
92+
venv/
93+
ENV/
94+
env.bak/
95+
venv.bak/
96+
97+
# Spyder project settings
98+
.spyderproject
99+
.spyproject
100+
101+
# Rope project settings
102+
.ropeproject
103+
104+
# mkdocs documentation
105+
/site
106+
107+
# mypy
108+
.mypy_cache/

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sudo: false
2+
3+
language: python
4+
5+
install:
6+
- pip install -r requirements.txt
7+
8+
script: python publish.py

LICENSE

100644100755
File mode changed.

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# OpenApi Generator PIP Package Generator
2+
3+
[![Join the Slack chat room](https://img.shields.io/badge/Slack-Join%20the%20chat%20room-orange)](https://join.slack.com/t/openapi-generator/shared_invite/enQtNzAyNDMyOTU0OTE1LTY5ZDBiNDI5NzI5ZjQ1Y2E5OWVjMjZkYzY1ZGM2MWQ4YWFjMzcyNDY5MGI4NjQxNDBiMTlmZTc5NjY2ZTQ5MGM)
4+
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
5+
6+
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and
7+
configuration automatically given an OpenAPI Spec (both 2.0 and 3.0 are supported). Please see
8+
[OpenAPITools/openapi-generator](https://github.com/OpenAPITools/openapi-generator)
9+
10+
---
11+
12+
This project checks the [maven repository](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-cli)
13+
once a day for a new version and will publish this new version automatically as a python package.
14+
15+
## Installation
16+
17+
You can install the package either in a virtual environment or globally.
18+
19+
```sh
20+
# install the latest version of "openapigenerator"
21+
pip install openapigenerator
22+
23+
# install a specific version of "openapigenerator"
24+
pip install openapigenerator==4.2.0
25+
```
26+
27+
After installation `openapi-generator` command will be available in your virtual environment or globally
28+
depending on your installation
29+
30+
To check the version, for example. Type the following command
31+
32+
```sh
33+
# this will print the correct version number
34+
openapi-generator version
35+
```
36+
37+
## Further Documentation
38+
39+
Please refer to the [official openapi-generator docs](https://github.com/OpenAPITools/openapi-generator#3---usage) for
40+
more information about the possible arguments and a detailed usage manual of the command line interface.
41+
42+
## Like the package?
43+
44+
Please leave a star.
45+
46+
## Have suggestions or feedback?
47+
48+
Please raise an issue, happy to hear from you :)

openapi_generator_cli/__init__.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# coding=utf-8
2+
# !/usr/bin/env python
3+
import os
4+
import subprocess
5+
import sys
6+
7+
8+
def run():
9+
arguments = ["java"]
10+
11+
if os.getenv("JAVA_OPTS"):
12+
arguments.append(os.getenv("JAVA_OPTS"))
13+
14+
arguments.append("-jar")
15+
16+
jar_path = os.path.join(
17+
os.path.dirname(os.path.realpath(__file__)), "openapi-generator.jar"
18+
)
19+
arguments.append(jar_path)
20+
21+
if len(sys.argv) > 1:
22+
arguments.extend(sys.argv[1:])
23+
24+
subprocess.call(" ".join(arguments), shell=True)

publish.py

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import os
2+
import subprocess
3+
4+
import requests
5+
6+
MVN_BASE_URL = "https://search.maven.org"
7+
8+
9+
def download_openapi_generator_jar(version):
10+
download_url = (
11+
MVN_BASE_URL
12+
+ "/remotecontent?filepath=org/openapitools/openapi-generator-cli/"
13+
+ version
14+
+ "/openapi-generator-cli-"
15+
+ version
16+
+ ".jar"
17+
)
18+
19+
if os.path.exists("openapi-generator.jar"):
20+
os.remove("openapi-generator.jar")
21+
22+
if os.path.exists("version"):
23+
os.remove("version")
24+
25+
print(download_url)
26+
response = requests.get(download_url)
27+
print("Downloading complete")
28+
29+
with open(
30+
"openapi_generator_cli/openapi-generator.jar", "wb"
31+
) as openapi_generator_jar:
32+
openapi_generator_jar.write(response.content)
33+
openapi_generator_jar.close()
34+
35+
with open("version", "w") as version_file:
36+
version_file.write(version)
37+
version_file.close()
38+
39+
40+
def get_available_versions():
41+
mvn_url = (
42+
MVN_BASE_URL
43+
+ "/solrsearch/select?q=g:org.openapitools+AND+a:openapi-generator-cli&core=gav"
44+
"&start=0&rows=200"
45+
)
46+
response = requests.get(mvn_url)
47+
docs = response.json()["response"]["docs"]
48+
return [doc["v"] for doc in docs]
49+
50+
51+
def get_published_vesions():
52+
pypi_url = "https://pypi.org/pypi/openapigenerator/json"
53+
response = requests.get(pypi_url)
54+
55+
if response.status_code == 404:
56+
return []
57+
58+
published_versions = response.json().get("releases").keys()
59+
return published_versions
60+
61+
62+
def publish():
63+
available_versions = get_available_versions()
64+
published_versions = get_published_vesions()
65+
66+
print("Available versions: " + str(available_versions))
67+
print("Published versions: " + str(published_versions))
68+
69+
versions_to_publish = set(available_versions) - set(published_versions)
70+
print(versions_to_publish)
71+
72+
for version in versions_to_publish:
73+
print("Publishing version " + version)
74+
download_openapi_generator_jar(version)
75+
subprocess.check_call("python setup.py upload", shell=True)
76+
77+
78+
if __name__ == "__main__":
79+
publish()

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests
2+
twine

setup.py

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# coding=utf-8
2+
import io
3+
import os
4+
import sys
5+
from shutil import rmtree
6+
7+
from setuptools import find_packages, setup, Command
8+
9+
NAME = "openapigenerator"
10+
DESCRIPTION = "CLI for openapi generator"
11+
URL = "https://github.com/OpenAPITools/openapi-generator"
12+
13+
AUTHOR = "OpenAPI Generator community"
14+
VERSION = open("version").read()
15+
EXTRAS = {}
16+
17+
here = os.path.abspath(os.path.dirname(__file__))
18+
19+
try:
20+
with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
21+
long_description = "\n" + f.read()
22+
except FileNotFoundError:
23+
long_description = DESCRIPTION
24+
25+
26+
class UploadCommand(Command):
27+
description = "Build and publish the package."
28+
user_options = []
29+
30+
@staticmethod
31+
def status(s):
32+
print("\033[1m{0}\033[0m".format(s))
33+
34+
def initialize_options(self):
35+
pass
36+
37+
def finalize_options(self):
38+
pass
39+
40+
def run(self):
41+
try:
42+
self.status("Removing previous builds…")
43+
rmtree(os.path.join(here, "dist"))
44+
except OSError:
45+
pass
46+
47+
self.status("Building Source and Wheel (universal) distribution…")
48+
os.system("{0} setup.py sdist bdist_wheel --universal".format(sys.executable))
49+
50+
self.status("Uploading the package to PyPI via Twine…")
51+
os.system("twine upload dist/*")
52+
53+
sys.exit()
54+
55+
56+
setup(
57+
name=NAME,
58+
version=VERSION,
59+
description=DESCRIPTION,
60+
long_description=long_description,
61+
long_description_content_type="text/markdown",
62+
author=AUTHOR,
63+
author_email=EMAIL,
64+
url=URL,
65+
packages=["openapi_generator_cli"],
66+
extras_require=EXTRAS,
67+
package_data={"openapi_generator_cli": ["*.jar"]},
68+
include_package_data=True,
69+
license="APACHE 2.0",
70+
classifiers=[
71+
"License :: OSI Approved :: Apache Software License",
72+
"Programming Language :: Python",
73+
"Programming Language :: Python :: Implementation :: CPython",
74+
"Programming Language :: Python :: Implementation :: PyPy",
75+
],
76+
cmdclass={"upload": UploadCommand},
77+
entry_points={"console_scripts": ["openapi-generator=openapi_generator_cli:run"]},
78+
)

0 commit comments

Comments
 (0)