Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc3b372c16 | ||
|
|
0a63d644e9 | ||
|
|
cfb6213acc | ||
|
|
a2fcb1cf2f | ||
|
|
9dbf0e6bd4 | ||
|
|
48b13d550c | ||
|
|
3a7919149c | ||
|
|
a5ab135f82 | ||
|
|
95e87eb197 | ||
|
|
00bffb1efe | ||
|
|
3b2769310d | ||
|
|
5f3478279b | ||
|
|
013b5fff92 |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
default_language_version:
|
||||
python: python3.10
|
||||
exclude: ^(src/octoprint/vendor/|src/octoprint/static/js/lib|src/octoprint/static/vendor|tests/static/js/lib|tests/util/_files|scripts/|translations/|.*\.css|.*\.svg)
|
||||
exclude: ^(src/octoprint/vendor/|src/octoprint/static/js/lib|src/octoprint/static/vendor|src/octoprint_setuptools|tests/static/js/lib|tests/util/_files|scripts/|translations/|.*\.css|.*\.svg)
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
|
||||
+8
-8
@@ -18,21 +18,21 @@ prerelease
|
||||
HEAD
|
||||
\(detached.*
|
||||
|
||||
# maintenance is currently the branch for preparation of maintenance release 1.9.0
|
||||
# maintenance is currently the branch for preparation of maintenance release 1.10.0
|
||||
# so are any fix/... and improve/... branches
|
||||
maintenance 1.9.0 fa2c4680cca0d1d6b46e6c1ed68ceea4d9b79afb pep440-dev
|
||||
fix/.* 1.9.0 fa2c4680cca0d1d6b46e6c1ed68ceea4d9b79afb pep440-dev
|
||||
improve/.* 1.9.0 fa2c4680cca0d1d6b46e6c1ed68ceea4d9b79afb pep440-dev
|
||||
maintenance 1.10.0 cd955e9a46782119b36cc22b8dea5652ebbf9774 pep440-dev
|
||||
fix/.* 1.10.0 cd955e9a46782119b36cc22b8dea5652ebbf9774 pep440-dev
|
||||
improve/.* 1.10.0 cd955e9a46782119b36cc22b8dea5652ebbf9774 pep440-dev
|
||||
|
||||
# staging/bugfix is the branch for preparation of the 1.8.7 bugfix release
|
||||
# staging/bugfix is the branch for preparation of the 1.8.8 bugfix release
|
||||
# so are any bug/... branches
|
||||
staging/bugfix 1.8.8 8e4c1f5246c4245b839ccdcdabf2beee671b08d7 pep440-dev
|
||||
bug/.* 1.8.8 8e4c1f5246c4245b839ccdcdabf2beee671b08d7 pep440-dev
|
||||
|
||||
# staging/maintenance is currently the branch for preparation of 1.8.0rc6
|
||||
# staging/maintenance is currently the branch for preparation of 1.9.0rc3
|
||||
# so is regressionfix/...
|
||||
staging/maintenance 1.8.0rc6 45598764e6c7f6257de87a98d15964209ddc9e09 pep440-dev
|
||||
regressionfix/.* 1.8.0rc6 45598764e6c7f6257de87a98d15964209ddc9e09 pep440-dev
|
||||
staging/maintenance 1.9.0rc3 95e87eb1970d8e322738f9698c9d665d78f2d74e pep440-dev
|
||||
regressionfix/.* 1.9.0rc3 95e87eb1970d8e322738f9698c9d665d78f2d74e pep440-dev
|
||||
|
||||
# staging/devel is currently inactive (but has the 1.4.1rc4 namespace)
|
||||
staging/devel 1.4.1rc4 650d54d1885409fa1d411eb54b9e8c7ff428910f pep440-dev
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
* [futures](https://github.com/agronholm/pythonfutures): Python
|
||||
* [monotonic](https://github.com/atdt/monotonic): Apache License 2.0
|
||||
* [netaddr](https://github.com/drkjam/netaddr/): BSD
|
||||
* [netifaces](https://bitbucket.org/al45tair/netifaces): MIT
|
||||
* [netifaces2](https://github.com/SamuelYvon/netifaces-2): MIT
|
||||
* [pathvalidate](https://pathvalidate.readthedocs.io/en/latest/index.html): MIT
|
||||
* [pkginfo](http://pypi.python.org/pypi/pkginfo/): Python
|
||||
* [psutil](https://github.com/giampaolo/psutil): BSD
|
||||
|
||||
@@ -1,5 +1,140 @@
|
||||
[metadata]
|
||||
license_file = LICENSE.txt
|
||||
name = OctoPrint
|
||||
version = attr: octoprint.__version__
|
||||
description = The snappy web interface for your 3D printer
|
||||
long_description = file: README.md
|
||||
long_description_content_type = text/markdown
|
||||
url = https://octoprint.org
|
||||
author = Gina Häußge
|
||||
author_email = gina@octoprint.org
|
||||
keywords =
|
||||
3dprinting
|
||||
3dprinter
|
||||
3d-printing
|
||||
3d-printer
|
||||
octoprint
|
||||
project_urls =
|
||||
Community Forum = https://community.octoprint.org
|
||||
Bug Reports = https://github.com/OctoPrint/OctoPrint/issues
|
||||
Source = https://github.com/OctoPrint/OctoPrint
|
||||
Funding = https://support.octoprint.org
|
||||
license_files = LICENSE.txt
|
||||
classifiers =
|
||||
Development Status :: 5 - Production/Stable
|
||||
Environment :: Web Environment
|
||||
Framework :: Flask
|
||||
Intended Audience :: Developers
|
||||
Intended Audience :: Education
|
||||
Intended Audience :: End Users/Desktop
|
||||
Intended Audience :: Manufacturing
|
||||
Intended Audience :: Other Audience
|
||||
Intended Audience :: Science/Research
|
||||
License :: OSI Approved :: GNU Affero General Public License v3
|
||||
Natural Language :: English
|
||||
Natural Language :: German
|
||||
Operating System :: OS Independent
|
||||
Programming Language :: Python
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3.7
|
||||
Programming Language :: Python :: 3.8
|
||||
Programming Language :: Python :: 3.9
|
||||
Programming Language :: Python :: 3.10
|
||||
Programming Language :: Python :: 3.11
|
||||
Programming Language :: Python :: 3 :: Only
|
||||
Programming Language :: Python :: Implementation :: CPython
|
||||
Programming Language :: JavaScript
|
||||
Topic :: Printing
|
||||
Topic :: System :: Monitoring
|
||||
|
||||
[options]
|
||||
packages = find:
|
||||
package_dir =
|
||||
= src
|
||||
include_package_data = True
|
||||
|
||||
zip_safe = False
|
||||
|
||||
python_requires = >=3.7,<3.12
|
||||
install_requires =
|
||||
# bundled plugins
|
||||
OctoPrint-FileCheck>=2021.2.23
|
||||
OctoPrint-FirmwareCheck>=2021.10.11
|
||||
OctoPrint-PiSupport>=2022.6.13
|
||||
|
||||
# core dependencies
|
||||
appdirs>=1.4.4,<2;sys_platform == "darwin"
|
||||
argon2_cffi>=21.3.0,<22
|
||||
Babel>=2.12.1,<2.13 # breaking changes can happen on minor version increases
|
||||
cachelib>=0.10.2,<0.11
|
||||
Click>=8.1.3,<9
|
||||
colorlog>=6.7.0,<7
|
||||
emoji>=2.2.0,<3
|
||||
feedparser>=6.0.10,<7
|
||||
filetype>=1.2.0,<2
|
||||
Flask-Assets>=2.0,<3
|
||||
Flask-Babel>=3.1.0,<4
|
||||
Flask-Login>=0.6.2,<0.7 # breaking changes can happen on minor version increases
|
||||
Flask-Limiter>=3.3.0,<4
|
||||
flask>=2.2.3,<2.3 # breaking changes can happen on minor version increases (with deprecation warnings)
|
||||
frozendict>=2.3.7,<3
|
||||
future>=0.18.3,<1 # not really needed anymore, but leaving in for py2/3 compat plugins
|
||||
markdown>=3.4.3,<4
|
||||
netaddr>=0.8,<0.9 # changelog hints at breaking changes on minor version increases
|
||||
netifaces2>=0.0.14,<0.1
|
||||
passlib>=1.7.4,<2
|
||||
pathvalidate>=2.5.2,<3
|
||||
pkginfo>=1.9.6,<2
|
||||
psutil>=5.9.4,<6
|
||||
pydantic>=1.10.7,<2
|
||||
pylru>=1.2.1,<2
|
||||
pyserial>=3.5,<4
|
||||
PyYAML>=6.0.1,<7 # changelog at https://github.com/yaml/pyyaml/blob/master/CHANGES
|
||||
requests>=2.28.2,<3
|
||||
sarge==0.1.7.post1
|
||||
semantic_version>=2.10.0,<3
|
||||
sentry-sdk>=1.19.0,<2
|
||||
tornado>=6.2,<7
|
||||
watchdog>=2.3.1,<3
|
||||
websocket-client>=1.5.1,<2
|
||||
werkzeug>=2.2.3,<2.3 # breaking changes can happen on minor version increases
|
||||
wrapt>=1.15,<1.16
|
||||
zeroconf==0.39.4 # final version to include universal wheel, later takes ages to compiles on rpi, piwheels has no wheels for latest either
|
||||
zipstream-ng>=1.5.0,<2.0.0
|
||||
|
||||
# vendored dependencies
|
||||
blinker>=1.6.1,<2 # dependency of flask_principal
|
||||
class-doc>=0.2.6,<0.3 # dependency of with_attrs_docs
|
||||
regex # dependency of awesome-slugify
|
||||
unidecode # dependency of awesome-slugify
|
||||
|
||||
# plugin dependencies
|
||||
wheel
|
||||
|
||||
[options.extras_require]
|
||||
develop =
|
||||
# Testing dependencies
|
||||
ddt
|
||||
mock>=5.0.1,<6
|
||||
pytest-doctest-custom>=1.0.0,<2
|
||||
pytest>=7.3.0,<8
|
||||
# pre-commit
|
||||
pre-commit
|
||||
# profiler
|
||||
pyinstrument
|
||||
# task runner
|
||||
invoke
|
||||
plugins =
|
||||
cookiecutter>=2.1.1,<3
|
||||
docs =
|
||||
sphinx
|
||||
sphinxcontrib-httpdomain
|
||||
sphinxcontrib-mermaid
|
||||
sphinx_rtd_theme
|
||||
readthedocs-sphinx-ext
|
||||
|
||||
[options.packages.find]
|
||||
where = src
|
||||
|
||||
|
||||
[bdist_wheel]
|
||||
universal = 1
|
||||
|
||||
@@ -1,390 +1,62 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
### NOTE #################################################################################
|
||||
# This file has to stay format compatible to Python 2, or pip under Python 2 will
|
||||
# not be able to detect that OctoPrint requires Python 3 but instead fail with a
|
||||
# syntax error.
|
||||
#
|
||||
# So, no f-strings, no walrus operators, no pyupgrade or codemods.
|
||||
##########################################################################################
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
from distutils.command.build_py import build_py as _build_py
|
||||
|
||||
import setuptools # noqa: F401,E402
|
||||
|
||||
try:
|
||||
import octoprint_setuptools # noqa: F401,E402
|
||||
except ImportError:
|
||||
octoprint_setuptools = None
|
||||
|
||||
import versioneer # noqa: F401
|
||||
|
||||
# ----------------------------------------------------------------------------------------
|
||||
|
||||
# Supported python versions
|
||||
PYTHON_REQUIRES = ">=3.7, <3.12"
|
||||
|
||||
# Requirements for setup.py
|
||||
SETUP_REQUIRES = []
|
||||
|
||||
# Requirements for our application
|
||||
bundled_plugins = [
|
||||
"OctoPrint-FileCheck>=2021.2.23",
|
||||
"OctoPrint-FirmwareCheck>=2021.10.11",
|
||||
"OctoPrint-PiSupport>=2022.6.13",
|
||||
]
|
||||
core_deps = [
|
||||
"argon2_cffi>=21.3.0,<22",
|
||||
"Babel>=2.12.1,<2.13", # breaking changes can happen on minor version increases
|
||||
"cachelib>=0.10.2,<0.11",
|
||||
"Click>=8.1.3,<9",
|
||||
"colorlog>=6.7.0,<7",
|
||||
"emoji>=2.2.0,<3",
|
||||
"feedparser>=6.0.10,<7",
|
||||
"filetype>=1.2.0,<2",
|
||||
"Flask-Assets>=2.0,<3",
|
||||
"Flask-Babel>=3.0.1,<4",
|
||||
"Flask-Login>=0.6.2,<0.7", # breaking changes can happen on minor version increases
|
||||
"Flask-Limiter>=3.3.0,<4",
|
||||
"flask>=2.2.3,<2.3", # breaking changes can happen on minor version increases (with deprecation warnings)
|
||||
"frozendict>=2.3.5,<3",
|
||||
"future>=0.18.3,<1", # not really needed anymore, but leaving in for py2/3 compat plugins
|
||||
"markdown>=3.4.1,<4",
|
||||
"netaddr>=0.8,<0.9", # changelog hints at breaking changes on minor version increases
|
||||
"netifaces>=0.11,<1",
|
||||
"passlib>=1.7.4,<2",
|
||||
"pathvalidate>=2.5.2,<3",
|
||||
"pkginfo>=1.9.6,<2",
|
||||
"psutil>=5.9.4,<6",
|
||||
"pydantic>=1.10.5,<2",
|
||||
"pylru>=1.2.1,<2",
|
||||
"pyserial>=3.5,<4",
|
||||
"PyYAML>=5.4.1,<6", # no changelog available for version 6, so we're not risking it
|
||||
"requests>=2.28.2,<3",
|
||||
"sarge==0.1.7.post1",
|
||||
"semantic_version>=2.10.0,<3",
|
||||
"sentry-sdk>=1.16.0,<2",
|
||||
"tornado>=6.2,<7",
|
||||
"watchdog>=2.3.1,<3",
|
||||
"websocket-client>=1.5.1,<2",
|
||||
"werkzeug>=2.2.3,<2.3", # breaking changes can happen on minor version increases
|
||||
"wrapt>=1.15,<1.16",
|
||||
"zeroconf==0.39.4", # final version to include universal wheel, later takes ages to compiles on rpi, piwheels has no wheels for latest either
|
||||
"zipstream-ng>=1.4.0,<2.0.0",
|
||||
]
|
||||
vendored_deps = [
|
||||
"blinker>=1.5,<2", # dependency of flask_principal
|
||||
"class-doc>=0.2.6,<0.3", # dependency of with_attrs_docs
|
||||
"regex", # dependency of awesome-slugify
|
||||
"unidecode", # dependency of awesome-slugify
|
||||
]
|
||||
plugin_deps = [
|
||||
"OctoPrint-Setuptools>=1.0.2", # makes sure plugins can import this on setup.py based install
|
||||
"wheel", # makes sure plugins can be built as wheels in OctoPrint's venv, see #4682
|
||||
]
|
||||
|
||||
INSTALL_REQUIRES = bundled_plugins + core_deps + vendored_deps + plugin_deps
|
||||
|
||||
# Additional requirements for optional install options and/or OS-specific dependencies
|
||||
EXTRA_REQUIRES = {
|
||||
# Dependencies for OSX
|
||||
":sys_platform == 'darwin'": [
|
||||
"appdirs>=1.4.4,<2",
|
||||
],
|
||||
# Dependencies for core development
|
||||
"develop": [
|
||||
# Testing dependencies
|
||||
"ddt",
|
||||
"mock>=5.0.1,<6",
|
||||
"pytest-doctest-custom>=1.0.0,<2",
|
||||
"pytest>=7.2.2,<8",
|
||||
# pre-commit
|
||||
"pre-commit",
|
||||
# profiler
|
||||
"pyinstrument",
|
||||
],
|
||||
# Dependencies for developing OctoPrint plugins
|
||||
"plugins": ["cookiecutter>=2.1.1,<3"],
|
||||
# Dependencies for building the documentation
|
||||
"docs": [
|
||||
"sphinx",
|
||||
"sphinxcontrib-httpdomain",
|
||||
"sphinxcontrib-mermaid",
|
||||
"sphinx_rtd_theme",
|
||||
"readthedocs-sphinx-ext",
|
||||
],
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------------------
|
||||
# Anything below here is just command setup and general setup configuration
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
from setuptools import setup
|
||||
from setuptools.command.build_py import build_py as _build_py
|
||||
|
||||
|
||||
def read_file_contents(path):
|
||||
import io
|
||||
|
||||
with io.open(path, encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def copy_files_build_py_factory(files, baseclass):
|
||||
class copy_files_build_py(baseclass):
|
||||
files = {}
|
||||
|
||||
def run(self):
|
||||
print("RUNNING copy_files_build_py")
|
||||
if not self.dry_run:
|
||||
import shutil
|
||||
|
||||
for directory, files in self.files.items():
|
||||
target_dir = os.path.join(self.build_lib, directory)
|
||||
self.mkpath(target_dir)
|
||||
|
||||
for entry in files:
|
||||
if isinstance(entry, tuple):
|
||||
if len(entry) != 2:
|
||||
continue
|
||||
source, dest = entry[0], os.path.join(target_dir, entry[1])
|
||||
else:
|
||||
source = entry
|
||||
dest = os.path.join(target_dir, source)
|
||||
|
||||
print("Copying {} to {}".format(source, dest))
|
||||
shutil.copy2(source, dest)
|
||||
|
||||
baseclass.run(self)
|
||||
|
||||
return type(copy_files_build_py)(
|
||||
copy_files_build_py.__name__, (copy_files_build_py,), {"files": files}
|
||||
)
|
||||
|
||||
|
||||
class ScanDepsCommand(setuptools.Command):
|
||||
description = "Scan dependencies for updates"
|
||||
user_options = []
|
||||
|
||||
PYPI = "https://pypi.org/simple/{package}/"
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
class custom_build_py(_build_py):
|
||||
FILES = {
|
||||
"octoprint/templates/_data": [
|
||||
"AUTHORS.md",
|
||||
"SUPPORTERS.md",
|
||||
"THIRDPARTYLICENSES.md",
|
||||
]
|
||||
}
|
||||
|
||||
def run(self):
|
||||
from collections import namedtuple
|
||||
self._copy_files(self.FILES)
|
||||
super().run()
|
||||
self._run_versioneer()
|
||||
|
||||
import pkg_resources
|
||||
import requests
|
||||
from packaging.version import parse as parse_version
|
||||
def _copy_files(self, files):
|
||||
for directory, entries in files.items():
|
||||
target_dir = os.path.join(self.build_lib, directory)
|
||||
self.mkpath(target_dir)
|
||||
|
||||
Update = namedtuple("Update", ["name", "spec", "current", "latest"])
|
||||
update_lower_bounds = []
|
||||
update_bounds = []
|
||||
for entry in entries:
|
||||
if isinstance(entry, tuple):
|
||||
if len(entry) != 2:
|
||||
continue
|
||||
source, dest = entry[0], os.path.join(target_dir, entry[1])
|
||||
else:
|
||||
source = entry
|
||||
dest = os.path.join(target_dir, source)
|
||||
|
||||
all_requires = list(INSTALL_REQUIRES)
|
||||
for value in EXTRA_REQUIRES.values():
|
||||
all_requires += value
|
||||
print("copying {} -> {}".format(source, dest))
|
||||
shutil.copy2(source, dest)
|
||||
|
||||
for r in all_requires:
|
||||
requirement = pkg_resources.Requirement.parse(r)
|
||||
|
||||
resp = requests.get(
|
||||
self.PYPI.format(package=requirement.project_name),
|
||||
headers={"Accept": "application/vnd.pypi.simple.v1+json"},
|
||||
)
|
||||
resp.raise_for_status()
|
||||
|
||||
data = resp.json()
|
||||
versions = list(
|
||||
filter(
|
||||
lambda x: not x.is_prerelease and not x.is_devrelease,
|
||||
map(lambda x: parse_version(x), data.get("versions", [])),
|
||||
)
|
||||
)
|
||||
if not versions:
|
||||
continue
|
||||
|
||||
lower = None
|
||||
for spec in requirement.specs:
|
||||
if spec[0] == ">=":
|
||||
lower = spec[1]
|
||||
break
|
||||
|
||||
latest = versions[-1]
|
||||
|
||||
update = Update(requirement.project_name, str(requirement), lower, latest)
|
||||
|
||||
if str(latest) not in requirement:
|
||||
update_bounds.append(update)
|
||||
elif lower and parse_version(lower) < latest:
|
||||
update_lower_bounds.append(update)
|
||||
|
||||
def print_update(update):
|
||||
print(
|
||||
f"{update.spec}: latest {update.latest}, pypi: https://pypi.org/project/{update.name}/"
|
||||
)
|
||||
|
||||
print("")
|
||||
print("The following dependencies can get their lower bounds updated:")
|
||||
print("")
|
||||
for update in update_lower_bounds:
|
||||
print_update(update)
|
||||
|
||||
print("")
|
||||
print("The following dependencies should get looked at for a full update:")
|
||||
print("")
|
||||
for update in update_bounds:
|
||||
print_update(update)
|
||||
|
||||
|
||||
def get_cmdclass():
|
||||
# make sure these are always available, even when run by dependabot
|
||||
global versioneer, octoprint_setuptools, md_to_html_build_py_factory
|
||||
|
||||
cmdclass = versioneer.get_cmdclass()
|
||||
|
||||
if octoprint_setuptools:
|
||||
# add clean command
|
||||
cmdclass.update(
|
||||
{
|
||||
"clean": octoprint_setuptools.CleanCommand.for_options(
|
||||
source_folder="src", eggs=["OctoPrint*.egg-info"]
|
||||
)
|
||||
}
|
||||
def _run_versioneer(self):
|
||||
from versioneer import (
|
||||
get_config_from_root,
|
||||
get_root,
|
||||
get_versions,
|
||||
write_to_version_file,
|
||||
)
|
||||
|
||||
# add translation commands
|
||||
translation_dir = "translations"
|
||||
pot_file = os.path.join(translation_dir, "messages.pot")
|
||||
bundled_dir = os.path.join("src", "octoprint", "translations")
|
||||
cmdclass.update(
|
||||
octoprint_setuptools.get_babel_commandclasses(
|
||||
pot_file=pot_file,
|
||||
output_dir=translation_dir,
|
||||
pack_name_prefix="OctoPrint-i18n-",
|
||||
pack_path_prefix="",
|
||||
bundled_dir=bundled_dir,
|
||||
)
|
||||
)
|
||||
root = get_root()
|
||||
cfg = get_config_from_root(root)
|
||||
versions = get_versions()
|
||||
if cfg.versionfile_build:
|
||||
target_versionfile = os.path.join(self.build_lib, cfg.versionfile_build)
|
||||
print("UPDATING {}".format(target_versionfile))
|
||||
write_to_version_file(target_versionfile, versions)
|
||||
|
||||
cmdclass["build_py"] = copy_files_build_py_factory(
|
||||
{
|
||||
"octoprint/templates/_data": [
|
||||
"AUTHORS.md",
|
||||
"SUPPORTERS.md",
|
||||
"THIRDPARTYLICENSES.md",
|
||||
]
|
||||
},
|
||||
cmdclass["build_py"] if "build_py" in cmdclass else _build_py,
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup(
|
||||
# supported in setup.cfg from setuptools 54, not yet on OctoPi
|
||||
entry_points={"console_scripts": ["octoprint = octoprint:main"]},
|
||||
# supported in setup.cfg from setuptools 51, not yet on OctoPi
|
||||
cmdclass={"build_py": custom_build_py},
|
||||
)
|
||||
|
||||
cmdclass["scan_deps"] = ScanDepsCommand
|
||||
|
||||
return cmdclass
|
||||
|
||||
|
||||
def package_data_dirs(source, sub_folders):
|
||||
dirs = []
|
||||
|
||||
for d in sub_folders:
|
||||
folder = os.path.join(source, d)
|
||||
if not os.path.exists(folder):
|
||||
continue
|
||||
|
||||
for dirname, _, files in os.walk(folder):
|
||||
dirname = os.path.relpath(dirname, source)
|
||||
for f in files:
|
||||
dirs.append(os.path.join(dirname, f))
|
||||
|
||||
return dirs
|
||||
|
||||
|
||||
def params():
|
||||
# make sure these are always available, even when run by dependabot
|
||||
global versioneer, get_cmdclass, read_file_contents, here, PYTHON_REQUIRES, SETUP_REQUIRES, INSTALL_REQUIRES, EXTRA_REQUIRES
|
||||
|
||||
name = "OctoPrint"
|
||||
version = versioneer.get_version()
|
||||
cmdclass = get_cmdclass()
|
||||
|
||||
description = "The snappy web interface for your 3D printer"
|
||||
long_description = read_file_contents(os.path.join(here, "README.md"))
|
||||
long_description_content_type = "text/markdown"
|
||||
|
||||
python_requires = PYTHON_REQUIRES
|
||||
setup_requires = SETUP_REQUIRES
|
||||
install_requires = INSTALL_REQUIRES
|
||||
extras_require = EXTRA_REQUIRES
|
||||
|
||||
classifiers = [
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Environment :: Web Environment",
|
||||
"Framework :: Flask",
|
||||
"Intended Audience :: Developers",
|
||||
"Intended Audience :: Education",
|
||||
"Intended Audience :: End Users/Desktop",
|
||||
"Intended Audience :: Manufacturing",
|
||||
"Intended Audience :: Other Audience",
|
||||
"Intended Audience :: Science/Research",
|
||||
"License :: OSI Approved :: GNU Affero General Public License v3",
|
||||
"Natural Language :: English",
|
||||
"Natural Language :: German",
|
||||
"Operating System :: OS Independent",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: JavaScript",
|
||||
"Topic :: Printing",
|
||||
"Topic :: System :: Monitoring",
|
||||
]
|
||||
author = "Gina Häußge"
|
||||
author_email = "gina@octoprint.org"
|
||||
url = "https://octoprint.org"
|
||||
license = "GNU Affero General Public License v3"
|
||||
keywords = "3dprinting 3dprinter 3d-printing 3d-printer octoprint"
|
||||
|
||||
project_urls = {
|
||||
"Community Forum": "https://community.octoprint.org",
|
||||
"Bug Reports": "https://github.com/OctoPrint/OctoPrint/issues",
|
||||
"Source": "https://github.com/OctoPrint/OctoPrint",
|
||||
"Funding": "https://support.octoprint.org",
|
||||
}
|
||||
|
||||
packages = setuptools.find_packages(where="src")
|
||||
package_dir = {
|
||||
"": "src",
|
||||
}
|
||||
package_data = {
|
||||
"octoprint": package_data_dirs(
|
||||
"src/octoprint", ["static", "templates", "plugins", "translations"]
|
||||
)
|
||||
+ ["util/piptestballoon/setup.py"]
|
||||
}
|
||||
|
||||
include_package_data = True
|
||||
zip_safe = False
|
||||
|
||||
if os.environ.get("READTHEDOCS", None) == "True":
|
||||
# we can't tell read the docs to please perform a pip install -e .[docs], so we help
|
||||
# it a bit here by explicitly adding the docs dependencies
|
||||
install_requires = install_requires + extras_require["docs"]
|
||||
|
||||
entry_points = {"console_scripts": ["octoprint = octoprint:main"]}
|
||||
|
||||
return locals()
|
||||
|
||||
|
||||
setuptools.setup(**params())
|
||||
@@ -117,18 +117,11 @@ $(function () {
|
||||
};
|
||||
|
||||
self._enableWebcam = function () {
|
||||
if (
|
||||
OctoPrint.coreui.selectedTab != "#control" ||
|
||||
!OctoPrint.coreui.browserTabVisible
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.webcamDisableTimeout != undefined) {
|
||||
clearTimeout(self.webcamDisableTimeout);
|
||||
}
|
||||
|
||||
// IF disabled then we dont need to do anything
|
||||
// If disabled then we dont need to do anything
|
||||
if (self.settings.webcamEnabled() == false) {
|
||||
console.log("Webcam not enabled");
|
||||
return;
|
||||
@@ -156,7 +149,7 @@ $(function () {
|
||||
};
|
||||
|
||||
self.onWebcamErrored = function () {
|
||||
log.debug("Webcam stream failed to load/disabled");
|
||||
log.debug("Webcam stream failed to load/was unloaded");
|
||||
self.webcamLoaded(false);
|
||||
self.webcamError(true);
|
||||
};
|
||||
|
||||
@@ -18,10 +18,10 @@ from octoprint.util.version import (
|
||||
)
|
||||
|
||||
SENTRY_URL_SERVER = (
|
||||
"https://6d8f1c1ae8ec40a6aa13ae60e89dd762@o118517.ingest.sentry.io/1373987"
|
||||
"https://11f9235bf2ac4f5d97f7e8bcb5be3783@o118517.ingest.sentry.io/1373987"
|
||||
)
|
||||
SENTRY_URL_COREUI = (
|
||||
"https://9d2de7de508142448da753336de534ba@o118517.ingest.sentry.io/1374096"
|
||||
"https://22fe071cb60c4dfcb8245a3712739f6e@o118517.ingest.sentry.io/1374096"
|
||||
)
|
||||
|
||||
SETTINGS_DEFAULTS = {
|
||||
|
||||
@@ -40,9 +40,9 @@ from octoprint.util.version import (
|
||||
|
||||
from . import cli, exceptions, updaters, util, version_checks
|
||||
|
||||
# OctoPi 0.16+
|
||||
MINIMUM_PYTHON = "2.7.13"
|
||||
MINIMUM_SETUPTOOLS = "40.7.1"
|
||||
# OctoPi 0.17+ (with Python 3)
|
||||
MINIMUM_PYTHON = "3.7.0"
|
||||
MINIMUM_SETUPTOOLS = "40.8.0"
|
||||
MINIMUM_PIP = "19.0.1"
|
||||
|
||||
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
@@ -190,7 +190,7 @@ def runFilesTest():
|
||||
|
||||
sanitized_path, _, sanitized = sanitize(storage, path, filename)
|
||||
|
||||
exists = fileManager.file_exists(storage, sanitized)
|
||||
exists = _getFileDetails(storage, filename)
|
||||
if exists:
|
||||
suggestion = filename
|
||||
name, ext = os.path.splitext(filename)
|
||||
@@ -205,7 +205,12 @@ def runFilesTest():
|
||||
):
|
||||
counter += 1
|
||||
suggestion = f"{name}_{counter}{ext}"
|
||||
return jsonify(exists=True, suggestion=suggestion)
|
||||
return jsonify(
|
||||
exists=True,
|
||||
suggestion=suggestion,
|
||||
size=exists.get("size"),
|
||||
date=exists.get("date"),
|
||||
)
|
||||
else:
|
||||
return jsonify(exists=False)
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ $(function () {
|
||||
|
||||
self.controlsFromServer = [];
|
||||
self.additionalControls = [];
|
||||
self.intersectionObservers = [];
|
||||
|
||||
self.keycontrolActive = ko.observable(false);
|
||||
self.keycontrolHelpActive = ko.observable(false);
|
||||
@@ -74,18 +75,27 @@ $(function () {
|
||||
}
|
||||
};
|
||||
|
||||
self.onAfterBinding = function () {
|
||||
self.onStartupComplete = function () {
|
||||
self.recreateIntersectionObservers();
|
||||
};
|
||||
|
||||
self.recreateIntersectionObservers = function () {
|
||||
// We are using the IntersectionObserver API to determine whether a webcam is visible or not.
|
||||
// A webcam will not intersect with the control tab if the control tab is invisible because another tab
|
||||
// is selected or if the webcam isn't shown because another webcam is active.
|
||||
//
|
||||
// Whenever the webacam changes visibility we will call onWebcamVisbilityChange() which the webcam's
|
||||
// VM can use to start or stop the stream.
|
||||
self.intersectionObservers.forEach(function (observer) {
|
||||
observer.disconnect();
|
||||
});
|
||||
self.intersectionObservers = [];
|
||||
|
||||
document
|
||||
.querySelectorAll("#webcam-group .tab-pane")
|
||||
.forEach(function (target) {
|
||||
var options = {
|
||||
root: document.querySelector("#control"),
|
||||
root: document.querySelector("#webcam_plugins_container"),
|
||||
rootMargin: "0px",
|
||||
threshold: 1.0
|
||||
};
|
||||
@@ -103,6 +113,7 @@ $(function () {
|
||||
|
||||
var observer = new IntersectionObserver(callback, options);
|
||||
observer.observe(target);
|
||||
self.intersectionObservers.push(observer);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1693,6 +1693,16 @@ $(function () {
|
||||
name: file.name
|
||||
})
|
||||
);
|
||||
$("span.existing_size", self.uploadExistsDialog).text(
|
||||
response.size ? formatSize(response.size) : "-"
|
||||
);
|
||||
$("span.existing_date", self.uploadExistsDialog).text(
|
||||
response.date ? new Date(response.date * 1000).toLocaleString() : "?"
|
||||
);
|
||||
$("span.new_size", self.uploadExistsDialog).text(formatSize(file.size));
|
||||
$("span.new_date", self.uploadExistsDialog).text(
|
||||
new Date(file.lastModified).toLocaleString()
|
||||
);
|
||||
$("p, form", self.uploadExistsDialog).toggle(!fileSizeTooBig);
|
||||
$("span", self.uploadExistsDialog).toggle(fileSizeTooBig);
|
||||
$("input", self.uploadExistsDialog)
|
||||
|
||||
@@ -70,6 +70,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div>
|
||||
<strong>{{ _('Existing file') }}</strong>
|
||||
<ul>
|
||||
<li>{{ _('Size') }}: <span class="existing_size"></span></li>
|
||||
<li>{{ _('Date') }}: <span class="existing_date"></span></li>
|
||||
</ul>
|
||||
|
||||
<strong>{{ _('New file') }}</strong>
|
||||
<ul>
|
||||
<li>{{ _('Size') }}: <span class="new_size"></span></li>
|
||||
<li>{{ _('Date') }}: <span class="new_date"></span></li>
|
||||
</ul>
|
||||
</div>
|
||||
<span hidden>
|
||||
{{ _('There is not enough free disk space to keep the existing file and upload this one.') }}
|
||||
</span>
|
||||
|
||||
@@ -0,0 +1,697 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
### NOTE #################################################################################
|
||||
# This file has to stay format compatible to Python 2, or pip under Python 2 will
|
||||
# not be able to detect that OctoPrint requires Python 3 but instead fail with a
|
||||
# syntax error.
|
||||
#
|
||||
# So, no f-strings, no walrus operators, no pyupgrade or codemods.
|
||||
##########################################################################################
|
||||
|
||||
__author__ = "Gina Häußge <osd@foosel.net>"
|
||||
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
|
||||
__copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
import glob
|
||||
import os
|
||||
import shutil
|
||||
from distutils.command.clean import clean as _clean
|
||||
|
||||
from setuptools import Command
|
||||
|
||||
|
||||
def package_data_dirs(source, sub_folders):
|
||||
dirs = []
|
||||
|
||||
for d in sub_folders:
|
||||
folder = os.path.join(source, d)
|
||||
if not os.path.exists(folder):
|
||||
continue
|
||||
|
||||
for dirname, _, files in os.walk(folder):
|
||||
dirname = os.path.relpath(dirname, source)
|
||||
for f in files:
|
||||
dirs.append(os.path.join(dirname, f))
|
||||
|
||||
return dirs
|
||||
|
||||
|
||||
def recursively_handle_files(
|
||||
directory, file_matcher, folder_matcher=None, folder_handler=None, file_handler=None
|
||||
):
|
||||
applied_handler = False
|
||||
|
||||
for filename in os.listdir(directory):
|
||||
path = os.path.join(directory, filename)
|
||||
|
||||
if file_handler is not None and file_matcher(filename):
|
||||
file_handler(path)
|
||||
applied_handler = True
|
||||
|
||||
elif os.path.isdir(path) and (
|
||||
folder_matcher is None or folder_matcher(directory, filename, path)
|
||||
):
|
||||
sub_applied_handler = recursively_handle_files(
|
||||
path,
|
||||
file_matcher,
|
||||
folder_handler=folder_handler,
|
||||
file_handler=file_handler,
|
||||
)
|
||||
if sub_applied_handler:
|
||||
applied_handler = True
|
||||
|
||||
if folder_handler is not None:
|
||||
folder_handler(path, sub_applied_handler)
|
||||
|
||||
return applied_handler
|
||||
|
||||
|
||||
def has_requirement(requirement, requirements):
|
||||
if requirement is None or requirements is None:
|
||||
return False
|
||||
|
||||
requirement = requirement.lower()
|
||||
requirements = [r.lower() for r in requirements]
|
||||
compat = [
|
||||
requirement.lower() + c for c in ("<", "<=", "!=", "==", ">=", ">", "~=", "===")
|
||||
]
|
||||
|
||||
return requirement in requirements or any(
|
||||
any(r.startswith(c) for c in compat) for r in requirements
|
||||
)
|
||||
|
||||
|
||||
class CleanCommand(_clean):
|
||||
user_options = _clean.user_options + [
|
||||
("orig", None, "behave like original clean command"),
|
||||
("noeggs", None, "don't clean up eggs"),
|
||||
("nopyc", None, "don't clean up pyc files"),
|
||||
]
|
||||
boolean_options = _clean.boolean_options + ["orig", "noeggs", "nopyc"]
|
||||
|
||||
source_folder = "src"
|
||||
eggs = None
|
||||
|
||||
@classmethod
|
||||
def for_options(cls, source_folder="src", eggs=None):
|
||||
if eggs is None:
|
||||
eggs = []
|
||||
return type(cls)(
|
||||
cls.__name__, (cls,), {"source_folder": source_folder, "eggs": eggs}
|
||||
)
|
||||
|
||||
def initialize_options(self):
|
||||
_clean.initialize_options(self)
|
||||
|
||||
self.orig = None
|
||||
self.noeggs = None
|
||||
self.nopyc = None
|
||||
|
||||
def finalize_options(self):
|
||||
_clean.finalize_options(self)
|
||||
|
||||
if not self.orig:
|
||||
self.all = True
|
||||
|
||||
def run(self):
|
||||
_clean.run(self)
|
||||
if self.orig:
|
||||
return
|
||||
|
||||
# eggs
|
||||
if not self.noeggs:
|
||||
for egg in self.eggs:
|
||||
globbed_eggs = glob.glob(egg)
|
||||
for globbed_egg in globbed_eggs:
|
||||
print("deleting '%s' egg" % globbed_egg)
|
||||
if not self.dry_run:
|
||||
shutil.rmtree(globbed_egg)
|
||||
|
||||
# pyc files
|
||||
if not self.nopyc:
|
||||
|
||||
def delete_folder_if_empty(path, applied_handler):
|
||||
if not applied_handler:
|
||||
return
|
||||
if len(os.listdir(path)) == 0:
|
||||
if not self.dry_run:
|
||||
shutil.rmtree(path)
|
||||
print(
|
||||
"removed %s since it was empty" % path[len(self.source_folder) :]
|
||||
)
|
||||
|
||||
def delete_file(path):
|
||||
print("removing '%s'" % path[len(self.source_folder) :])
|
||||
if not self.dry_run:
|
||||
os.remove(path)
|
||||
|
||||
import fnmatch
|
||||
|
||||
print("recursively removing *.pyc from '%s'" % self.source_folder)
|
||||
recursively_handle_files(
|
||||
os.path.abspath(self.source_folder),
|
||||
lambda name: fnmatch.fnmatch(name.lower(), "*.pyc"),
|
||||
folder_matcher=lambda dir, name, path: name != ".git",
|
||||
folder_handler=delete_folder_if_empty,
|
||||
file_handler=delete_file,
|
||||
)
|
||||
|
||||
|
||||
def _normalize_locale(l):
|
||||
from babel.core import Locale
|
||||
|
||||
return str(Locale.parse(l))
|
||||
|
||||
|
||||
class NewTranslation(Command):
|
||||
description = "create a new translation"
|
||||
user_options = [
|
||||
("locale=", "l", "locale for the new translation"),
|
||||
]
|
||||
boolean_options = []
|
||||
|
||||
pot_file = None
|
||||
output_dir = None
|
||||
|
||||
@classmethod
|
||||
def for_options(cls, pot_file=None, output_dir=None):
|
||||
if pot_file is None:
|
||||
raise ValueError("pot_file must not be None")
|
||||
if output_dir is None:
|
||||
raise ValueError("output_dir must not be None")
|
||||
|
||||
return type(cls)(
|
||||
cls.__name__, (cls,), {"pot_file": pot_file, "output_dir": output_dir}
|
||||
)
|
||||
|
||||
def __init__(self, dist, **kw):
|
||||
from babel.messages import frontend as babel
|
||||
|
||||
self.babel_init_messages = babel.init_catalog(dist)
|
||||
Command.__init__(self, dist, **kw)
|
||||
|
||||
def initialize_options(self):
|
||||
self.locale = None
|
||||
self.babel_init_messages.initialize_options()
|
||||
|
||||
def finalize_options(self):
|
||||
self.babel_init_messages.locale = _normalize_locale(self.locale)
|
||||
self.babel_init_messages.input_file = self.__class__.pot_file
|
||||
self.babel_init_messages.output_dir = self.__class__.output_dir
|
||||
self.babel_init_messages.finalize_options()
|
||||
|
||||
def run(self):
|
||||
self.babel_init_messages.run()
|
||||
|
||||
|
||||
class ExtractTranslation(Command):
|
||||
description = "extract translations"
|
||||
user_options = []
|
||||
boolean_options = []
|
||||
|
||||
mail_address = "i18n@octoprint.org"
|
||||
copyright_holder = "The OctoPrint Project"
|
||||
mapping_file = None
|
||||
pot_file = None
|
||||
input_dirs = None
|
||||
|
||||
@classmethod
|
||||
def for_options(
|
||||
cls,
|
||||
mail_address="i18n@octoprint.org",
|
||||
copyright_holder="The OctoPrint Project",
|
||||
mapping_file=None,
|
||||
pot_file=None,
|
||||
input_dirs=None,
|
||||
):
|
||||
if mapping_file is None:
|
||||
raise ValueError("mapping_file must not be None")
|
||||
if pot_file is None:
|
||||
raise ValueError("pot_file must not be None")
|
||||
if input_dirs is None:
|
||||
raise ValueError("input_dirs must not be None")
|
||||
|
||||
return type(cls)(
|
||||
cls.__name__,
|
||||
(cls,),
|
||||
{
|
||||
"mapping_file": mapping_file,
|
||||
"pot_file": pot_file,
|
||||
"input_dirs": input_dirs,
|
||||
"mail_address": mail_address,
|
||||
"copyright_holder": copyright_holder,
|
||||
},
|
||||
)
|
||||
|
||||
def __init__(self, dist, **kw):
|
||||
from babel.messages import frontend as babel
|
||||
|
||||
self.babel_extract_messages = babel.extract_messages(dist)
|
||||
Command.__init__(self, dist, **kw)
|
||||
|
||||
def initialize_options(self):
|
||||
self.babel_extract_messages.initialize_options()
|
||||
|
||||
def finalize_options(self):
|
||||
self.babel_extract_messages.mapping_file = self.__class__.mapping_file
|
||||
self.babel_extract_messages.output_file = self.__class__.pot_file
|
||||
self.babel_extract_messages.input_dirs = self.__class__.input_dirs
|
||||
self.babel_extract_messages.msgid_bugs_address = self.__class__.mail_address
|
||||
self.babel_extract_messages.copyright_holder = self.__class__.copyright_holder
|
||||
self.babel_extract_messages.finalize_options()
|
||||
|
||||
def run(self):
|
||||
self.babel_extract_messages.run()
|
||||
|
||||
|
||||
class RefreshTranslation(Command):
|
||||
description = "refresh translations"
|
||||
user_options = [
|
||||
("locale=", "l", "locale for the translation to refresh"),
|
||||
]
|
||||
boolean_options = []
|
||||
|
||||
mail_address = "i18n@octoprint.org"
|
||||
copyright_holder = "The OctoPrint Project"
|
||||
mapping_file = None
|
||||
pot_file = None
|
||||
input_dirs = None
|
||||
output_dir = None
|
||||
|
||||
@classmethod
|
||||
def for_options(
|
||||
cls,
|
||||
mail_address="i18n@octoprint.org",
|
||||
copyright_holder="The OctoPrint Project",
|
||||
mapping_file=None,
|
||||
pot_file=None,
|
||||
input_dirs=None,
|
||||
output_dir=None,
|
||||
):
|
||||
if mapping_file is None:
|
||||
raise ValueError("mapping_file must not be None")
|
||||
if pot_file is None:
|
||||
raise ValueError("pot_file must not be None")
|
||||
if input_dirs is None:
|
||||
raise ValueError("input_dirs must not be None")
|
||||
if output_dir is None:
|
||||
raise ValueError("output_dir must not be None")
|
||||
|
||||
return type(cls)(
|
||||
cls.__name__,
|
||||
(cls,),
|
||||
{
|
||||
"mapping_file": mapping_file,
|
||||
"pot_file": pot_file,
|
||||
"input_dirs": input_dirs,
|
||||
"mail_address": mail_address,
|
||||
"copyright_holder": copyright_holder,
|
||||
"output_dir": output_dir,
|
||||
},
|
||||
)
|
||||
|
||||
def __init__(self, dist, **kw):
|
||||
from babel.messages import frontend as babel
|
||||
|
||||
self.babel_extract_messages = babel.extract_messages(dist)
|
||||
self.babel_update_messages = babel.update_catalog(dist)
|
||||
Command.__init__(self, dist, **kw)
|
||||
|
||||
def initialize_options(self):
|
||||
self.locale = None
|
||||
self.babel_extract_messages.initialize_options()
|
||||
self.babel_update_messages.initialize_options()
|
||||
|
||||
def finalize_options(self):
|
||||
self.babel_extract_messages.mapping_file = self.__class__.mapping_file
|
||||
self.babel_extract_messages.output_file = self.__class__.pot_file
|
||||
self.babel_extract_messages.input_dirs = self.__class__.input_dirs
|
||||
self.babel_extract_messages.msgid_bugs_address = self.__class__.mail_address
|
||||
self.babel_extract_messages.copyright_holder = self.__class__.copyright_holder
|
||||
self.babel_extract_messages.finalize_options()
|
||||
|
||||
self.babel_update_messages.input_file = self.__class__.pot_file
|
||||
self.babel_update_messages.output_dir = self.__class__.output_dir
|
||||
if self.locale:
|
||||
self.babel_update_messages.locale = _normalize_locale(self.locale)
|
||||
self.babel_update_messages.finalize_options()
|
||||
|
||||
def run(self):
|
||||
self.babel_extract_messages.run()
|
||||
self.babel_update_messages.run()
|
||||
|
||||
|
||||
class CompileTranslation(Command):
|
||||
description = "compile translations"
|
||||
user_options = []
|
||||
boolean_options = []
|
||||
|
||||
output_dir = None
|
||||
|
||||
@classmethod
|
||||
def for_options(cls, output_dir=None):
|
||||
if output_dir is None:
|
||||
raise ValueError("output_dir must not be None")
|
||||
|
||||
return type(cls)(cls.__name__, (cls,), {"output_dir": output_dir})
|
||||
|
||||
def __init__(self, dist, **kw):
|
||||
from babel.messages import frontend as babel
|
||||
|
||||
self.babel_compile_messages = babel.compile_catalog(dist)
|
||||
Command.__init__(self, dist, **kw)
|
||||
|
||||
def initialize_options(self):
|
||||
self.babel_compile_messages.initialize_options()
|
||||
|
||||
def finalize_options(self):
|
||||
self.babel_compile_messages.directory = self.__class__.output_dir
|
||||
self.babel_compile_messages.finalize_options()
|
||||
|
||||
def run(self):
|
||||
self.babel_compile_messages.run()
|
||||
|
||||
|
||||
class BundleTranslation(Command):
|
||||
description = "bundles translations"
|
||||
user_options = [("locale=", "l", "locale for the translation to bundle")]
|
||||
boolean_options = []
|
||||
|
||||
source_dir = None
|
||||
target_dir = None
|
||||
|
||||
@classmethod
|
||||
def for_options(cls, source_dir=None, target_dir=None):
|
||||
if source_dir is None:
|
||||
raise ValueError("source_dir must not be None")
|
||||
if target_dir is None:
|
||||
raise ValueError("target_dir must not be None")
|
||||
|
||||
return type(cls)(
|
||||
cls.__name__, (cls,), {"source_dir": source_dir, "target_dir": target_dir}
|
||||
)
|
||||
|
||||
def initialize_options(self):
|
||||
self.locale = None
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
locale = _normalize_locale(self.locale)
|
||||
source_path = os.path.join(self.__class__.source_dir, locale)
|
||||
target_path = os.path.join(self.__class__.target_dir, locale)
|
||||
|
||||
if not os.path.exists(source_path):
|
||||
raise RuntimeError("source path " + source_path + " does not exist")
|
||||
|
||||
if os.path.exists(target_path):
|
||||
if not os.path.isdir(target_path):
|
||||
raise RuntimeError(
|
||||
"target path " + target_path + " exists and is not a directory"
|
||||
)
|
||||
shutil.rmtree(target_path)
|
||||
|
||||
print(
|
||||
"Copying translations for locale {locale} from {source_path} to {target_path}...".format(
|
||||
**locals()
|
||||
)
|
||||
)
|
||||
shutil.copytree(source_path, target_path)
|
||||
|
||||
|
||||
class PackTranslation(Command):
|
||||
description = "creates language packs for translations"
|
||||
user_options = [
|
||||
("locale=", "l", "locale for the translation to pack"),
|
||||
("author=", "a", "author of the translation"),
|
||||
("target=", "t", "target folder for the pack"),
|
||||
]
|
||||
boolean_options = []
|
||||
|
||||
source_dir = None
|
||||
pack_name_prefix = None
|
||||
pack_path_prefix = None
|
||||
|
||||
@classmethod
|
||||
def for_options(cls, source_dir=None, pack_name_prefix=None, pack_path_prefix=None):
|
||||
if source_dir is None:
|
||||
raise ValueError("source_dir must not be None")
|
||||
if pack_name_prefix is None:
|
||||
raise ValueError("pack_name_prefix must not be None")
|
||||
if pack_path_prefix is None:
|
||||
raise ValueError("pack_path_prefix must not be None")
|
||||
|
||||
return type(cls)(
|
||||
cls.__name__,
|
||||
(cls,),
|
||||
{
|
||||
"source_dir": source_dir,
|
||||
"pack_name_prefix": pack_name_prefix,
|
||||
"pack_path_prefix": pack_path_prefix,
|
||||
},
|
||||
)
|
||||
|
||||
def initialize_options(self):
|
||||
self.locale = None
|
||||
self.author = None
|
||||
self.target = None
|
||||
|
||||
def finalize_options(self):
|
||||
if self.locale is None:
|
||||
raise ValueError("locale must be provided")
|
||||
|
||||
def run(self):
|
||||
locale = _normalize_locale(self.locale)
|
||||
locale_dir = os.path.join(self.__class__.source_dir, locale)
|
||||
|
||||
if not os.path.isdir(locale_dir):
|
||||
raise RuntimeError("translation does not exist, please create it first")
|
||||
|
||||
import datetime
|
||||
|
||||
now = datetime.datetime.utcnow().replace(microsecond=0)
|
||||
|
||||
if self.target is None:
|
||||
self.target = self.__class__.source_dir
|
||||
|
||||
zip_path = os.path.join(
|
||||
self.target,
|
||||
"{prefix}{locale}_{date}.zip".format(
|
||||
prefix=self.__class__.pack_name_prefix,
|
||||
locale=locale,
|
||||
date=now.strftime("%Y%m%d%H%M%S"),
|
||||
),
|
||||
)
|
||||
print("Packing translation to {zip_path}".format(**locals()))
|
||||
|
||||
def add_recursively(zip, path, prefix):
|
||||
if not os.path.isdir(path):
|
||||
return
|
||||
|
||||
for entry in os.listdir(path):
|
||||
entry_path = os.path.join(path, entry)
|
||||
new_prefix = prefix + "/" + entry
|
||||
if os.path.isdir(entry_path):
|
||||
add_recursively(zip, entry_path, new_prefix)
|
||||
elif os.path.isfile(entry_path):
|
||||
print("Adding {entry_path} as {new_prefix}".format(**locals()))
|
||||
zip.write(entry_path, new_prefix)
|
||||
|
||||
meta_str = "last_update: {date}\n".format(date=now.isoformat())
|
||||
if self.author:
|
||||
meta_str += "author: {author}\n".format(author=self.author)
|
||||
|
||||
zip_locale_root = self.__class__.pack_path_prefix + locale
|
||||
|
||||
import zipfile
|
||||
|
||||
with zipfile.ZipFile(zip_path, "w") as zip:
|
||||
add_recursively(zip, locale_dir, zip_locale_root)
|
||||
|
||||
print("Adding meta.yaml as {zip_locale_root}/meta.yaml".format(**locals()))
|
||||
zip.writestr(zip_locale_root + "/meta.yaml", meta_str)
|
||||
|
||||
|
||||
def get_babel_commandclasses(
|
||||
pot_file=None,
|
||||
mapping_file="babel.cfg",
|
||||
input_dirs=".",
|
||||
output_dir=None,
|
||||
pack_name_prefix=None,
|
||||
pack_path_prefix=None,
|
||||
bundled_dir=None,
|
||||
mail_address="i18n@octoprint.org",
|
||||
copyright_holder="The OctoPrint Project",
|
||||
):
|
||||
try:
|
||||
import babel
|
||||
except ImportError:
|
||||
return {}
|
||||
|
||||
result = {
|
||||
"babel_new": NewTranslation.for_options(pot_file=pot_file, output_dir=output_dir),
|
||||
"babel_extract": ExtractTranslation.for_options(
|
||||
mapping_file=mapping_file,
|
||||
pot_file=pot_file,
|
||||
input_dirs=input_dirs,
|
||||
mail_address=mail_address,
|
||||
copyright_holder=copyright_holder,
|
||||
),
|
||||
"babel_refresh": RefreshTranslation.for_options(
|
||||
mapping_file=mapping_file,
|
||||
pot_file=pot_file,
|
||||
input_dirs=input_dirs,
|
||||
output_dir=output_dir,
|
||||
mail_address=mail_address,
|
||||
copyright_holder=copyright_holder,
|
||||
),
|
||||
"babel_compile": CompileTranslation.for_options(output_dir=output_dir),
|
||||
"babel_pack": PackTranslation.for_options(
|
||||
source_dir=output_dir,
|
||||
pack_name_prefix=pack_name_prefix,
|
||||
pack_path_prefix=pack_path_prefix,
|
||||
),
|
||||
}
|
||||
|
||||
if bundled_dir is not None:
|
||||
result["babel_bundle"] = BundleTranslation.for_options(
|
||||
source_dir=output_dir, target_dir=bundled_dir
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def create_plugin_setup_parameters(
|
||||
identifier="todo",
|
||||
name="TODO",
|
||||
version="0.1",
|
||||
description="TODO",
|
||||
author="TODO",
|
||||
mail="todo@example.com",
|
||||
url="TODO",
|
||||
license="AGPLv3",
|
||||
source_folder=".",
|
||||
additional_data=None,
|
||||
additional_packages=None,
|
||||
ignored_packages=None,
|
||||
requires=None,
|
||||
extra_requires=None,
|
||||
cmdclass=None,
|
||||
eggs=None,
|
||||
package=None,
|
||||
dependency_links=None,
|
||||
):
|
||||
import pkg_resources
|
||||
|
||||
if package is None:
|
||||
package = "octoprint_{identifier}".format(**locals())
|
||||
|
||||
if additional_data is None:
|
||||
additional_data = list()
|
||||
|
||||
if additional_packages is None:
|
||||
additional_packages = list()
|
||||
|
||||
if ignored_packages is None:
|
||||
ignored_packages = list()
|
||||
|
||||
if dependency_links is None:
|
||||
dependency_links = list()
|
||||
|
||||
if requires is None:
|
||||
requires = ["OctoPrint"]
|
||||
if not isinstance(requires, list):
|
||||
raise ValueError("requires must be a list")
|
||||
if not has_requirement("OctoPrint", requires):
|
||||
requires = ["OctoPrint"] + list(requires)
|
||||
|
||||
if extra_requires is None:
|
||||
extra_requires = {}
|
||||
if not isinstance(extra_requires, dict):
|
||||
raise ValueError("extra_requires must be a dict")
|
||||
|
||||
if cmdclass is None:
|
||||
cmdclass = {}
|
||||
if not isinstance(cmdclass, dict):
|
||||
raise ValueError("cmdclass must be a dict")
|
||||
|
||||
if eggs is None:
|
||||
eggs = []
|
||||
if not isinstance(eggs, list):
|
||||
raise ValueError("eggs must be a list")
|
||||
|
||||
egg = "{name}*.egg-info".format(
|
||||
name=pkg_resources.to_filename(pkg_resources.safe_name(name))
|
||||
)
|
||||
if egg not in eggs:
|
||||
eggs = [egg] + eggs
|
||||
|
||||
cmdclass.update(
|
||||
{
|
||||
"clean": CleanCommand.for_options(
|
||||
source_folder=os.path.join(source_folder, package), eggs=eggs
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
translation_dir = os.path.join(source_folder, "translations")
|
||||
pot_file = os.path.join(translation_dir, "messages.pot")
|
||||
bundled_dir = os.path.join(source_folder, package, "translations")
|
||||
cmdclass.update(
|
||||
get_babel_commandclasses(
|
||||
pot_file=pot_file,
|
||||
output_dir=translation_dir,
|
||||
bundled_dir=bundled_dir,
|
||||
pack_name_prefix="{name}-i18n-".format(**locals()),
|
||||
pack_path_prefix="_plugins/{identifier}/".format(**locals()),
|
||||
)
|
||||
)
|
||||
|
||||
from setuptools import find_packages
|
||||
|
||||
packages = set(
|
||||
[package]
|
||||
+ list(
|
||||
filter(
|
||||
lambda x: x.startswith("{package}.".format(package=package)),
|
||||
find_packages(where=source_folder, exclude=ignored_packages),
|
||||
)
|
||||
)
|
||||
+ additional_packages
|
||||
)
|
||||
print("Found packages: {packages!r}".format(**locals()))
|
||||
|
||||
return {
|
||||
"name": name,
|
||||
"version": version,
|
||||
"description": description,
|
||||
"author": author,
|
||||
"author_email": mail,
|
||||
"url": url,
|
||||
"license": license,
|
||||
# adding new commands
|
||||
"cmdclass": cmdclass,
|
||||
# we only have our plugin package to install
|
||||
"packages": packages,
|
||||
# we might have additional data files in sub folders that need to be installed too
|
||||
"package_data": {
|
||||
package: package_data_dirs(
|
||||
os.path.join(source_folder, package),
|
||||
["static", "templates", "translations"] + additional_data,
|
||||
)
|
||||
},
|
||||
"include_package_data": True,
|
||||
# If you have any package data that needs to be accessible on the file system, such as templates or static assets
|
||||
# this plugin is not zip_safe.
|
||||
"zip_safe": False,
|
||||
"install_requires": requires,
|
||||
"extras_require": extra_requires,
|
||||
"dependency_links": dependency_links,
|
||||
# Hook the plugin into the "octoprint.plugin" entry point, mapping the plugin_identifier to the plugin_package.
|
||||
# That way OctoPrint will be able to find the plugin and load it.
|
||||
"entry_points": {
|
||||
"octoprint.plugin": ["{identifier} = {package}".format(**locals())]
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
import fnmatch
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from invoke import task
|
||||
|
||||
|
||||
@task
|
||||
def clean(ctx, dry_run=False):
|
||||
source_folder = "src"
|
||||
abs_source_folder = os.path.abspath(source_folder)
|
||||
|
||||
def delete_folder_if_empty(path):
|
||||
if next(os.scandir(path), None):
|
||||
return
|
||||
if not dry_run:
|
||||
shutil.rmtree(path)
|
||||
print(f"removed {path[len(abs_source_folder)+1:]} since it was empty")
|
||||
|
||||
def delete_file(path):
|
||||
print(f"removing file '{path[len(abs_source_folder)+1:]}'")
|
||||
if not dry_run:
|
||||
os.remove(path)
|
||||
|
||||
def delete_folder(path):
|
||||
print(f"removing directory '{path[len(abs_source_folder)+1:]}'")
|
||||
if not dry_run:
|
||||
shutil.rmtree(path)
|
||||
|
||||
rules = [
|
||||
("f", "*.pyc", delete_file),
|
||||
("d", "*.egg-info", delete_folder),
|
||||
("d", "*", delete_folder_if_empty),
|
||||
]
|
||||
|
||||
def process(root, rules):
|
||||
for entry in os.scandir(root):
|
||||
if entry.is_dir():
|
||||
process(entry.path, rules)
|
||||
|
||||
for rule in rules:
|
||||
if (
|
||||
(rule[0] == "f" and entry.is_file)
|
||||
or (rule[0] == "d" and entry.is_dir())
|
||||
) and fnmatch.fnmatch(entry.name, rule[1]):
|
||||
rule[2](entry.path)
|
||||
break
|
||||
|
||||
process(abs_source_folder, rules)
|
||||
print("Cleaned up!")
|
||||
|
||||
|
||||
@task
|
||||
def css_build(ctx):
|
||||
ctx.run("octoprint dev css:build --all")
|
||||
|
||||
|
||||
@task
|
||||
def scan_deps(ctx):
|
||||
try:
|
||||
from setuptools.config.setupcfg import read_configuration
|
||||
except ImportError:
|
||||
from setuptools.config import read_configuration
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
import pkg_resources
|
||||
import requests
|
||||
from packaging.version import InvalidVersion
|
||||
from packaging.version import parse as parse_version
|
||||
|
||||
PYPI = "https://pypi.org/simple/{package}/"
|
||||
|
||||
config = read_configuration("setup.cfg")
|
||||
install_requires = config.get("options", {}).get("install_requires", [])
|
||||
extra_requires = config.get("options.extras_requires", {})
|
||||
|
||||
Update = namedtuple("Update", ["name", "spec", "current", "latest"])
|
||||
update_lower_bounds = []
|
||||
update_bounds = []
|
||||
|
||||
all_requires = list(install_requires)
|
||||
for value in extra_requires.values():
|
||||
all_requires += value
|
||||
|
||||
# strip any comments
|
||||
all_requires = [r.split("#")[0].strip() for r in all_requires]
|
||||
|
||||
for r in all_requires:
|
||||
print(f"Checking {r}...")
|
||||
requirement = pkg_resources.Requirement.parse(r)
|
||||
|
||||
resp = requests.get(
|
||||
PYPI.format(package=requirement.project_name),
|
||||
headers={"Accept": "application/vnd.pypi.simple.v1+json"},
|
||||
)
|
||||
resp.raise_for_status()
|
||||
|
||||
data = resp.json()
|
||||
|
||||
def safe_parse_version(version):
|
||||
try:
|
||||
return parse_version(version)
|
||||
except InvalidVersion:
|
||||
return None
|
||||
|
||||
versions = list(
|
||||
filter(
|
||||
lambda x: x and not x.is_prerelease and not x.is_devrelease,
|
||||
map(lambda x: safe_parse_version(x), data.get("versions", [])),
|
||||
)
|
||||
)
|
||||
if not versions:
|
||||
continue
|
||||
|
||||
lower = None
|
||||
for spec in requirement.specs:
|
||||
if spec[0] == ">=":
|
||||
lower = spec[1]
|
||||
break
|
||||
|
||||
latest = versions[-1]
|
||||
|
||||
update = Update(requirement.project_name, str(requirement), lower, latest)
|
||||
|
||||
if str(latest) not in requirement:
|
||||
update_bounds.append(update)
|
||||
elif lower and parse_version(lower) < latest:
|
||||
update_lower_bounds.append(update)
|
||||
|
||||
def print_update(update):
|
||||
print(
|
||||
f"{update.spec}: latest {update.latest}, pypi: https://pypi.org/project/{update.name}/"
|
||||
)
|
||||
|
||||
if update_lower_bounds:
|
||||
print("")
|
||||
print("The following dependencies can get their lower bounds updated:")
|
||||
print("")
|
||||
for update in update_lower_bounds:
|
||||
print_update(update)
|
||||
|
||||
if update_bounds:
|
||||
print("")
|
||||
print("The following dependencies should get looked at for a full update:")
|
||||
print("")
|
||||
for update in update_bounds:
|
||||
print_update(update)
|
||||
|
||||
if not update_lower_bounds and not update_bounds:
|
||||
print("All dependencies are up to date!")
|
||||
|
||||
|
||||
try:
|
||||
import babel # noqa: F401
|
||||
|
||||
def _normalize_locale(locale):
|
||||
from babel.core import Locale
|
||||
|
||||
return str(Locale.parse(locale))
|
||||
|
||||
@task
|
||||
def babel_new(ctx, locale):
|
||||
locale = _normalize_locale(locale)
|
||||
output_dir = "translations"
|
||||
pot_file = os.path.join(output_dir, "messages.pot")
|
||||
ctx.run(f"pybabel init -l {locale} -i {pot_file} -o {output_dir}")
|
||||
|
||||
@task
|
||||
def babel_extract(ctx):
|
||||
output_dir = "translations"
|
||||
mapping_file = "babel.cfg"
|
||||
input_dirs = "."
|
||||
mail_address = "i18n@octoprint.org"
|
||||
copyright_holder = "The OctoPrint Project"
|
||||
pot_file = os.path.join(output_dir, "messages.pot")
|
||||
|
||||
ctx.run(
|
||||
f"pybabel extract -F '{mapping_file}' -o '{pot_file}' --msgid-bugs-address='{mail_address}' --copyright-holder='{copyright_holder}' {input_dirs}"
|
||||
)
|
||||
|
||||
@task
|
||||
def babel_refresh(ctx, locale=None):
|
||||
locale = _normalize_locale(locale) if locale else None
|
||||
output_dir = "translations"
|
||||
mapping_file = "babel.cfg"
|
||||
input_dirs = "."
|
||||
mail_address = "i18n@octoprint.org"
|
||||
copyright_holder = "The OctoPrint Project"
|
||||
pot_file = os.path.join(output_dir, "messages.pot")
|
||||
|
||||
ctx.run(
|
||||
f"pybabel extract -F '{mapping_file}' -o '{pot_file}' --msgid-bugs-address='{mail_address}' --copyright-holder='{copyright_holder}' {input_dirs}"
|
||||
)
|
||||
ctx.run(
|
||||
f"pybabel update -i '{pot_file}' -d '{output_dir}'"
|
||||
+ (f" -l {locale}" if locale else "")
|
||||
)
|
||||
|
||||
@task
|
||||
def babel_compile(ctx):
|
||||
output_dir = "translations"
|
||||
ctx.run(f"pybabel compile -d '{output_dir}'")
|
||||
|
||||
@task
|
||||
def babel_bundle(ctx, locale):
|
||||
locale = _normalize_locale(locale)
|
||||
source_path = os.path.join("translations", locale)
|
||||
target_path = os.path.join("src", "octoprint", "translations")
|
||||
|
||||
if not os.path.exists(source_path):
|
||||
raise RuntimeError(f"Locale {locale} does not exist")
|
||||
|
||||
if os.path.exists(target_path):
|
||||
if not os.path.isdir(target_path):
|
||||
raise RuntimeError(f"Target path {target_path} is not a directory")
|
||||
shutil.rmtree(target_path)
|
||||
|
||||
print(
|
||||
f"Copying translations for locale {locale} from {source_path} to {target_path}"
|
||||
)
|
||||
shutil.copytree(source_path, target_path)
|
||||
|
||||
@task
|
||||
def babel_pack(ctx, locale, target=None, author=None):
|
||||
locale = _normalize_locale(locale)
|
||||
source_path = os.path.join("translations", locale)
|
||||
|
||||
if not os.path.exists(source_path):
|
||||
raise RuntimeError(
|
||||
f"translation for locale {locale} does not exist, please create it first"
|
||||
)
|
||||
|
||||
import datetime
|
||||
|
||||
now = datetime.datetime.utcnow().replace(microsecond=0)
|
||||
|
||||
if target is None:
|
||||
target = source_path
|
||||
|
||||
zip_path = os.path.join(f"OctoPrint-i18n-{locale}_{now}.zip")
|
||||
print(f"Packing translation to {zip_path}")
|
||||
|
||||
def add_recursively(zip, path, prefix):
|
||||
if not os.path.isdir(path):
|
||||
return
|
||||
|
||||
for entry in os.listdir(path):
|
||||
entry_path = os.path.join(path, entry)
|
||||
new_prefix = prefix + "/" + entry
|
||||
if os.path.isdir(entry_path):
|
||||
add_recursively(zip, entry_path, new_prefix)
|
||||
elif os.path.isfile(entry_path):
|
||||
print(f"Adding {entry_path} as {new_prefix}")
|
||||
zip.write(entry_path, new_prefix)
|
||||
|
||||
meta_str = f"last_update: {now.isoformat()}\n"
|
||||
if author:
|
||||
meta_str += f"author: {author}\n"
|
||||
|
||||
zip_locale_root = locale
|
||||
|
||||
import zipfile
|
||||
|
||||
with zipfile.ZipFile(zip_path, "w") as zip:
|
||||
add_recursively(zip, source_path, zip_locale_root)
|
||||
|
||||
print(f"Adding meta.yaml as {zip_locale_root}/meta.yaml")
|
||||
zip.writestr(zip_locale_root + "/meta.yaml", meta_str)
|
||||
|
||||
except ImportError:
|
||||
pass
|
||||
Reference in new issue
Block a user