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

Dev environment enhancements #54

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig is awesome: https://editorconfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Rust and Python
[*.{py,rs}]
charset = utf-8
indent_style = space
indent_size = 4

# YAML
[*.yml]
indent_style = space
indent_size = 2
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
name: Release creation
# Release on PyPi if a realease is created

name: Release on PyPi

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
release:
types: [created]

env:
PYTHON_VERSION: "3.12"

jobs:
build-linux:
deploy:
if: github.repository_owner == 'trappitsch'
name: Release on PyPi
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install the latest version of rye
uses: eifinger/setup-rye@v2
uses: eifinger/setup-rye@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Sync Rye
Expand Down
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ docs = [
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.ruff]
target-version = "py38"

[tool.ruff.lint]
select = [
"A", # shadowing built-ins
"E", # style stuff, whitespaces
"F", # pyflakes lints
"I", # sorting
"N", # naming
"T100", # breakpoints
]

[tool.ruff.lint.isort]
known-first-party = ["box-packager", "box"]

[tool.ruff.lint.per-file-ignores]
"src/box/installer_utils/linux_hlp.py" = ["E501"]
"src/box/installer_utils/mac_hlp.py" = ["E501"]
"src/box/installer_utils/windows_hlp.py" = ["E501"]

[tool.rye]
managed = true
dev-dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion src/box/cleaner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Clean the project folder

from pathlib import Path
import shutil
from pathlib import Path

import box.formatters as fmt

Expand Down
8 changes: 5 additions & 3 deletions src/box/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import rich_click as click

import box
import box.formatters as fmt
import box.utils as ut
from box import env_vars
from box.cleaner import CleanProject
from box.config import uninitialize
from box.initialization import InitializeProject
from box.installer import CreateInstaller
import box.formatters as fmt
from box.packager import PackageApp
import box.utils as ut

CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])

Expand Down Expand Up @@ -45,7 +45,9 @@ def cli():
"--gui",
is_flag=True,
default=None,
help="Set the project as a GUI project. In quiet mode, this will default to `False`.",
help=(
"Set the project as a GUI project. In quiet mode, this will default to `False`."
),
)
@click.option("-e", "--entry", help="Set the app entry for the project.")
@click.option(
Expand Down
2 changes: 1 addition & 1 deletion src/box/env_vars.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Deal with setting and getting environmental variables. Getting all at once is handled in the `config.py`
# Deal with environmental variables.

from enum import Enum

Expand Down
4 changes: 2 additions & 2 deletions src/box/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import rich_click as click

from box.config import PyProjectParser, pyproject_writer
import box.formatters as fmt
from box.packager import PackageApp
import box.utils as ut
from box.config import PyProjectParser, pyproject_writer
from box.packager import PackageApp


class InitializeProject:
Expand Down
12 changes: 6 additions & 6 deletions src/box/installer.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Create an OS specific installer for GUI or CLI application.

import os
from pathlib import Path
import shutil
import subprocess
import sys
from pathlib import Path

import rich_click as click

from box import RELEASE_DIR_NAME
from box.config import PyProjectParser
import box.formatters as fmt
import box.utils as ut
from box import RELEASE_DIR_NAME
from box.config import PyProjectParser


class CreateInstaller:
Expand Down Expand Up @@ -322,11 +322,11 @@ def get_icon(suffix: str = None) -> Path:
):
continue

for dir in dirs:
if dir != "assets":
for my_dir in dirs:
if my_dir != "assets":
continue

icon_file = Path.cwd().joinpath(f"{root}/{dir}/icon")
icon_file = Path.cwd().joinpath(f"{root}/{my_dir}/icon")

if suffix:
suffixes = [suffix] # overwrite exisiting and only check this.
Expand Down
2 changes: 1 addition & 1 deletion src/box/installer_utils/mac_hlp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Helper functions to create Mac Installers

from pathlib import Path
import shutil
from pathlib import Path


def dmgbuild_settings(target_path: Path, name_pkg: str, icon: Path) -> dict:
Expand Down
10 changes: 5 additions & 5 deletions src/box/packager.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Build the project with PyApp

import os
import sys
from pathlib import Path
import shutil
import subprocess
import sys
import tarfile
from typing import List, Union
import urllib.request
from pathlib import Path
from typing import List, Union

import rich_click as click

from box import BUILD_DIR_NAME, RELEASE_DIR_NAME
from box.config import PyProjectParser
import box.formatters as fmt
import box.utils as ut
from box import BUILD_DIR_NAME, RELEASE_DIR_NAME
from box.config import PyProjectParser

PYAPP_SOURCE_URL = "https://github.com/ofek/pyapp/releases/"
PYAPP_SOURCE_NAME = "source.tar.gz"
Expand Down
10 changes: 5 additions & 5 deletions src/box/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Utility and helper functions

from contextlib import contextmanager
import os
from pathlib import Path
import subprocess
from contextlib import contextmanager
from pathlib import Path

from rich_click import ClickException

Expand Down Expand Up @@ -67,14 +67,14 @@ def is_windows() -> bool:


@contextmanager
def set_dir(dir: Path) -> None:
def set_dir(my_dir: Path) -> None:
"""Context manager to change directory to a specific one and then go back on exit.

:param dir: Folder to move to with `os.chdir`
:param my_dir: Folder to move to with `os.chdir`
"""
origin = Path.cwd()
try:
os.chdir(dir)
os.chdir(my_dir)
yield
finally:
os.chdir(origin)
5 changes: 2 additions & 3 deletions tests/cli/test_cli_clean.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# CLI tests for cleaning the project folder

from typing import List

from pathlib import Path
from typing import List

from click.testing import CliRunner
import pytest
from click.testing import CliRunner

from box.cli import cli

Expand Down
16 changes: 8 additions & 8 deletions tests/cli/test_cli_env.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Tests for setting environment variables with `box env ...`

from click.testing import CliRunner
import pytest
from click.testing import CliRunner

from box.cli import cli

Expand All @@ -15,11 +15,11 @@ def test_env_not_box_project(rye_project_no_box):
assert "not a box project" in result.output


@pytest.mark.parametrize("vars", [["PYAPP_SOMETHING", 1], ["TEST_ENV", "qerty"]])
def test_env_set(rye_project, vars):
@pytest.mark.parametrize("my_vars", [["PYAPP_SOMETHING", 1], ["TEST_ENV", "qerty"]])
def test_env_set(rye_project, my_vars):
"""Set some environments in the box project and ensure they are there."""
var = vars[0]
value = vars[1]
var = my_vars[0]
value = my_vars[1]

runner = CliRunner()
result = runner.invoke(cli, ["env", "--set", f"{var}={value}"])
Expand Down Expand Up @@ -139,21 +139,21 @@ def test_env_get(rye_project):

def test_env_list(rye_project):
"""List all environment variables set in the box project."""
vars = [["PYAPP_SOMETHING", 1], ["TEST_ENV", "qerty"]]
my_vars = [["PYAPP_SOMETHING", 1], ["TEST_ENV", "qerty"]]

runner = CliRunner()

result_none = runner.invoke(cli, ["env", "--list"])

for var, value in vars:
for var, value in my_vars:
runner.invoke(cli, ["env", "--set", f"{var}={value}"])
result_some = runner.invoke(cli, ["env", "--list"])

assert result_none.exit_code == 0
assert "No variables set" in result_none.output

assert result_some.exit_code == 0
for var, value in vars:
for var, value in my_vars:
assert var in result_some.output
assert f"{value}" in result_some.output

Expand Down
4 changes: 2 additions & 2 deletions tests/cli/test_cli_initialization.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Test initialization of a new project with CLI

from click.testing import CliRunner
import pytest
from click.testing import CliRunner

import box.utils as ut
from box.cli import cli
from box.config import PyProjectParser
from box.packager import PackageApp
import box.utils as ut


@pytest.mark.parametrize(
Expand Down
8 changes: 4 additions & 4 deletions tests/cli/test_cli_installer.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
### CLI tests for the installer

import os
import stat
import sys
from pathlib import Path
import stat
from unittest.mock import MagicMock, patch

from click.testing import CliRunner
import rich_click as click
import pytest
import rich_click as click
from click.testing import CliRunner

from box.cli import cli
from box import config
from box.cli import cli


def setup_mock_target_binary(path: Path, release_name: str) -> str:
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/test_cli_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import os
import shutil
import sys
from pathlib import Path
import urllib.request
from pathlib import Path

from click.testing import CliRunner
import pytest
from click.testing import CliRunner

from box.cli import cli

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Fixtures for pytest

import os
from pathlib import Path
import subprocess
from pathlib import Path

import pytest

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_pyproject_parser_basic_project(tmp_path_chdir):

def test_pyproject_parser_entry_point(tmp_path_chdir):
"""Try to get an entry point for the app from project.scripts."""
TOML_FILE = (
toml_file = (
TOML_BASIC_FILE
+ """

Expand All @@ -56,7 +56,7 @@ def test_pyproject_parser_entry_point(tmp_path_chdir):
"scripts": {"run": "my-app.app:run"},
}

tmp_path_chdir.joinpath("pyproject.toml").write_text(TOML_FILE)
tmp_path_chdir.joinpath("pyproject.toml").write_text(toml_file)
parser = PyProjectParser()
assert parser.possible_app_entries == possible_entries_exp

Expand Down Expand Up @@ -93,7 +93,7 @@ def test_pyproject_parser_env_vars(rye_project):


def test_pyproject_parser_env_vars_always_returns_dict(rye_project):
"""Ensure that the environment variable parser returns empty dict if key not there."""
"""Return empty dict if no environment variables key not there."""
parser = PyProjectParser()
ret_val = parser.env_vars
assert ret_val == {}
Expand Down
Loading
Loading