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
13 changes: 6 additions & 7 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 @@ -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'
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
24 changes: 11 additions & 13 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.6", "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 @@ -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'
Expand All @@ -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

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

include_recipe: False
binary_relocation: False # Without that binaries are broken on Mac OS.

Expand All @@ -33,9 +32,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)
2 changes: 1 addition & 1 deletion jdk4py/lib_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
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
43 changes: 18 additions & 25 deletions scripts/set_versions.py
Original file line number Diff line number Diff line change
@@ -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)),
}
)
Loading