Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing license classifier #33

Merged
merged 17 commits into from
Jun 2, 2021
Merged
21 changes: 10 additions & 11 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ name: Deploy Conda and PyPI packages
on:
push:
branches:
- master
- main

jobs:
deploy:
runs-on: ${{ matrix.os }}
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
Expand All @@ -19,17 +18,16 @@ 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: 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'
Expand All @@ -52,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:
Expand Down Expand Up @@ -112,7 +110,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'
Expand Down
53 changes: 29 additions & 24 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: Test
on:
pull_request:
branches:
- master
- main

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
python: ["3.6", "3.7", "3.8"]
fail-fast: false # To not cancel other platforms when one fails
python: ["3.7", "3.8", "3.9"]
fail-fast: false
name: Test on ${{ matrix.os }} with Python ${{ matrix.python }}
steps:
- uses: actions/checkout@v2
Expand All @@ -21,14 +21,13 @@ 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: 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'
Expand All @@ -44,12 +43,24 @@ 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: # only on latest Ubuntu and Python
# 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 }}.whl
path: dist/jdk4py-*.whl

conda-package:
runs-on: ubuntu-latest
name: Test packaging wheel and Conda
name: Test Conda packaging
steps:
- uses: actions/checkout@v2

Expand All @@ -58,14 +69,13 @@ 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: 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
Expand All @@ -76,15 +86,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 .
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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'
```
7 changes: 4 additions & 3 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ source:
path: ../

build:
number: 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the build number ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because to be consistent, we should add one too here:

https://github.com/atoti/jdk4py/blob/8810e2faad3b7eb9fee980a99ce1ae686ea6e2a4/.github/workflows/deployment.yaml#L55

And make sure that they are kept in sync.

We could do this in a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, let's do it now and try to fix atoti/atoti#279 without having to publish a new version of atoti or fighting pip/poetry/conda to ignore the pinned version of jdk4py in atoti.

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:
Expand All @@ -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
32 changes: 12 additions & 20 deletions jdk4py/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions jdk4py/build_number.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 0 additions & 1 deletion jdk4py/major_java_version.txt

This file was deleted.

14 changes: 8 additions & 6 deletions scripts/build_jdk.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions scripts/set_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from os import environ
from pathlib import Path
from typing import Mapping

_PROJECT_DIRECTORY = Path(__file__).parent.parent
_SOURCE_DIRECTORY = _PROJECT_DIRECTORY / "jdk4py"


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")


if __name__ == "__main__":
build_number, java_version, lib_version = (
(_SOURCE_DIRECTORY / filename).read_text().strip()
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)),
}
)
Loading