pyobs-flipro 2.0.0.dev1__tar.gz → 2.0.0.dev2__tar.gz

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.
Files changed (21) hide show
  1. pyobs_flipro-2.0.0.dev2/.github/workflows/pypi.yml +26 -0
  2. pyobs_flipro-2.0.0.dev2/.github/workflows/ruff.yml +23 -0
  3. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/PKG-INFO +1 -1
  4. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/pyproject.toml +1 -1
  5. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/uv.lock +1 -1
  6. pyobs_flipro-2.0.0.dev1/.github/workflows/pypi.yml +0 -26
  7. pyobs_flipro-2.0.0.dev1/get-poetry.py +0 -958
  8. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/.pre-commit-config.yaml +0 -0
  9. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/.readthedocs.yml +0 -0
  10. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/CMakeLists.txt +0 -0
  11. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/LICENSE +0 -0
  12. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/README.md +0 -0
  13. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/lib/libflipro.h +0 -0
  14. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/lib/liblibflialgo.so +0 -0
  15. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/lib/liblibflipro.so +0 -0
  16. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/poetry.lock +0 -0
  17. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/pyobs_flipro/__init__.py +0 -0
  18. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/pyobs_flipro/fliprocamera.py +0 -0
  19. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/pyobs_flipro/fliprodriver.pyx +0 -0
  20. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/pyobs_flipro/gui.py +0 -0
  21. {pyobs_flipro-2.0.0.dev1 → pyobs_flipro-2.0.0.dev2}/pyobs_flipro/libflipro.pxd +0 -0
@@ -0,0 +1,26 @@
1
+ name: Publish package to PyPI
2
+ on:
3
+ push:
4
+ tags:
5
+ - 'v*'
6
+ jobs:
7
+ build-n-publish:
8
+ name: Build and publish package to PyPI
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Check out repository code
12
+ uses: actions/checkout@v4
13
+
14
+ - name: Set up Python
15
+ uses: astral-sh/setup-uv@v5
16
+ with:
17
+ enable-cache: true
18
+ python-version: "3.11"
19
+
20
+ - name: Build
21
+ run: uv build --sdist
22
+
23
+ - name: Publish
24
+ env:
25
+ PYPI_TOKEN: ${{ secrets.pypi_password }}
26
+ run: uv publish --token $PYPI_TOKEN
@@ -0,0 +1,23 @@
1
+ name: ruff
2
+ on: push
3
+
4
+ jobs:
5
+ ruff:
6
+ runs-on: ubuntu-latest
7
+ timeout-minutes: 10
8
+
9
+ steps:
10
+ - name: Check out repository code
11
+ uses: actions/checkout@v4
12
+
13
+ - name: Set up Python
14
+ uses: astral-sh/setup-uv@v5
15
+ with:
16
+ enable-cache: true
17
+ python-version: "3.13"
18
+
19
+ - name: Install packages
20
+ run: uv sync --all-extras --dev
21
+
22
+ - name: Run ruff
23
+ run: uv run ruff check pyobs_flipro/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyobs-flipro
3
- Version: 2.0.0.dev1
3
+ Version: 2.0.0.dev2
4
4
  Summary: pyobs module for FLIPRO cameras
5
5
  Author-Email: Tim-Oliver Husser <thusser@uni-goettingen.de>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyobs-flipro"
3
- version = "2.0.0.dev1"
3
+ version = "2.0.0.dev2"
4
4
  description = "pyobs module for FLIPRO cameras"
5
5
  authors = [{ name = "Tim-Oliver Husser", email = "thusser@uni-goettingen.de" }]
6
6
  requires-python = ">=3.11"
@@ -1738,7 +1738,7 @@ wheels = [
1738
1738
 
1739
1739
  [[package]]
1740
1740
  name = "pyobs-flipro"
1741
- version = "2.0.0.dev1"
1741
+ version = "2.0.0.dev2"
1742
1742
  source = { editable = "." }
1743
1743
  dependencies = [
1744
1744
  { name = "astropy" },
@@ -1,26 +0,0 @@
1
- name: Publish package to PyPI
2
- on:
3
- push:
4
- tags:
5
- - 'v*'
6
- jobs:
7
- build-n-publish:
8
- name: Build and publish package to PyPI
9
- runs-on: ubuntu-latest
10
- steps:
11
- - uses: actions/checkout@v2
12
- - name: Set up Python
13
- uses: actions/setup-python@v1
14
- with:
15
- python-version: "3.11"
16
- - name: Install poetry
17
- run: |
18
- curl -fsS -o get-poetry.py https://install.python-poetry.org
19
- python get-poetry.py -y
20
- - name: Publish
21
- env:
22
- PYPI_TOKEN: ${{ secrets.pypi_password }}
23
- run: |
24
- $HOME/.local/bin/poetry config pypi-token.pypi $PYPI_TOKEN
25
- $HOME/.local/bin/poetry build -f sdist
26
- $HOME/.local/bin/poetry publish
@@ -1,958 +0,0 @@
1
- #!/usr/bin/env python3
2
- r"""
3
- This script will install Poetry and its dependencies in an isolated fashion.
4
-
5
- It will perform the following steps:
6
- * Create a new virtual environment using the built-in venv module, or the virtualenv zipapp if venv is unavailable.
7
- This will be created at a platform-specific path (or `$POETRY_HOME` if `$POETRY_HOME` is set:
8
- - `~/Library/Application Support/pypoetry` on macOS
9
- - `$XDG_DATA_HOME/pypoetry` on Linux/Unix (`$XDG_DATA_HOME` is `~/.local/share` if unset)
10
- - `%APPDATA%\pypoetry` on Windows
11
- * Update pip inside the virtual environment to avoid bugs in older versions.
12
- * Install the latest (or a given) version of Poetry inside this virtual environment using pip.
13
- * Install a `poetry` script into a platform-specific path (or `$POETRY_HOME/bin` if `$POETRY_HOME` is set):
14
- - `~/.local/bin` on Unix
15
- - `%APPDATA%\Python\Scripts` on Windows
16
- * Attempt to inform the user if they need to add this bin directory to their `$PATH`, as well as how to do so.
17
- * Upon failure, write an error log to `poetry-installer-error-<hash>.log and restore any previous environment.
18
-
19
- This script performs minimal magic, and should be relatively stable. However, it is optimized for interactive developer
20
- use and trivial pipelines. If you are considering using this script in production, you should consider manually-managed
21
- installs, or use of pipx as alternatives to executing arbitrary, unversioned code from the internet. If you prefer this
22
- script to alternatives, consider maintaining a local copy as part of your infrastructure.
23
-
24
- For full documentation, visit https://python-poetry.org/docs/#installation.
25
- """
26
-
27
- import sys
28
-
29
- # Eager version check so we fail nicely before possible syntax errors
30
- if sys.version_info < (3, 6): # noqa: UP036
31
- sys.stdout.write("Poetry installer requires Python 3.6 or newer to run!\n")
32
- sys.exit(1)
33
-
34
-
35
- import argparse
36
- import json
37
- import os
38
- import re
39
- import shutil
40
- import subprocess
41
- import sysconfig
42
- import tempfile
43
-
44
- from contextlib import closing
45
- from contextlib import contextmanager
46
- from functools import cmp_to_key
47
- from io import UnsupportedOperation
48
- from pathlib import Path
49
- from typing import Optional
50
- from urllib.request import Request
51
- from urllib.request import urlopen
52
-
53
- SHELL = os.getenv("SHELL", "")
54
- WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt")
55
- MINGW = sysconfig.get_platform().startswith("mingw")
56
- MACOS = sys.platform == "darwin"
57
-
58
- FOREGROUND_COLORS = {
59
- "black": 30,
60
- "red": 31,
61
- "green": 32,
62
- "yellow": 33,
63
- "blue": 34,
64
- "magenta": 35,
65
- "cyan": 36,
66
- "white": 37,
67
- }
68
-
69
- BACKGROUND_COLORS = {
70
- "black": 40,
71
- "red": 41,
72
- "green": 42,
73
- "yellow": 43,
74
- "blue": 44,
75
- "magenta": 45,
76
- "cyan": 46,
77
- "white": 47,
78
- }
79
-
80
- OPTIONS = {"bold": 1, "underscore": 4, "blink": 5, "reverse": 7, "conceal": 8}
81
-
82
-
83
- def style(fg, bg, options):
84
- codes = []
85
-
86
- if fg:
87
- codes.append(FOREGROUND_COLORS[fg])
88
-
89
- if bg:
90
- codes.append(BACKGROUND_COLORS[bg])
91
-
92
- if options:
93
- if not isinstance(options, (list, tuple)):
94
- options = [options]
95
-
96
- for option in options:
97
- codes.append(OPTIONS[option])
98
-
99
- return "\033[{}m".format(";".join(map(str, codes)))
100
-
101
-
102
- STYLES = {
103
- "info": style("cyan", None, None),
104
- "comment": style("yellow", None, None),
105
- "success": style("green", None, None),
106
- "error": style("red", None, None),
107
- "warning": style("yellow", None, None),
108
- "b": style(None, None, ("bold",)),
109
- }
110
-
111
-
112
- def is_decorated():
113
- if WINDOWS:
114
- return (
115
- os.getenv("ANSICON") is not None
116
- or os.getenv("ConEmuANSI") == "ON" # noqa: SIM112
117
- or os.getenv("Term") == "xterm" # noqa: SIM112
118
- )
119
-
120
- if not hasattr(sys.stdout, "fileno"):
121
- return False
122
-
123
- try:
124
- return os.isatty(sys.stdout.fileno())
125
- except UnsupportedOperation:
126
- return False
127
-
128
-
129
- def is_interactive():
130
- if not hasattr(sys.stdin, "fileno"):
131
- return False
132
-
133
- try:
134
- return os.isatty(sys.stdin.fileno())
135
- except UnsupportedOperation:
136
- return False
137
-
138
-
139
- def colorize(style, text):
140
- if not is_decorated():
141
- return text
142
-
143
- return f"{STYLES[style]}{text}\033[0m"
144
-
145
-
146
- def string_to_bool(value):
147
- value = value.lower()
148
-
149
- return value in {"true", "1", "y", "yes"}
150
-
151
-
152
- def data_dir() -> Path:
153
- if os.getenv("POETRY_HOME"):
154
- return Path(os.getenv("POETRY_HOME")).expanduser()
155
-
156
- if WINDOWS:
157
- base_dir = Path(_get_win_folder("CSIDL_APPDATA"))
158
- elif MACOS:
159
- base_dir = Path("~/Library/Application Support").expanduser()
160
- else:
161
- base_dir = Path(os.getenv("XDG_DATA_HOME", "~/.local/share")).expanduser()
162
-
163
- base_dir = base_dir.resolve()
164
- return base_dir / "pypoetry"
165
-
166
-
167
- def bin_dir() -> Path:
168
- if os.getenv("POETRY_HOME"):
169
- return Path(os.getenv("POETRY_HOME")).expanduser() / "bin"
170
-
171
- if WINDOWS and not MINGW:
172
- return Path(_get_win_folder("CSIDL_APPDATA")) / "Python/Scripts"
173
- else:
174
- return Path("~/.local/bin").expanduser()
175
-
176
-
177
- def _get_win_folder_from_registry(csidl_name):
178
- import winreg as _winreg
179
-
180
- shell_folder_name = {
181
- "CSIDL_APPDATA": "AppData",
182
- "CSIDL_COMMON_APPDATA": "Common AppData",
183
- "CSIDL_LOCAL_APPDATA": "Local AppData",
184
- }[csidl_name]
185
-
186
- key = _winreg.OpenKey(
187
- _winreg.HKEY_CURRENT_USER,
188
- r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders",
189
- )
190
- path, _ = _winreg.QueryValueEx(key, shell_folder_name)
191
-
192
- return path
193
-
194
-
195
- def _get_win_folder_with_ctypes(csidl_name):
196
- import ctypes
197
-
198
- csidl_const = {
199
- "CSIDL_APPDATA": 26,
200
- "CSIDL_COMMON_APPDATA": 35,
201
- "CSIDL_LOCAL_APPDATA": 28,
202
- }[csidl_name]
203
-
204
- buf = ctypes.create_unicode_buffer(1024)
205
- ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf)
206
-
207
- # Downgrade to short path name if have highbit chars. See
208
- # <http://bugs.activestate.com/show_bug.cgi?id=85099>.
209
- has_high_char = False
210
- for c in buf:
211
- if ord(c) > 255:
212
- has_high_char = True
213
- break
214
- if has_high_char:
215
- buf2 = ctypes.create_unicode_buffer(1024)
216
- if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024):
217
- buf = buf2
218
-
219
- return buf.value
220
-
221
-
222
- if WINDOWS:
223
- try:
224
- from ctypes import windll # noqa: F401
225
-
226
- _get_win_folder = _get_win_folder_with_ctypes
227
- except ImportError:
228
- _get_win_folder = _get_win_folder_from_registry
229
-
230
-
231
- PRE_MESSAGE = """# Welcome to {poetry}!
232
-
233
- This will download and install the latest version of {poetry},
234
- a dependency and package manager for Python.
235
-
236
- It will add the `poetry` command to {poetry}'s bin directory, located at:
237
-
238
- {poetry_home_bin}
239
-
240
- You can uninstall at any time by executing this script with the --uninstall option,
241
- and these changes will be reverted.
242
- """
243
-
244
- POST_MESSAGE = """{poetry} ({version}) is installed now. Great!
245
-
246
- You can test that everything is set up by executing:
247
-
248
- `{test_command}`
249
- """
250
-
251
- POST_MESSAGE_NOT_IN_PATH = """{poetry} ({version}) is installed now. Great!
252
-
253
- To get started you need {poetry}'s bin directory ({poetry_home_bin}) in your `PATH`
254
- environment variable.
255
- {configure_message}
256
- Alternatively, you can call {poetry} explicitly with `{poetry_executable}`.
257
-
258
- You can test that everything is set up by executing:
259
-
260
- `{test_command}`
261
- """
262
-
263
- POST_MESSAGE_CONFIGURE_UNIX = """
264
- Add `export PATH="{poetry_home_bin}:$PATH"` to your shell configuration file.
265
- """
266
-
267
- POST_MESSAGE_CONFIGURE_FISH = """
268
- You can execute `set -U fish_user_paths {poetry_home_bin} $fish_user_paths`
269
- """
270
-
271
- POST_MESSAGE_CONFIGURE_WINDOWS = """
272
- You can choose and execute one of the following commands in PowerShell:
273
-
274
- A. Append the bin directory to your user environment variable `PATH`:
275
-
276
- ```
277
- [Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";{poetry_home_bin}", "User")
278
- ```
279
-
280
- B. Try to append the bin directory to PATH every when you run PowerShell (>=6 recommended):
281
-
282
- ```
283
- echo 'if (-not (Get-Command poetry -ErrorAction Ignore)) {{ $env:Path += ";{poetry_home_bin}" }}' | Out-File -Append $PROFILE
284
- ```
285
- """
286
-
287
-
288
- class PoetryInstallationError(RuntimeError):
289
- def __init__(self, return_code: int = 0, log: Optional[str] = None):
290
- super().__init__()
291
- self.return_code = return_code
292
- self.log = log
293
-
294
-
295
- class VirtualEnvironment:
296
- def __init__(self, path: Path) -> None:
297
- self._path = path
298
- self._bin_path = self._path.joinpath(
299
- "Scripts" if WINDOWS and not MINGW else "bin"
300
- )
301
- # str is for compatibility with subprocess.run on CPython <= 3.7 on Windows
302
- self._python = str(
303
- self._path.joinpath(self._bin_path, "python.exe" if WINDOWS else "python")
304
- )
305
-
306
- @property
307
- def path(self):
308
- return self._path
309
-
310
- @property
311
- def bin_path(self):
312
- return self._bin_path
313
-
314
- @classmethod
315
- def make(cls, target: Path) -> "VirtualEnvironment":
316
- if not sys.executable:
317
- raise ValueError(
318
- "Unable to determine sys.executable. Set PATH to a sane value or set it"
319
- " explicitly with PYTHONEXECUTABLE."
320
- )
321
-
322
- try:
323
- # on some linux distributions (eg: debian), the distribution provided python
324
- # installation might not include ensurepip, causing the venv module to
325
- # fail when attempting to create a virtual environment
326
- # we import ensurepip but do not use it explicitly here
327
- import ensurepip # noqa: F401
328
- import venv
329
-
330
- builder = venv.EnvBuilder(clear=True, with_pip=True, symlinks=False)
331
- context = builder.ensure_directories(target)
332
-
333
- if (
334
- WINDOWS
335
- and hasattr(context, "env_exec_cmd")
336
- and context.env_exe != context.env_exec_cmd
337
- ):
338
- target = target.resolve()
339
-
340
- builder.create(target)
341
- except ImportError:
342
- # fallback to using virtualenv package if venv is not available, eg: ubuntu
343
- python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
344
- virtualenv_bootstrap_url = (
345
- f"https://bootstrap.pypa.io/virtualenv/{python_version}/virtualenv.pyz"
346
- )
347
-
348
- with tempfile.TemporaryDirectory(prefix="poetry-installer") as temp_dir:
349
- virtualenv_pyz = Path(temp_dir) / "virtualenv.pyz"
350
- request = Request(
351
- virtualenv_bootstrap_url, headers={"User-Agent": "Python Poetry"}
352
- )
353
- virtualenv_pyz.write_bytes(urlopen(request).read())
354
- cls.run(
355
- sys.executable, virtualenv_pyz, "--clear", "--always-copy", target
356
- )
357
-
358
- # We add a special file so that Poetry can detect
359
- # its own virtual environment
360
- target.joinpath("poetry_env").touch()
361
-
362
- env = cls(target)
363
-
364
- # this ensures that outdated system default pip does not trigger older bugs
365
- env.pip("install", "--disable-pip-version-check", "--upgrade", "pip")
366
-
367
- return env
368
-
369
- @staticmethod
370
- def run(*args, **kwargs) -> subprocess.CompletedProcess:
371
- completed_process = subprocess.run(
372
- args,
373
- stdout=subprocess.PIPE,
374
- stderr=subprocess.STDOUT,
375
- **kwargs,
376
- )
377
- if completed_process.returncode != 0:
378
- raise PoetryInstallationError(
379
- return_code=completed_process.returncode,
380
- log=completed_process.stdout.decode(),
381
- )
382
- return completed_process
383
-
384
- def python(self, *args, **kwargs) -> subprocess.CompletedProcess:
385
- return self.run(self._python, *args, **kwargs)
386
-
387
- def pip(self, *args, **kwargs) -> subprocess.CompletedProcess:
388
- return self.python("-m", "pip", *args, **kwargs)
389
-
390
-
391
- class Cursor:
392
- def __init__(self) -> None:
393
- self._output = sys.stdout
394
-
395
- def move_up(self, lines: int = 1) -> "Cursor":
396
- self._output.write(f"\x1b[{lines}A")
397
-
398
- return self
399
-
400
- def move_down(self, lines: int = 1) -> "Cursor":
401
- self._output.write(f"\x1b[{lines}B")
402
-
403
- return self
404
-
405
- def move_right(self, columns: int = 1) -> "Cursor":
406
- self._output.write(f"\x1b[{columns}C")
407
-
408
- return self
409
-
410
- def move_left(self, columns: int = 1) -> "Cursor":
411
- self._output.write(f"\x1b[{columns}D")
412
-
413
- return self
414
-
415
- def move_to_column(self, column: int) -> "Cursor":
416
- self._output.write(f"\x1b[{column}G")
417
-
418
- return self
419
-
420
- def move_to_position(self, column: int, row: int) -> "Cursor":
421
- self._output.write(f"\x1b[{row + 1};{column}H")
422
-
423
- return self
424
-
425
- def save_position(self) -> "Cursor":
426
- self._output.write("\x1b7")
427
-
428
- return self
429
-
430
- def restore_position(self) -> "Cursor":
431
- self._output.write("\x1b8")
432
-
433
- return self
434
-
435
- def hide(self) -> "Cursor":
436
- self._output.write("\x1b[?25l")
437
-
438
- return self
439
-
440
- def show(self) -> "Cursor":
441
- self._output.write("\x1b[?25h\x1b[?0c")
442
-
443
- return self
444
-
445
- def clear_line(self) -> "Cursor":
446
- """
447
- Clears all the output from the current line.
448
- """
449
- self._output.write("\x1b[2K")
450
-
451
- return self
452
-
453
- def clear_line_after(self) -> "Cursor":
454
- """
455
- Clears all the output from the current line after the current position.
456
- """
457
- self._output.write("\x1b[K")
458
-
459
- return self
460
-
461
- def clear_output(self) -> "Cursor":
462
- """
463
- Clears all the output from the cursors' current position
464
- to the end of the screen.
465
- """
466
- self._output.write("\x1b[0J")
467
-
468
- return self
469
-
470
- def clear_screen(self) -> "Cursor":
471
- """
472
- Clears the entire screen.
473
- """
474
- self._output.write("\x1b[2J")
475
-
476
- return self
477
-
478
-
479
- class Installer:
480
- METADATA_URL = "https://pypi.org/pypi/poetry/json"
481
- VERSION_REGEX = re.compile(
482
- r"v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?"
483
- "("
484
- "[._-]?"
485
- r"(?:(stable|beta|b|rc|RC|alpha|a|patch|pl|p)((?:[.-]?\d+)*)?)?"
486
- "([.-]?dev)?"
487
- ")?"
488
- r"(?:\+[^\s]+)?"
489
- )
490
-
491
- def __init__(
492
- self,
493
- version: Optional[str] = None,
494
- preview: bool = False,
495
- force: bool = False,
496
- accept_all: bool = False,
497
- git: Optional[str] = None,
498
- path: Optional[str] = None,
499
- ) -> None:
500
- self._version = version
501
- self._preview = preview
502
- self._force = force
503
- self._accept_all = accept_all
504
- self._git = git
505
- self._path = path
506
-
507
- self._cursor = Cursor()
508
- self._bin_dir = None
509
- self._data_dir = None
510
-
511
- @property
512
- def bin_dir(self) -> Path:
513
- if not self._bin_dir:
514
- self._bin_dir = bin_dir()
515
- return self._bin_dir
516
-
517
- @property
518
- def data_dir(self) -> Path:
519
- if not self._data_dir:
520
- self._data_dir = data_dir()
521
- return self._data_dir
522
-
523
- @property
524
- def version_file(self) -> Path:
525
- return self.data_dir.joinpath("VERSION")
526
-
527
- def allows_prereleases(self) -> bool:
528
- return self._preview
529
-
530
- def run(self) -> int:
531
- if self._git:
532
- version = self._git
533
- elif self._path:
534
- version = self._path
535
- else:
536
- try:
537
- version, _current_version = self.get_version()
538
- except ValueError:
539
- return 1
540
-
541
- if version is None:
542
- return 0
543
-
544
- self.display_pre_message()
545
- self.ensure_directories()
546
-
547
- def _is_self_upgrade_supported(x):
548
- mx = self.VERSION_REGEX.match(x)
549
-
550
- if mx is None:
551
- # the version is not semver, perhaps scm or file
552
- # we assume upgrade is supported
553
- return True
554
-
555
- vx = (*tuple(int(p) for p in mx.groups()[:3]), mx.group(5))
556
- return vx >= (1, 1, 7)
557
-
558
- if version and not _is_self_upgrade_supported(version):
559
- self._write(
560
- colorize(
561
- "warning",
562
- f"You are installing {version}. When using the current installer, "
563
- "this version does not support updating using the 'self update' "
564
- "command. Please use 1.1.7 or later.",
565
- )
566
- )
567
- if not self._accept_all:
568
- continue_install = input("Do you want to continue? ([y]/n) ") or "y"
569
- if continue_install.lower() in {"n", "no"}:
570
- return 0
571
-
572
- try:
573
- self.install(version)
574
- except subprocess.CalledProcessError as e:
575
- raise PoetryInstallationError(
576
- return_code=e.returncode, log=e.output.decode()
577
- ) from e
578
-
579
- self._write("")
580
- self.display_post_message(version)
581
-
582
- return 0
583
-
584
- def install(self, version):
585
- """
586
- Installs Poetry in $POETRY_HOME.
587
- """
588
- self._write(
589
- "Installing {} ({})".format(
590
- colorize("info", "Poetry"), colorize("info", version)
591
- )
592
- )
593
-
594
- with self.make_env(version) as env:
595
- self.install_poetry(version, env)
596
- self.make_bin(version, env)
597
- self.version_file.write_text(version)
598
- self._install_comment(version, "Done")
599
-
600
- return 0
601
-
602
- def uninstall(self) -> int:
603
- if not self.data_dir.exists():
604
- self._write(
605
- "{} is not currently installed.".format(colorize("info", "Poetry"))
606
- )
607
-
608
- return 1
609
-
610
- version = None
611
- if self.version_file.exists():
612
- version = self.version_file.read_text().strip()
613
-
614
- if version:
615
- self._write(
616
- "Removing {} ({})".format(
617
- colorize("info", "Poetry"), colorize("b", version)
618
- )
619
- )
620
- else:
621
- self._write("Removing {}".format(colorize("info", "Poetry")))
622
-
623
- shutil.rmtree(str(self.data_dir))
624
- for script in ["poetry", "poetry.bat", "poetry.exe"]:
625
- if self.bin_dir.joinpath(script).exists():
626
- self.bin_dir.joinpath(script).unlink()
627
-
628
- return 0
629
-
630
- def _install_comment(self, version: str, message: str):
631
- self._overwrite(
632
- "Installing {} ({}): {}".format(
633
- colorize("info", "Poetry"),
634
- colorize("b", version),
635
- colorize("comment", message),
636
- )
637
- )
638
-
639
- @contextmanager
640
- def make_env(self, version: str) -> VirtualEnvironment:
641
- env_path = self.data_dir.joinpath("venv")
642
- env_path_saved = env_path.with_suffix(".save")
643
-
644
- if env_path.exists():
645
- self._install_comment(version, "Saving existing environment")
646
- if env_path_saved.exists():
647
- shutil.rmtree(env_path_saved)
648
- shutil.move(env_path, env_path_saved)
649
-
650
- try:
651
- self._install_comment(version, "Creating environment")
652
- yield VirtualEnvironment.make(env_path)
653
- except Exception as e:
654
- if env_path.exists():
655
- self._install_comment(
656
- version, "An error occurred. Removing partial environment."
657
- )
658
- shutil.rmtree(env_path)
659
-
660
- if env_path_saved.exists():
661
- self._install_comment(
662
- version, "Restoring previously saved environment."
663
- )
664
- shutil.move(env_path_saved, env_path)
665
-
666
- raise e
667
- else:
668
- if env_path_saved.exists():
669
- shutil.rmtree(env_path_saved, ignore_errors=True)
670
-
671
- def make_bin(self, version: str, env: VirtualEnvironment) -> None:
672
- self._install_comment(version, "Creating script")
673
- self.bin_dir.mkdir(parents=True, exist_ok=True)
674
-
675
- script = "poetry.exe" if WINDOWS else "poetry"
676
- target_script = env.bin_path.joinpath(script)
677
-
678
- if self.bin_dir.joinpath(script).exists():
679
- self.bin_dir.joinpath(script).unlink()
680
-
681
- try:
682
- self.bin_dir.joinpath(script).symlink_to(target_script)
683
- except OSError:
684
- # This can happen if the user
685
- # does not have the correct permission on Windows
686
- shutil.copy(target_script, self.bin_dir.joinpath(script))
687
-
688
- def install_poetry(self, version: str, env: VirtualEnvironment) -> None:
689
- self._install_comment(version, "Installing Poetry")
690
-
691
- if self._git:
692
- specification = "git+" + version
693
- elif self._path:
694
- specification = version
695
- else:
696
- specification = f"poetry=={version}"
697
-
698
- env.pip("install", specification)
699
-
700
- def display_pre_message(self) -> None:
701
- kwargs = {
702
- "poetry": colorize("info", "Poetry"),
703
- "poetry_home_bin": colorize("comment", self.bin_dir),
704
- }
705
- self._write(PRE_MESSAGE.format(**kwargs))
706
-
707
- def display_post_message(self, version: str) -> None:
708
- if WINDOWS:
709
- return self.display_post_message_windows(version)
710
-
711
- if SHELL == "fish":
712
- return self.display_post_message_fish(version)
713
-
714
- return self.display_post_message_unix(version)
715
-
716
- def display_post_message_windows(self, version: str) -> None:
717
- path = self.get_windows_path_var()
718
-
719
- message = POST_MESSAGE_NOT_IN_PATH
720
- if path and str(self.bin_dir) in path:
721
- message = POST_MESSAGE
722
-
723
- self._write(
724
- message.format(
725
- poetry=colorize("info", "Poetry"),
726
- version=colorize("b", version),
727
- poetry_home_bin=colorize("comment", self.bin_dir),
728
- poetry_executable=colorize("b", self.bin_dir.joinpath("poetry")),
729
- configure_message=POST_MESSAGE_CONFIGURE_WINDOWS.format(
730
- poetry_home_bin=colorize("comment", self.bin_dir)
731
- ),
732
- test_command=colorize("b", "poetry --version"),
733
- )
734
- )
735
-
736
- def get_windows_path_var(self) -> Optional[str]:
737
- import winreg
738
-
739
- with winreg.ConnectRegistry(
740
- None, winreg.HKEY_CURRENT_USER
741
- ) as root, winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
742
- path, _ = winreg.QueryValueEx(key, "PATH")
743
-
744
- return path
745
-
746
- def display_post_message_fish(self, version: str) -> None:
747
- fish_user_paths = subprocess.check_output(
748
- ["fish", "-c", "echo $fish_user_paths"]
749
- ).decode("utf-8")
750
-
751
- message = POST_MESSAGE_NOT_IN_PATH
752
- if fish_user_paths and str(self.bin_dir) in fish_user_paths:
753
- message = POST_MESSAGE
754
-
755
- self._write(
756
- message.format(
757
- poetry=colorize("info", "Poetry"),
758
- version=colorize("b", version),
759
- poetry_home_bin=colorize("comment", self.bin_dir),
760
- poetry_executable=colorize("b", self.bin_dir.joinpath("poetry")),
761
- configure_message=POST_MESSAGE_CONFIGURE_FISH.format(
762
- poetry_home_bin=colorize("comment", self.bin_dir)
763
- ),
764
- test_command=colorize("b", "poetry --version"),
765
- )
766
- )
767
-
768
- def display_post_message_unix(self, version: str) -> None:
769
- paths = os.getenv("PATH", "").split(":")
770
-
771
- message = POST_MESSAGE_NOT_IN_PATH
772
- if paths and str(self.bin_dir) in paths:
773
- message = POST_MESSAGE
774
-
775
- self._write(
776
- message.format(
777
- poetry=colorize("info", "Poetry"),
778
- version=colorize("b", version),
779
- poetry_home_bin=colorize("comment", self.bin_dir),
780
- poetry_executable=colorize("b", self.bin_dir.joinpath("poetry")),
781
- configure_message=POST_MESSAGE_CONFIGURE_UNIX.format(
782
- poetry_home_bin=colorize("comment", self.bin_dir)
783
- ),
784
- test_command=colorize("b", "poetry --version"),
785
- )
786
- )
787
-
788
- def ensure_directories(self) -> None:
789
- self.data_dir.mkdir(parents=True, exist_ok=True)
790
- self.bin_dir.mkdir(parents=True, exist_ok=True)
791
-
792
- def get_version(self):
793
- current_version = None
794
- if self.version_file.exists():
795
- current_version = self.version_file.read_text().strip()
796
-
797
- self._write(colorize("info", "Retrieving Poetry metadata"))
798
-
799
- metadata = json.loads(self._get(self.METADATA_URL).decode())
800
-
801
- def _compare_versions(x, y):
802
- mx = self.VERSION_REGEX.match(x)
803
- my = self.VERSION_REGEX.match(y)
804
-
805
- vx = (*tuple(int(p) for p in mx.groups()[:3]), mx.group(5))
806
- vy = (*tuple(int(p) for p in my.groups()[:3]), my.group(5))
807
-
808
- if vx < vy:
809
- return -1
810
- elif vx > vy:
811
- return 1
812
-
813
- return 0
814
-
815
- self._write("")
816
- releases = sorted(
817
- metadata["releases"].keys(), key=cmp_to_key(_compare_versions)
818
- )
819
-
820
- if self._version and self._version not in releases:
821
- msg = f"Version {self._version} does not exist."
822
- self._write(colorize("error", msg))
823
-
824
- raise ValueError(msg)
825
-
826
- version = self._version
827
- if not version:
828
- for release in reversed(releases):
829
- m = self.VERSION_REGEX.match(release)
830
- if m.group(5) and not self.allows_prereleases():
831
- continue
832
-
833
- version = release
834
-
835
- break
836
-
837
- if current_version == version and not self._force:
838
- self._write(
839
- f'The latest version ({colorize("b", version)}) is already installed.'
840
- )
841
-
842
- return None, current_version
843
-
844
- return version, current_version
845
-
846
- def _write(self, line) -> None:
847
- sys.stdout.write(line + "\n")
848
-
849
- def _overwrite(self, line) -> None:
850
- if not is_decorated():
851
- return self._write(line)
852
-
853
- self._cursor.move_up()
854
- self._cursor.clear_line()
855
- self._write(line)
856
-
857
- def _get(self, url):
858
- request = Request(url, headers={"User-Agent": "Python Poetry"})
859
-
860
- with closing(urlopen(request)) as r:
861
- return r.read()
862
-
863
-
864
- def main():
865
- parser = argparse.ArgumentParser(
866
- description="Installs the latest (or given) version of poetry"
867
- )
868
- parser.add_argument(
869
- "-p",
870
- "--preview",
871
- help="install preview version",
872
- dest="preview",
873
- action="store_true",
874
- default=False,
875
- )
876
- parser.add_argument("--version", help="install named version", dest="version")
877
- parser.add_argument(
878
- "-f",
879
- "--force",
880
- help="install on top of existing version",
881
- dest="force",
882
- action="store_true",
883
- default=False,
884
- )
885
- parser.add_argument(
886
- "-y",
887
- "--yes",
888
- help="accept all prompts",
889
- dest="accept_all",
890
- action="store_true",
891
- default=False,
892
- )
893
- parser.add_argument(
894
- "--uninstall",
895
- help="uninstall poetry",
896
- dest="uninstall",
897
- action="store_true",
898
- default=False,
899
- )
900
- parser.add_argument(
901
- "--path",
902
- dest="path",
903
- action="store",
904
- help=(
905
- "Install from a given path (file or directory) instead of "
906
- "fetching the latest version of Poetry available online."
907
- ),
908
- )
909
- parser.add_argument(
910
- "--git",
911
- dest="git",
912
- action="store",
913
- help=(
914
- "Install from a git repository instead of fetching the latest version "
915
- "of Poetry available online."
916
- ),
917
- )
918
-
919
- args = parser.parse_args()
920
-
921
- installer = Installer(
922
- version=args.version or os.getenv("POETRY_VERSION"),
923
- preview=args.preview or string_to_bool(os.getenv("POETRY_PREVIEW", "0")),
924
- force=args.force,
925
- accept_all=args.accept_all
926
- or string_to_bool(os.getenv("POETRY_ACCEPT", "0"))
927
- or not is_interactive(),
928
- path=args.path,
929
- git=args.git,
930
- )
931
-
932
- if args.uninstall or string_to_bool(os.getenv("POETRY_UNINSTALL", "0")):
933
- return installer.uninstall()
934
-
935
- try:
936
- return installer.run()
937
- except PoetryInstallationError as e:
938
- installer._write(colorize("error", "Poetry installation failed."))
939
-
940
- if e.log is not None:
941
- import traceback
942
-
943
- _, path = tempfile.mkstemp(
944
- suffix=".log",
945
- prefix="poetry-installer-error-",
946
- dir=str(Path.cwd()),
947
- text=True,
948
- )
949
- installer._write(colorize("error", f"See {path} for error logs."))
950
- tb = "".join(traceback.format_tb(e.__traceback__))
951
- text = f"{e.log}\nTraceback:\n\n{tb}"
952
- Path(path).write_text(text)
953
-
954
- return e.return_code
955
-
956
-
957
- if __name__ == "__main__":
958
- sys.exit(main())