shipit-cli 0.14.0__py3-none-any.whl → 0.15.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
shipit/providers/php.py CHANGED
@@ -1,8 +1,6 @@
1
- from __future__ import annotations
2
-
3
1
  import json
4
2
  from pathlib import Path
5
- from typing import Dict, Optional
3
+ from typing import Dict, Optional, Literal
6
4
 
7
5
  from .base import (
8
6
  DetectResult,
@@ -12,17 +10,35 @@ from .base import (
12
10
  MountSpec,
13
11
  ServiceSpec,
14
12
  VolumeSpec,
15
- CustomCommands,
13
+ Config,
16
14
  )
15
+ from pydantic_settings import SettingsConfigDict
16
+
17
+
18
+ class PhpConfig(Config):
19
+ model_config = SettingsConfigDict(extra="ignore", env_prefix="SHIPIT_")
20
+
21
+ use_composer: bool = False
22
+ php_version: Optional[str] = "8.3"
23
+ php_architecture: Optional[Literal["64-bit", "32-bit"]] = "64-bit"
17
24
 
18
25
 
19
26
  class PhpProvider:
20
- def __init__(self, path: Path, custom_commands: CustomCommands):
27
+ def __init__(self, path: Path, config: PhpConfig):
21
28
  self.path = path
22
- self.custom_commands = custom_commands
23
- self.has_composer = _exists(self.path, "composer.json", "composer.lock") or (
24
- custom_commands.install and custom_commands.install.startswith("composer ")
29
+ self.config = config
30
+
31
+ @classmethod
32
+ def load_config(cls, path: Path, base_config: Config) -> PhpConfig:
33
+ use_composer = (
34
+ _exists(path, "composer.json", "composer.lock")
35
+ or (
36
+ base_config.commands.install
37
+ and base_config.commands.install.startswith("composer ")
38
+ )
39
+ or False
25
40
  )
41
+ return PhpConfig(use_composer=use_composer, **base_config.model_dump())
26
42
 
27
43
  @classmethod
28
44
  def name(cls) -> str:
@@ -30,7 +46,7 @@ class PhpProvider:
30
46
 
31
47
  @classmethod
32
48
  def detect(
33
- cls, path: Path, custom_commands: CustomCommands
49
+ cls, path: Path, config: Config
34
50
  ) -> Optional[DetectResult]:
35
51
  if _exists(path, "composer.json") and _exists(path, "public/index.php"):
36
52
  return DetectResult(cls.name(), 60)
@@ -40,55 +56,46 @@ class PhpProvider:
40
56
  or _exists(path, "app/index.php")
41
57
  ):
42
58
  return DetectResult(cls.name(), 10)
43
- if custom_commands.start and custom_commands.start.startswith("php "):
59
+ if config.commands.start and config.commands.start.startswith("php "):
44
60
  return DetectResult(cls.name(), 70)
45
- if custom_commands.install and custom_commands.install.startswith("composer "):
61
+ if config.commands.install and config.commands.install.startswith("composer "):
46
62
  return DetectResult(cls.name(), 30)
47
63
  return None
48
64
 
49
- def initialize(self) -> None:
50
- pass
51
-
52
65
  def serve_name(self) -> Optional[str]:
53
66
  return None
54
67
 
55
- def platform(self) -> Optional[str]:
56
- return None
57
-
58
68
  def dependencies(self) -> list[DependencySpec]:
59
69
  deps = [
60
70
  DependencySpec(
61
71
  "php",
62
- env_var="SHIPIT_PHP_VERSION",
63
- default_version="8.3",
64
- architecture_var="SHIPIT_PHP_ARCHITECTURE",
72
+ var_name="config.php_version",
73
+ architecture_var_name="config.php_architecture",
65
74
  use_in_build=True,
66
75
  use_in_serve=True,
67
76
  ),
68
77
  ]
69
- if self.has_composer:
78
+ if self.config.use_composer:
70
79
  deps.append(DependencySpec("composer", use_in_build=True))
71
80
  deps.append(DependencySpec("bash", use_in_serve=True))
72
81
  return deps
73
82
 
74
83
  def declarations(self) -> Optional[str]:
75
- if self.has_composer:
76
- return 'HOME = getenv("HOME")\n'
77
84
  return None
78
85
 
79
86
  def build_steps(self) -> list[str]:
80
87
  steps = [
81
- 'workdir(app["build"])',
88
+ 'workdir(app.path)',
82
89
  ]
83
90
  if _exists(self.path, "php.ini"):
84
- steps.append('copy("php.ini", "{}/php.ini".format(assets["build"]))')
91
+ steps.append('copy("php.ini", "{}/php.ini".format(assets.path))')
85
92
  else:
86
93
  steps.append(
87
- 'copy("php/php.ini", "{}/php.ini".format(assets["build"]), base="assets")'
94
+ 'copy("php/php.ini", "{}/php.ini".format(assets.path), base="assets")'
88
95
  )
89
96
 
90
- if self.has_composer:
91
- steps.append('env(HOME=HOME, COMPOSER_FUND="0")')
97
+ if self.config.use_composer:
98
+ steps.append('env(COMPOSER_HOME="/tmp", COMPOSER_FUND="0")')
92
99
  steps.append(
93
100
  'run("composer install --optimize-autoloader --no-scripts --no-interaction", inputs=["composer.json", "composer.lock"], outputs=["."], group="install")'
94
101
  )
@@ -100,24 +107,21 @@ class PhpProvider:
100
107
  return None
101
108
 
102
109
  def commands(self) -> Dict[str, str]:
103
- commands = self.base_commands()
104
- if self.custom_commands.start:
105
- commands["start"] = json.dumps(self.custom_commands.start)
106
- return commands
110
+ return self.base_commands()
107
111
 
108
112
  def base_commands(self) -> Dict[str, str]:
109
113
  if _exists(self.path, "public/index.php"):
110
114
  return {
111
- "start": '"php -S localhost:{} -t {}/public".format(PORT, app["serve"])'
115
+ "start": '"php -S localhost:{} -t {}/public".format(PORT, app.serve_path)'
112
116
  }
113
117
  elif _exists(self.path, "app/index.php"):
114
118
  return {
115
- "start": '"php -S localhost:{} -t {}/app".format(PORT, app["serve"])'
119
+ "start": '"php -S localhost:{} -t {}/app".format(PORT, app.serve_path)'
116
120
  }
117
121
  elif _exists(self.path, "index.php"):
118
- return {"start": '"php -S localhost:{} -t {}".format(PORT, app["serve"])'}
122
+ return {"start": '"php -S localhost:{} -t {}".format(PORT, app.serve_path)'}
119
123
  return {
120
- "start": '"php -S localhost:{} -t {}".format(PORT, app["serve"])',
124
+ "start": '"php -S localhost:{} -t {}".format(PORT, app.serve_path)',
121
125
  }
122
126
 
123
127
  def mounts(self) -> list[MountSpec]:
@@ -131,7 +135,7 @@ class PhpProvider:
131
135
 
132
136
  def env(self) -> Optional[Dict[str, str]]:
133
137
  return {
134
- "PHP_INI_SCAN_DIR": '"{}".format(assets["serve"])',
138
+ "PHP_INI_SCAN_DIR": '"{}".format(assets.serve_path)',
135
139
  }
136
140
 
137
141
  def services(self) -> list[ServiceSpec]: