From 7f01ef8d51cbdb69b42fccb6ae81afe58ff9d905 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 14:39:34 +0200 Subject: [PATCH 01/17] Rename master to main --- .github/workflows/deployment.yaml | 5 +++-- .github/workflows/test.yaml | 2 +- conda.recipe/meta.yaml | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index 8cdf055..f12387b 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -2,7 +2,7 @@ name: Deploy Conda and PyPI packages on: push: branches: - - master + - main jobs: deploy: @@ -112,7 +112,8 @@ jobs: name: Deploy to PyPI [Windows] env: TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} - run: | # Install twine with conda as poetry is broken after installing conda + run: + | # Install twine with conda as poetry is broken after installing conda conda install twine twine upload dist/jdk4py-*.whl --username __token__ --password ${env:TWINE_PASSWORD} - if: matrix.os != 'windows-latest' diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0dda93b..b8929d5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,7 +2,7 @@ name: Test on: pull_request: branches: - - master + - main jobs: test: diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 6211400..27c5910 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -33,9 +33,10 @@ about: home: https://github.com/atoti/jdk4py license: GNU General Public License v2.0 license_file: LICENSE - summary: 'Packaged JDK for Python.' + summary: Packaged JDK for Python. dev_url: https://github.com/atoti/jdk4py extra: recipe-maintainers: - fabiencelier + - tibdex From d26f4350dd281b1c4a8e9d249e0d1589cafa827e Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 14:39:46 +0200 Subject: [PATCH 02/17] Add license classifier --- setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 3943d99..0ea5aa3 100644 --- a/setup.py +++ b/setup.py @@ -50,9 +50,10 @@ packages=setuptools.find_packages(exclude=["tests"]), package_data={_NAME: [*_JAVA_FILES, _JAVA_VERSION_FILENAME, _JAVA_MAJOR_FILENAME, _LIB_VERSION_FILENAME]}, classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: OS Independent", "Development Status :: 4 - Beta", + "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", ], keywords=["jdk", "java", "jvm", "jre"], python_requires=">=3.7", From d91323715571e3605f6de8e9b677d0be9c830aca Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 14:51:39 +0200 Subject: [PATCH 03/17] Bump lib version --- conda.recipe/meta.yaml | 1 - jdk4py/lib_version.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 27c5910..64f1585 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -8,7 +8,6 @@ source: path: ../ build: - number: 0 include_recipe: False binary_relocation: False # Without that binaries are broken on Mac OS. diff --git a/jdk4py/lib_version.txt b/jdk4py/lib_version.txt index 573541a..d00491f 100644 --- a/jdk4py/lib_version.txt +++ b/jdk4py/lib_version.txt @@ -1 +1 @@ -0 +1 From 26c52770edaf81605062401ac5b27ce9985b5d8a Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 14:53:14 +0200 Subject: [PATCH 04/17] Test on Python 3.9 too --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b8929d5..5b3accf 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] - python: ["3.6", "3.7", "3.8"] + python: ["3.6", "3.7", "3.8", "3.9"] fail-fast: false # To not cancel other platforms when one fails name: Test on ${{ matrix.os }} with Python ${{ matrix.python }} steps: From a7381b2ecf94f7583776cce50922f5b7943e2e97 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 15:16:54 +0200 Subject: [PATCH 05/17] Make some improvements --- README.md | 8 ++++---- tests/test_jdk4py.py | 16 +++++----------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 11b2b19..a872d6c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A packaged JDK for Python. ## Install -Java is made easy to install as a single pip library: +Java is made easy to install as a single Python package: ```bash pip install jdk4py @@ -23,8 +23,8 @@ conda install jdk4py jdk4py version contains 4 figures: - - The first 3 figures are the Java version - - The fourth is jdk4py specific: it starts at 0 for each Java version and then increases. +- The first 3 figures are the Java version +- The fourth is jdk4py specific: it starts at 0 for each Java version and then increases. ## API @@ -35,7 +35,7 @@ from jdk4py import execute_jar execute_jar("myJar.jar") ``` -Some JVM arguments can be provided, any additional argument will be passed to Popen: +Some JVM arguments can be provided, any additional argument will be passed to `Popen`: ```python execute_jar("myJar.jar", jvm_args=["-xmx=16G"], stdout=PIPE, stderr=PIPE) diff --git a/tests/test_jdk4py.py b/tests/test_jdk4py.py index 399e607..b0f623d 100644 --- a/tests/test_jdk4py.py +++ b/tests/test_jdk4py.py @@ -1,32 +1,26 @@ from pathlib import Path from subprocess import PIPE +from jdk4py import JAVA, JAVA_HOME, JAVA_VERSION, MAJOR_JAVA_VERSION, execute_jar, java + _TESTS_DIRECTORY = Path(__file__).parent def test_java_version(): - from jdk4py import java, JAVA_VERSION - process = java(["--version"], stdout=PIPE, stderr=PIPE) out, err = process.communicate() + assert not err version = str(out).split("\n")[0].split(" ")[1] assert version[:version.rindex(".")] == JAVA_VERSION - assert err == b"" def test_major_java_version(): - from jdk4py import MAJOR_JAVA_VERSION - assert MAJOR_JAVA_VERSION == "11" def test_java_home(): - from jdk4py import JAVA, JAVA_HOME - assert JAVA == JAVA_HOME / "bin" / "java" def test_hello_world_jar(): - from jdk4py import execute_jar - # The JAR can be regenerated like that: # rm resources/*.class # rm resources/*.jar @@ -36,6 +30,6 @@ def test_hello_world_jar(): path = _TESTS_DIRECTORY / "resources" / "hello.jar" process = execute_jar(path.absolute(), stdout=PIPE, stderr=PIPE) out, err = process.communicate() - assert out == b"Hello, World\n" or out == b"Hello, World\r\n" - assert err == b"" + assert not err assert process.returncode == 0 + assert out == b"Hello, World\n" or out == b"Hello, World\r\n" From 80cbfbdce395e73c07847d64816c68f26088e5e0 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 15:17:29 +0200 Subject: [PATCH 06/17] Temporary commit --- tests/test_jdk4py.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_jdk4py.py b/tests/test_jdk4py.py index b0f623d..871f2d4 100644 --- a/tests/test_jdk4py.py +++ b/tests/test_jdk4py.py @@ -10,6 +10,7 @@ def test_java_version(): process = java(["--version"], stdout=PIPE, stderr=PIPE) out, err = process.communicate() assert not err + assert out == "bim" version = str(out).split("\n")[0].split(" ")[1] assert version[:version.rindex(".")] == JAVA_VERSION From 5c5c9376e69d84fdf6b910f6b79ac89d4a1aa79f Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 15:20:53 +0200 Subject: [PATCH 07/17] Java 11.0.11 --- jdk4py/java_version.txt | 2 +- jdk4py/lib_version.txt | 2 +- tests/test_jdk4py.py | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/jdk4py/java_version.txt b/jdk4py/java_version.txt index 771a7f0..2b689ad 100644 --- a/jdk4py/java_version.txt +++ b/jdk4py/java_version.txt @@ -1 +1 @@ -11.0.9 +11.0.11 diff --git a/jdk4py/lib_version.txt b/jdk4py/lib_version.txt index d00491f..573541a 100644 --- a/jdk4py/lib_version.txt +++ b/jdk4py/lib_version.txt @@ -1 +1 @@ -1 +0 diff --git a/tests/test_jdk4py.py b/tests/test_jdk4py.py index 871f2d4..b0f623d 100644 --- a/tests/test_jdk4py.py +++ b/tests/test_jdk4py.py @@ -10,7 +10,6 @@ def test_java_version(): process = java(["--version"], stdout=PIPE, stderr=PIPE) out, err = process.communicate() assert not err - assert out == "bim" version = str(out).split("\n")[0].split(" ")[1] assert version[:version.rindex(".")] == JAVA_VERSION From 080af640e0e7ba5e568b991fd91b07b38272f2ab Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 16:07:58 +0200 Subject: [PATCH 08/17] Try to fix test_java_version --- tests/test_jdk4py.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_jdk4py.py b/tests/test_jdk4py.py index b0f623d..096a3ef 100644 --- a/tests/test_jdk4py.py +++ b/tests/test_jdk4py.py @@ -11,10 +11,10 @@ def test_java_version(): out, err = process.communicate() assert not err version = str(out).split("\n")[0].split(" ")[1] - assert version[:version.rindex(".")] == JAVA_VERSION + assert version == JAVA_VERSION def test_major_java_version(): - assert MAJOR_JAVA_VERSION == "11" + assert MAJOR_JAVA_VERSION == JAVA_VERSION.split('.')[0] def test_java_home(): assert JAVA == JAVA_HOME / "bin" / "java" From 52a5c9c0b3a28d3768bdf7e8489b82147a4e0565 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 17:22:33 +0200 Subject: [PATCH 09/17] Make some improvements --- .github/workflows/deployment.yaml | 8 +++--- .github/workflows/test.yaml | 20 +++++++------- README.md | 2 +- jdk4py/__init__.py | 32 +++++++++-------------- jdk4py/java_version.txt | 2 +- jdk4py/major_java_version.txt | 1 - scripts/build_jdk.py | 14 +++++----- scripts/set_versions.py | 43 +++++++++++++------------------ setup.py | 39 ++++++++++++++++------------ tests/test_jdk4py.py | 4 +-- 10 files changed, 75 insertions(+), 90 deletions(-) delete mode 100644 jdk4py/major_java_version.txt diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index f12387b..80d5f6c 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -10,7 +10,6 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] - fail-fast: false # To not cancel other platforms when one fails name: Deploy on ${{ matrix.os }} env: JDK4PY_CONDA_CHANNEL: https://activeviam.jfrog.io/artifactory/jdk4py-conda-release @@ -25,11 +24,10 @@ jobs: - name: Set Java version run: python scripts/set_versions.py - - uses: joschi/setup-jdk@v2 # We must use to the official action once https://github.com/actions/setup-java/pull/97 is closed + - uses: actions/setup-java@v2 with: - java-version: ${{ env.MAJOR_JAVA_VERSION }} - java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk - architecture: x64 + distribution: adopt + java-version: ${{ env.JAVA_VERSION }} # Install Poetry - if: matrix.os == 'windows-latest' diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5b3accf..473a9b6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,7 +11,7 @@ jobs: matrix: os: [macos-latest, windows-latest, ubuntu-latest] python: ["3.6", "3.7", "3.8", "3.9"] - fail-fast: false # To not cancel other platforms when one fails + fail-fast: false name: Test on ${{ matrix.os }} with Python ${{ matrix.python }} steps: - uses: actions/checkout@v2 @@ -24,11 +24,10 @@ jobs: - name: Set Java version run: python scripts/set_versions.py - - uses: joschi/setup-jdk@v2 # We must use to the official action once https://github.com/actions/setup-java/pull/97 is closed + - uses: actions/setup-java@v2 with: - java-version: ${{ env.MAJOR_JAVA_VERSION }} - java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk - architecture: x64 + distribution: adopt + java-version: ${{ env.JAVA_VERSION }} # Install Poetry - if: matrix.os == 'windows-latest' @@ -47,9 +46,9 @@ jobs: - name: Test run: poetry run pytest - package: # only on latest Ubuntu and Python + package: runs-on: ubuntu-latest - name: Test packaging wheel and Conda + name: Test packaging Python wheel and Conda package steps: - uses: actions/checkout@v2 @@ -61,11 +60,10 @@ jobs: - name: Set Java version run: python scripts/set_versions.py - - uses: joschi/setup-jdk@v2 # We must use to the official action once https://github.com/actions/setup-java/pull/97 is closed + - uses: actions/setup-java@v2 with: - java-version: ${{ env.MAJOR_JAVA_VERSION }} - java-package: jdk - architecture: x64 + distribution: adopt + java-version: ${{ env.JAVA_VERSION }} - name: Install poetry run: pip3 install poetry diff --git a/README.md b/README.md index a872d6c..5178d96 100644 --- a/README.md +++ b/README.md @@ -54,5 +54,5 @@ The Java version can be checked with: ```python >>> from jdk4py import JAVA_VERSION >>> JAVA_VERSION -'11.0.2' +'11.0.9' ``` diff --git a/jdk4py/__init__.py b/jdk4py/__init__.py index 33181fb..b8fd137 100644 --- a/jdk4py/__init__.py +++ b/jdk4py/__init__.py @@ -1,53 +1,45 @@ """JDK packaged for Python.""" -from typing import Union, List, Optional, Any from pathlib import Path from subprocess import Popen +from typing import Any, Collection, Optional, Union _PACKAGE_DIRECTORY = Path(__file__).parent JAVA_HOME = _PACKAGE_DIRECTORY.absolute() / "java-runtime" JAVA = JAVA_HOME / "bin" / "java" -JAVA_VERSION, LIB_VERSION, MAJOR_JAVA_VERSION = ( +JAVA_VERSION, LIB_VERSION = ( (_PACKAGE_DIRECTORY / filename).read_text().strip() - for filename in ("java_version.txt", "lib_version.txt", "major_java_version.txt") + for filename in ("java_version.txt", "lib_version.txt") ) __version__ = ".".join((JAVA_VERSION, LIB_VERSION)) def java( - java_args: List[str], + jvm_args: Collection[str], **popen_args: Any, ) -> Popen: """Run a Java process with the given arguments. Args: - jvm_args: The Java arguments, for instance ["HelloWorls.class", "-Xmx16G"] - popen_args: Additional arguments to pass to the Popen - - Returns: - The Popen process + jvm_args: The Java arguments, for instance: ``["HelloWorls.class", "-Xmx16G"]``. + popen_args: Additional arguments to pass to ``Popen``. """ - return Popen([str(JAVA), *java_args], **popen_args) + return Popen([str(JAVA), *jvm_args], **popen_args) def execute_jar( jar_path: Union[Path, str], - jvm_args: Optional[List[str]] = None, + jvm_args: Optional[Collection[str]] = None, **popen_args: Any, ) -> Popen: """Execute a JAR file. Args: - jar_path: The path to the JAR file - jvm_args: The JVM arguments, for instance ["-Xmx16G", "-Xms2G"] - popen_args: Additional arguments to pass to the Popen - - Returns: - The Popen process + jar_path: The path to the JAR file. + jvm_args: The JVM arguments, for instance ``["-Xmx16G", "-Xms2G"]``. + popen_args: Additional arguments to pass to ``Popen``. """ - if jvm_args is None: - jvm_args = [] - return java(["-jar", str(jar_path), *jvm_args], **popen_args) + return java(["-jar", str(jar_path), *(jvm_args or [])], **popen_args) diff --git a/jdk4py/java_version.txt b/jdk4py/java_version.txt index 2b689ad..771a7f0 100644 --- a/jdk4py/java_version.txt +++ b/jdk4py/java_version.txt @@ -1 +1 @@ -11.0.11 +11.0.9 diff --git a/jdk4py/major_java_version.txt b/jdk4py/major_java_version.txt deleted file mode 100644 index b4de394..0000000 --- a/jdk4py/major_java_version.txt +++ /dev/null @@ -1 +0,0 @@ -11 diff --git a/scripts/build_jdk.py b/scripts/build_jdk.py index a381de0..f6e2092 100644 --- a/scripts/build_jdk.py +++ b/scripts/build_jdk.py @@ -1,10 +1,10 @@ -from subprocess import Popen, PIPE from pathlib import Path from shutil import rmtree +from subprocess import PIPE, Popen -PROJECT_FOLDER = Path(__file__).parent.parent -JAVA_PATH = PROJECT_FOLDER / "jdk4py" / "java-runtime" +_PROJECT_DIRECTORY = Path(__file__).parent.parent +_JAVA_PATH = _PROJECT_DIRECTORY / "jdk4py" / "java-runtime" _MODULES = [ "jdk.management.agent", @@ -13,12 +13,13 @@ "jdk.security.auth", "jdk.crypto.ec", "jdk.jfr", - "jdk.management.jfr" + "jdk.management.jfr", ] def build_java_executable_files(): - rmtree(JAVA_PATH, ignore_errors=True) + rmtree(_JAVA_PATH, ignore_errors=True) + process = Popen( [ "jlink", @@ -29,12 +30,13 @@ def build_java_executable_files(): "--add-modules", ",".join(_MODULES), "--output", - str(JAVA_PATH), + str(_JAVA_PATH), ], stdout=PIPE, stderr=PIPE, ) out, err = process.communicate() + if process.returncode == 0: print("Successfully built the Java executables.") return diff --git a/scripts/set_versions.py b/scripts/set_versions.py index 1885a8a..ba62d1d 100644 --- a/scripts/set_versions.py +++ b/scripts/set_versions.py @@ -1,36 +1,29 @@ -import os +from os import environ from pathlib import Path +from typing import Mapping _PROJECT_DIRECTORY = Path(__file__).parent.parent -_JDK4PY_DIRECTORY = _PROJECT_DIRECTORY / "jdk4py" -_MAJOR_JAVA_VERSION_FILENAME = "major_java_version.txt" +_SOURCE_DIRECTORY = _PROJECT_DIRECTORY / "jdk4py" _JAVA_VERSION_FILENAME = "java_version.txt" _LIB_VERSION_FILENAME = "lib_version.txt" -def set_env_variable_in_github_job(name: str, value: str): - # See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable. - with open(os.environ["GITHUB_ENV"], "a") as environment_file: - environment_file.write(f"{name}={value}\n") - -def set_java_version_env_variable_in_github_job(): - java_version = (_JDK4PY_DIRECTORY / _JAVA_VERSION_FILENAME).read_text().strip() - set_env_variable_in_github_job("JAVA_VERSION", java_version) +def set_env_variables_in_github_job(variables: Mapping[str, str]): + # See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable. + with open(environ["GITHUB_ENV"], "a") as environment_file: + for name, value in variables.items(): + environment_file.write(f"{name}={value}\n") -def set_major_java_version_env_variable_in_github_job(): # To be removed after https://github.com/actions/setup-java/pull/97 is closed - java_version = (_JDK4PY_DIRECTORY / _MAJOR_JAVA_VERSION_FILENAME).read_text().strip() - set_env_variable_in_github_job("MAJOR_JAVA_VERSION", java_version) -def set_jdk4py_version_env_variable_in_github_job(): - version = ".".join( - [ - (_JDK4PY_DIRECTORY / filename).read_text().strip() - for filename in (_JAVA_VERSION_FILENAME, _LIB_VERSION_FILENAME) - ] +if __name__ == "__main__": + java_version, lib_version = ( + (_SOURCE_DIRECTORY / filename).read_text().strip() + for filename in (_JAVA_VERSION_FILENAME, _LIB_VERSION_FILENAME) ) - set_env_variable_in_github_job("JDK4PY_VERSION", version) -if __name__ == "__main__": - set_java_version_env_variable_in_github_job() - set_jdk4py_version_env_variable_in_github_job() - set_major_java_version_env_variable_in_github_job() + set_env_variables_in_github_job( + { + "JAVA_VERSION": java_version, + "JDK4PY_VERSION": ".".join((java_version, lib_version)), + } + ) diff --git a/setup.py b/setup.py index 0ea5aa3..7182db0 100644 --- a/setup.py +++ b/setup.py @@ -1,27 +1,29 @@ -import glob -import setuptools -import sys - -from os import path, environ +from os import environ from pathlib import Path +from sys import argv + +from setuptools import find_packages, setup _NAME = "jdk4py" +_PROJECT_DIRECTORY = Path(__file__).parent + +_SOURCE_DIRECTORY = _PROJECT_DIRECTORY / _NAME -_JAVA_FILES = [ - str(Path(f).relative_to(_NAME)) - for f in glob.glob(path.join(_NAME, "java-runtime", "**"), recursive=True) +_JAVA_RUNTIME_FOLDER = "java-runtime" + +_JAVA_FILES = [_JAVA_RUNTIME_FOLDER] + [ + str(path.relative_to(_SOURCE_DIRECTORY)) + for path in (_SOURCE_DIRECTORY / _JAVA_RUNTIME_FOLDER).rglob("*") ] -_PROJECT_DIR = Path(__file__).parent _JAVA_VERSION_FILENAME = "java_version.txt" -_JAVA_MAJOR_FILENAME = "major_java_version.txt" _LIB_VERSION_FILENAME = "lib_version.txt" _PLATFORM_ENV_VARIABLE = "JDK4PY_BUILD_PLATFORM" _VERSION = ".".join( [ - (_PROJECT_DIR / _NAME / filename).read_text().strip() + (_SOURCE_DIRECTORY / filename).read_text().strip() for filename in (_JAVA_VERSION_FILENAME, _LIB_VERSION_FILENAME) ] ) @@ -32,13 +34,13 @@ "windows-latest": "win_amd64", } -if "--plat-name" not in sys.argv and _PLATFORM_ENV_VARIABLE in environ: +if "--plat-name" not in argv and _PLATFORM_ENV_VARIABLE in environ: machine = environ[_PLATFORM_ENV_VARIABLE] platform = _PLATFORMS[machine] - sys.argv.append("--plat-name") - sys.argv.append(platform) + argv.append("--plat-name") + argv.append(platform) -setuptools.setup( +setup_args = dict( name=_NAME, version=_VERSION, author="atoti", @@ -47,8 +49,8 @@ long_description=Path("README.md").read_text(), long_description_content_type="text/markdown", url="https://github.com/atoti/jdk4py", - packages=setuptools.find_packages(exclude=["tests"]), - package_data={_NAME: [*_JAVA_FILES, _JAVA_VERSION_FILENAME, _JAVA_MAJOR_FILENAME, _LIB_VERSION_FILENAME]}, + packages=find_packages(exclude=["tests"]), + package_data={_NAME: [*_JAVA_FILES, _JAVA_VERSION_FILENAME, _LIB_VERSION_FILENAME]}, classifiers=[ "Development Status :: 4 - Beta", "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", @@ -58,3 +60,6 @@ keywords=["jdk", "java", "jvm", "jre"], python_requires=">=3.7", ) + +if __name__ == "__main__": + setup(**setup_args) diff --git a/tests/test_jdk4py.py b/tests/test_jdk4py.py index 096a3ef..5828ecb 100644 --- a/tests/test_jdk4py.py +++ b/tests/test_jdk4py.py @@ -1,7 +1,7 @@ from pathlib import Path from subprocess import PIPE -from jdk4py import JAVA, JAVA_HOME, JAVA_VERSION, MAJOR_JAVA_VERSION, execute_jar, java +from jdk4py import JAVA, JAVA_HOME, JAVA_VERSION, execute_jar, java _TESTS_DIRECTORY = Path(__file__).parent @@ -13,8 +13,6 @@ def test_java_version(): version = str(out).split("\n")[0].split(" ")[1] assert version == JAVA_VERSION -def test_major_java_version(): - assert MAJOR_JAVA_VERSION == JAVA_VERSION.split('.')[0] def test_java_home(): assert JAVA == JAVA_HOME / "bin" / "java" From 037e4e23583242c92a1b8bfad30cb54176295d51 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 17:25:42 +0200 Subject: [PATCH 10/17] fixup! Make some improvements --- tests/test_jdk4py.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_jdk4py.py b/tests/test_jdk4py.py index 5828ecb..5eb9e98 100644 --- a/tests/test_jdk4py.py +++ b/tests/test_jdk4py.py @@ -11,7 +11,8 @@ def test_java_version(): out, err = process.communicate() assert not err version = str(out).split("\n")[0].split(" ")[1] - assert version == JAVA_VERSION + semver_version = version[: version.rindex(".")] + assert semver_version == JAVA_VERSION def test_java_home(): From 5d200def253c59bf71ef7e85faf243baad2d964b Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 17:32:36 +0200 Subject: [PATCH 11/17] Bump lib version --- jdk4py/lib_version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk4py/lib_version.txt b/jdk4py/lib_version.txt index 573541a..d00491f 100644 --- a/jdk4py/lib_version.txt +++ b/jdk4py/lib_version.txt @@ -1 +1 @@ -0 +1 From 1d15bfff6399aa72b589bea0ad6dc4af1688a0c2 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 18:01:46 +0200 Subject: [PATCH 12/17] Bump build number instead of lib version --- .github/workflows/deployment.yaml | 8 ++--- .github/workflows/test.yaml | 31 +++++++++++-------- conda.recipe/meta.yaml | 3 +- jdk4py/build_number.txt | 1 + jdk4py/lib_version.txt | 2 +- .../{set_versions.py => set_environment.py} | 7 ++--- 6 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 jdk4py/build_number.txt rename scripts/{set_versions.py => set_environment.py} (81%) diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index 80d5f6c..ca679e6 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -18,11 +18,11 @@ jobs: - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: 3.8 architecture: "x64" - - name: Set Java version - run: python scripts/set_versions.py + - name: Set environment variables + run: python scripts/set_environment.py - uses: actions/setup-java@v2 with: @@ -50,7 +50,7 @@ jobs: - name: Build wheel env: JDK4PY_BUILD_PLATFORM: ${{ matrix.os }} - run: poetry run python setup.py bdist_wheel + run: poetry run python setup.py bdist_wheel --build-number ${{ env.JDK4PY_BUILD_NUMBER }} - uses: actions/upload-artifact@v2 with: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 473a9b6..7065558 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -21,8 +21,8 @@ jobs: python-version: ${{ matrix.python }} architecture: "x64" - - name: Set Java version - run: python scripts/set_versions.py + - name: Set environment variables + run: python scripts/set_environment.py - uses: actions/setup-java@v2 with: @@ -43,12 +43,22 @@ jobs: - name: Build JDK run: poetry run python scripts/build_jdk.py + - name: Build wheel + env: + JDK4PY_BUILD_PLATFORM: ubuntu-latest + run: poetry run python setup.py bdist_wheel --build-number ${{ env.JDK4PY_BUILD_NUMBER }} + - name: Test run: poetry run pytest - package: + - uses: actions/upload-artifact@v2 + with: + name: jdk4py-${{ matrix.os }}.whl + path: dist/jdk4py-*.whl + + conda-package: runs-on: ubuntu-latest - name: Test packaging Python wheel and Conda package + name: Test Conda packaging steps: - uses: actions/checkout@v2 @@ -57,8 +67,8 @@ jobs: python-version: 3.8 architecture: "x64" - - name: Set Java version - run: python scripts/set_versions.py + - name: Set environment variables + run: python scripts/set_environment.py - uses: actions/setup-java@v2 with: @@ -74,15 +84,10 @@ jobs: - name: Build JDK run: poetry run python scripts/build_jdk.py - - name: Build wheel - env: - JDK4PY_BUILD_PLATFORM: ubuntu-latest - run: poetry run python setup.py bdist_wheel - - uses: conda-incubator/setup-miniconda@v2 with: channels: conda-forge conda-build-version: 3.20.0 - - name: Build Conda package on ubuntu and latest Python - run: conda build --output-folder dist . --no-anaconda-upload --debug + - name: Build Conda package + run: conda build --debug --no-anaconda-upload --output-folder dist . diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 64f1585..7b2c856 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -8,8 +8,9 @@ source: path: ../ build: + binary_relocation: False # Without that, binaries are broken on macOS. include_recipe: False - binary_relocation: False # Without that binaries are broken on Mac OS. + number: {{ environ.get('JDK4PY_BUILD_NUMBER') }} requirements: build: diff --git a/jdk4py/build_number.txt b/jdk4py/build_number.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/jdk4py/build_number.txt @@ -0,0 +1 @@ +1 diff --git a/jdk4py/lib_version.txt b/jdk4py/lib_version.txt index d00491f..573541a 100644 --- a/jdk4py/lib_version.txt +++ b/jdk4py/lib_version.txt @@ -1 +1 @@ -1 +0 diff --git a/scripts/set_versions.py b/scripts/set_environment.py similarity index 81% rename from scripts/set_versions.py rename to scripts/set_environment.py index ba62d1d..7c2aeb0 100644 --- a/scripts/set_versions.py +++ b/scripts/set_environment.py @@ -4,8 +4,6 @@ _PROJECT_DIRECTORY = Path(__file__).parent.parent _SOURCE_DIRECTORY = _PROJECT_DIRECTORY / "jdk4py" -_JAVA_VERSION_FILENAME = "java_version.txt" -_LIB_VERSION_FILENAME = "lib_version.txt" def set_env_variables_in_github_job(variables: Mapping[str, str]): @@ -16,14 +14,15 @@ def set_env_variables_in_github_job(variables: Mapping[str, str]): if __name__ == "__main__": - java_version, lib_version = ( + build_number, java_version, lib_version = ( (_SOURCE_DIRECTORY / filename).read_text().strip() - for filename in (_JAVA_VERSION_FILENAME, _LIB_VERSION_FILENAME) + for filename in ("build_number.txt", "java_version.txt", "lib_version.txt") ) set_env_variables_in_github_job( { "JAVA_VERSION": java_version, + "JDK4PY_BUILD_NUMBER": build_number, "JDK4PY_VERSION": ".".join((java_version, lib_version)), } ) From 1c57910d385039d7731b3bfafb7f1b27bd196cd5 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 18:05:22 +0200 Subject: [PATCH 13/17] fixup! Bump build number instead of lib version --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7065558..be949cf 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -53,7 +53,7 @@ jobs: - uses: actions/upload-artifact@v2 with: - name: jdk4py-${{ matrix.os }}.whl + name: jdk4py-${{ matrix.os }}-${{ matrix.python }}.whl path: dist/jdk4py-*.whl conda-package: From f6d1283de9e16f683c8d05f968b73430c28f4a9e Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 18:22:48 +0200 Subject: [PATCH 14/17] fixup! Bump build number instead of lib version --- .github/workflows/deployment.yaml | 16 ++++++++-------- .github/workflows/test.yaml | 12 +++++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index ca679e6..fef1b96 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -30,17 +30,17 @@ jobs: java-version: ${{ env.JAVA_VERSION }} # Install Poetry - - if: matrix.os == 'windows-latest' + - if: matrix.os == "windows-latest" name: Install Poetry [Windows] run: pip install poetry - - if: matrix.os != 'windows-latest' + - if: matrix.os != "windows-latest" name: Install Poetry [Ubuntu/macOS] run: pip3 install poetry - name: Install Python dependencies run: poetry install - - if: matrix.os == 'ubuntu-latest' + - if: matrix.os == "ubuntu-latest" name: Build source wheel run: poetry run python setup.py sdist @@ -72,7 +72,7 @@ jobs: # Deploy Conda package to artifactory. - name: Upload Conda package [Linux] - if: matrix.os == 'ubuntu-latest' + if: matrix.os == "ubuntu-latest" env: ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} @@ -84,7 +84,7 @@ jobs: done - name: Upload Conda package [macOS] - if: matrix.os == 'macos-latest' + if: matrix.os == "macos-latest" env: ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} @@ -96,7 +96,7 @@ jobs: done - name: Upload Conda package [Windows] - if: matrix.os == 'windows-latest' + if: matrix.os == "windows-latest" env: ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} @@ -106,7 +106,7 @@ jobs: curl --fail --user ${env:ARTIFACTORY_USERNAME}:${env:ARTIFACTORY_PASSWORD} "${env:JDK4PY_CONDA_CHANNEL}/win-64/" --upload-file "dist\win-64\jdk4py-${env:JDK4PY_VERSION}-py39_0.tar.bz2" # Deploy to PyPI - - if: matrix.os == 'windows-latest' + - if: matrix.os == "windows-latest" name: Deploy to PyPI [Windows] env: TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} @@ -114,7 +114,7 @@ jobs: | # Install twine with conda as poetry is broken after installing conda conda install twine twine upload dist/jdk4py-*.whl --username __token__ --password ${env:TWINE_PASSWORD} - - if: matrix.os != 'windows-latest' + - if: matrix.os != "windows-latest" name: Deploy to PyPI [Linux/macOS] env: TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index be949cf..50a1a0e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] - python: ["3.6", "3.7", "3.8", "3.9"] + python: ["3.7", "3.8", "3.9"] fail-fast: false name: Test on ${{ matrix.os }} with Python ${{ matrix.python }} steps: @@ -30,10 +30,10 @@ jobs: java-version: ${{ env.JAVA_VERSION }} # Install Poetry - - if: matrix.os == 'windows-latest' + - if: matrix.os == "windows-latest" name: Install poetry [Windows] run: pip install poetry - - if: matrix.os != 'windows-latest' + - if: matrix.os != "windows-latest" name: Install poetry [Ubuntu/macOS] run: pip3 install poetry @@ -51,9 +51,11 @@ jobs: - name: Test run: poetry run pytest - - uses: actions/upload-artifact@v2 + # No need to upload the package for each Python version + - if: matrix.python == "3.8" + uses: actions/upload-artifact@v2 with: - name: jdk4py-${{ matrix.os }}-${{ matrix.python }}.whl + name: jdk4py-${{ matrix.os }}.whl path: dist/jdk4py-*.whl conda-package: From d90f6607f803315eb22f9b9c0f66c9e1377a007d Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 18:23:55 +0200 Subject: [PATCH 15/17] Revert "fixup! Bump build number instead of lib version" This reverts commit f6d1283de9e16f683c8d05f968b73430c28f4a9e. --- .github/workflows/deployment.yaml | 16 ++++++++-------- .github/workflows/test.yaml | 12 +++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index fef1b96..ca679e6 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -30,17 +30,17 @@ jobs: java-version: ${{ env.JAVA_VERSION }} # Install Poetry - - if: matrix.os == "windows-latest" + - if: matrix.os == 'windows-latest' name: Install Poetry [Windows] run: pip install poetry - - if: matrix.os != "windows-latest" + - if: matrix.os != 'windows-latest' name: Install Poetry [Ubuntu/macOS] run: pip3 install poetry - name: Install Python dependencies run: poetry install - - if: matrix.os == "ubuntu-latest" + - if: matrix.os == 'ubuntu-latest' name: Build source wheel run: poetry run python setup.py sdist @@ -72,7 +72,7 @@ jobs: # Deploy Conda package to artifactory. - name: Upload Conda package [Linux] - if: matrix.os == "ubuntu-latest" + if: matrix.os == 'ubuntu-latest' env: ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} @@ -84,7 +84,7 @@ jobs: done - name: Upload Conda package [macOS] - if: matrix.os == "macos-latest" + if: matrix.os == 'macos-latest' env: ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} @@ -96,7 +96,7 @@ jobs: done - name: Upload Conda package [Windows] - if: matrix.os == "windows-latest" + if: matrix.os == 'windows-latest' env: ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} @@ -106,7 +106,7 @@ jobs: curl --fail --user ${env:ARTIFACTORY_USERNAME}:${env:ARTIFACTORY_PASSWORD} "${env:JDK4PY_CONDA_CHANNEL}/win-64/" --upload-file "dist\win-64\jdk4py-${env:JDK4PY_VERSION}-py39_0.tar.bz2" # Deploy to PyPI - - if: matrix.os == "windows-latest" + - if: matrix.os == 'windows-latest' name: Deploy to PyPI [Windows] env: TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} @@ -114,7 +114,7 @@ jobs: | # Install twine with conda as poetry is broken after installing conda conda install twine twine upload dist/jdk4py-*.whl --username __token__ --password ${env:TWINE_PASSWORD} - - if: matrix.os != "windows-latest" + - if: matrix.os != 'windows-latest' name: Deploy to PyPI [Linux/macOS] env: TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 50a1a0e..be949cf 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] - python: ["3.7", "3.8", "3.9"] + python: ["3.6", "3.7", "3.8", "3.9"] fail-fast: false name: Test on ${{ matrix.os }} with Python ${{ matrix.python }} steps: @@ -30,10 +30,10 @@ jobs: java-version: ${{ env.JAVA_VERSION }} # Install Poetry - - if: matrix.os == "windows-latest" + - if: matrix.os == 'windows-latest' name: Install poetry [Windows] run: pip install poetry - - if: matrix.os != "windows-latest" + - if: matrix.os != 'windows-latest' name: Install poetry [Ubuntu/macOS] run: pip3 install poetry @@ -51,11 +51,9 @@ jobs: - name: Test run: poetry run pytest - # No need to upload the package for each Python version - - if: matrix.python == "3.8" - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v2 with: - name: jdk4py-${{ matrix.os }}.whl + name: jdk4py-${{ matrix.os }}-${{ matrix.python }}.whl path: dist/jdk4py-*.whl conda-package: From bec15ca2931f46c96a9eae410f3377d4a58717ee Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 18:25:03 +0200 Subject: [PATCH 16/17] Fix workflow files --- .github/workflows/test.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index be949cf..5a9fdec 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] - python: ["3.6", "3.7", "3.8", "3.9"] + python: ["3.7", "3.8", "3.9"] fail-fast: false name: Test on ${{ matrix.os }} with Python ${{ matrix.python }} steps: @@ -51,7 +51,9 @@ jobs: - name: Test run: poetry run pytest - - uses: actions/upload-artifact@v2 + # No need to upload the package for each Python version + - if: matrix.python == '3.8' + uses: actions/upload-artifact@v2 with: name: jdk4py-${{ matrix.os }}-${{ matrix.python }}.whl path: dist/jdk4py-*.whl From 650e197895cc9f00b9c799d322e062589d835ef5 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Tue, 1 Jun 2021 18:25:33 +0200 Subject: [PATCH 17/17] fixup! Fix workflow files --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5a9fdec..2cac0cd 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -55,7 +55,7 @@ jobs: - if: matrix.python == '3.8' uses: actions/upload-artifact@v2 with: - name: jdk4py-${{ matrix.os }}-${{ matrix.python }}.whl + name: jdk4py-${{ matrix.os }}.whl path: dist/jdk4py-*.whl conda-package: